Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Padding removal function results in zero-size array due to slicing with [0:-0] #665

Closed
RaiBP opened this issue Jun 5, 2023 · 3 comments · Fixed by vanvalenlab/kiosk-redis-consumer#199 or #673
Labels
bug Something isn't working

Comments

@RaiBP
Copy link

RaiBP commented Jun 5, 2023

Bug Report

  • DeepCell version: 0.12.5
  • Python version: 3.10.10
  • Operating System: Manjaro Linux 22.1.2

Description

While running the predict method of CytoplasmSegmentation, an error is thrown with the message ValueError: zero-size array to reduction operation maximum which has no identity.

Upon investigation, the issue seems to be related to the _untile_output function in the Application class. Specifically, when the _process function is called to remove padding from the image, it results in a zero-dimensional array if the padding is zero.

Here is the problematic code (link):

def _process(im, tiles_info):
    x_pad, y_pad = tiles_info['x_pad'], tiles_info['y_pad']
    out = im[:, x_pad[0]:-x_pad[1], y_pad[0]:-y_pad[1], :]
    return out

In Python, using negative zero indexing (like a[0:-0]) does not behave as expected. Instead of returning the whole array, it returns an empty array.

Steps to Reproduce

  1. Run the predict method of CytoplasmSegmentation with an image where y-padding is zero i.e. width of 512 for the default model.

Expected Behavior

The _process function should handle the case where padding is zero, and return the original image in such cases, rather than an empty array. One solution is:

def _process(im, tiles_info):
    x_pad, y_pad = tiles_info['x_pad'], tiles_info['y_pad']
    x_slice = slice(x_pad[0], -x_pad[1] if x_pad[1] != 0 else None)
    y_slice = slice(y_pad[0], -y_pad[1] if y_pad[1] != 0 else None)
    out = im[:, x_slice, y_slice, :]
    return out

Actual Behavior

The function returns an empty array if padding is zero, leading to a ValueError in later processing steps.

Please let me know if you have any questions or if you need more information.

@msschwartz21
Copy link
Member

I just ran into this same bug when trying to use the NuclearSegmentation application to predict on a 216x256 image which is smaller than the training size for the model.

@rossbar
Copy link
Contributor

rossbar commented Jun 27, 2023

Thanks you very much @RaiBP for the thorough report! And thanks @msschwartz21 for verifying, I'll take a look asap.

@rossbar rossbar added the bug Something isn't working label Jun 27, 2023
@msschwartz21
Copy link
Member

@rossbar I tested a redeploy of the kiosk with deepcell 0.12.5. Of course, our current sample data for nuclear segmentation is 256x256 so this bug pops up right away if anyone uses the exiting sample data. I can swap out the sample data for something bigger, but if we can resolve this issue before the tracking preprint comes out that would be best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants