Skip to content

Error when segmenting #36

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

Open
joaomamede opened this issue Sep 13, 2020 · 3 comments
Open

Error when segmenting #36

joaomamede opened this issue Sep 13, 2020 · 3 comments

Comments

@joaomamede
Copy link

joaomamede commented Sep 13, 2020

Hi, first use resulted in errors.
Can anyone point me to a fix?

Segmenting...
ERROR:root:Unhandled exception:
Traceback (most recent call last):
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/magicgui/core.py", line 199, in <lambda>
    self.call_button.clicked.connect(lambda checked: self.__call__())
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/magicgui/core.py", line 532, in __call__
    value = self.func(**_kwargs)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/segmentify-0.1.1-py3.8.egg/segmentify/gui.py", line 29, in segmentation
    clf, features = fit(data, initial_labels.data, featurizer=featurizer.value)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/segmentify-0.1.1-py3.8.egg/segmentify/semantic/main.py", line 129, in fit
    padded_features = unet_featurize(padded_image, featurizer)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/segmentify-0.1.1-py3.8.egg/segmentify/semantic/main.py", line 59, in unet_featurize
    features = model(image)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/segmentify-0.1.1-py3.8.egg/segmentify/model/unet.py", line 57, in forward
    x = self.decode_4(x, skip_4)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 722, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/jmamede/anaconda3/lib/python3.8/site-packages/segmentify-0.1.1-py3.8.egg/segmentify/model/layers/unet_layers.py", line 63, in forward
    output += skip
RuntimeError: The size of tensor a (254) must match the size of tensor b (255) at non-singleton dimension 2

These were the labels I made before:
image

Same error example:
image

I started things with:

    import napari 
    from segmentify import segmentation 

    with napari.gui_qt(): 
        viewer = napari.Viewer() 
    
        # instantiate the segmentify widget 
        gui = segmentation.Gui() 

        # add the new widget to the napari viewer 
        viewer.window.add_dock_widget(gui) 
 
        # keep the dropdown menus in the gui in sync with the layer model 
        viewer.layers.events.changed.connect(lambda x: gui.refresh_choices() )
                                                                `
@joaomamede
Copy link
Author

Okay.
Original image was 2044x2048. It resulted in that error
I clipped the 4 pixels to ahve a 2044x2044 and the segmentation worked.

@sofroniewn
Copy link
Collaborator

Hi @joaomamede, sorry I'm just seeing this now, yes - the original model might only have worked on square images, see #34 (comment). I'm not sure how easy that would be to fix, but if you were interested in working on a PR I'd happily review! I can look into it a bit too, but it's been a while since i've looked at this repo

@sofroniewn
Copy link
Collaborator

@joaomamede I suspect this may have now been fixed by #37, but let me know if you're still seeing issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants