vanvalenlab / deepcell-tf

Deep Learning Library for Single Cell Analysis
https://deepcell.readthedocs.io
Other
425 stars 99 forks source link

Different segmentation between web and code versions of DeepCell #616

Open jayluo2 opened 2 years ago

jayluo2 commented 2 years ago

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):

Additional context I have two questions:

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.

ngreenwald commented 2 years ago

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

jayluo2 commented 2 years ago

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

ngreenwald commented 2 years ago

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.

jayluo2 commented 2 years ago

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?

ngreenwald commented 2 years ago

Hmm, maybe @tddough98 can weigh in?

tddough98 commented 2 years ago

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

jayluo2 commented 2 years ago

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

msschwartz21 commented 2 years ago

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.

jayluo2 commented 2 years ago

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
msschwartz21 commented 2 years ago

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