deepcell-tf icon indicating copy to clipboard operation
deepcell-tf copied to clipboard

Different segmentation between web and code versions of DeepCell

Open jayluo2 opened this issue 2 years ago • 10 comments

Describe the bug Inconsistent segmentation results between https://deepcell.org/predict and code implementation.

To Reproduce Steps to reproduce the behavior: Use the below image as input to https://deepcell.org/predict, with settings Screen Shot 2022-07-06 at 7 43 23 PM

and in code, output = app.predict(image, image_mpp=1, batch_size=1) where app is the Mesmer object with pretrained weights. ‘image’ is a numpy array of dimensions (1, 1024, 1024, 2), with both channels containing the same image (below).

sample

Expected behavior Identical/nearly identical segmentations between https://deepcell.org/predict and local implementation.

Screenshots Left: binarized predictions (local). Right: https://deepcell.org/predict results. Red boxes highlight example regions of missed cells.

Screen Shot 2022-07-06 at 7 42 19 PM

Desktop (please complete the following information):

  • OS: macOS
  • Version of DeepCell: 0.12.2
  • Python Version: 3.9

Additional context I have two questions:

  • Does the web version of DeepCell use the same pretrained weights as the ones from calling Mesmer()?
  • I assume the “Prediction Type” for app.predict() is “Mesmer” (same as the option on deepcell.org)?

If both the pretrained weights and other configurations are the same across the web and code versions, I am confused on why some cells would be missed in the code version.

jayluo2 avatar Jul 07 '22 00:07 jayluo2

Hey @jayluo2, are you running the code locally within a docker or in a virtual environment?

ngreenwald avatar Jul 07 '22 15:07 ngreenwald

Hi @ngreenwald, I am running Python 3.9.0 in a virtual environment (local).

jayluo2 avatar Jul 07 '22 16:07 jayluo2

Got it. We've found that different tensorflow versions can interact in unpredictable ways local machines/trained models. Can you try running it from within the docker to confirm? The instructions are in the main readme.

ngreenwald avatar Jul 07 '22 16:07 ngreenwald

I am on MacOS 11.3.1 (Big Sur) and don’t think CUDA is supported for this OS. Is there another way to verify?

jayluo2 avatar Jul 07 '22 17:07 jayluo2

Hmm, maybe @tddough98 can weigh in?

ngreenwald avatar Jul 07 '22 18:07 ngreenwald

There's been some work on tensorflow consistency recently, not on my part tho. @elaubsch @msschwartz21 might know more about subtle differences in tensorflow

tddough98 avatar Jul 07 '22 19:07 tddough98

Are https://deepcell.org/predict and the code version using different versions of Tensorflow? Is there a workaround for this?

jayluo2 avatar Jul 11 '22 17:07 jayluo2

Hi Jay,

I confirmed that we are in the process of upgrading the tensorflow environment and model that runs on deepcell.org to match the one in deepcell 0.12. You can keep an eye on this issue (https://github.com/vanvalenlab/kiosk-console/issues/466) to see when we have made the change.

In the meantime, you can try pinning deepcell to 0.11.2 which should match the results you are getting from deepcell.org.

msschwartz21 avatar Jul 11 '22 18:07 msschwartz21

Hi @msschwartz21, deepcell 0.11.2 doesn’t appear to be available on pip (I’m using pip 20.2.3). The installation error is below. Would deepcell 0.11.1 work?

ERROR: Could not find a version that satisfies the requirement deepcell==0.11.2 (from versions: 0.8.0, 0.8.1, 0.8.2, 0.8.3, 0.8.4, 0.8.5, 0.8.6, 0.8.7, 0.8.8, 0.9.0, 0.9.1, 0.9.2, 0.10.0rc1, 0.10.0rc2, 0.10.0rc3, 0.10.0, 0.10.1, 0.10.2, 0.11.0rc1, 0.11.0, 0.11.1, 0.12.0rc0, 0.12.0rc1, 0.12.0rc2, 0.12.0, 0.12.1, 0.12.2)
ERROR: No matching distribution found for deepcell==0.11.2

jayluo2 avatar Jul 11 '22 19:07 jayluo2

You may need to create an environment with Python 3.6-3.8 but any 0.11 version of deepcell should also be fine.

msschwartz21 avatar Jul 11 '22 20:07 msschwartz21