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

Some problems occurred in predict.py. #94

Closed
DL-Alva opened this issue Dec 4, 2019 · 21 comments
Closed

Some problems occurred in predict.py. #94

DL-Alva opened this issue Dec 4, 2019 · 21 comments

Comments

@DL-Alva
Copy link

DL-Alva commented Dec 4, 2019

Hi, sorry for troubling you. But when I run predict.py, it remind AttributeError: 'numpy.ndarray' object has no attribute 'unsqueeze':

Traceback (most recent call last):
File "origin_predict.py", line 135, in
device=device)
File "origin_predict.py", line 32, in predict_img
img = img.unsqueeze(0)
AttributeError: 'numpy.ndarray' object has no attribute 'unsqueeze'

Do you know how to deal with it? Thank you so much.

@milesial
Copy link
Owner

milesial commented Dec 4, 2019

Hi, can you try after pulling the last commit on master ?

@DL-Alva
Copy link
Author

DL-Alva commented Dec 4, 2019

Thank you for your reply. I try to use torch.from_numpy(img).unsqeeze(0),to transfer the numpy type of img to that of torch.

@glesx
Copy link

glesx commented Dec 11, 2019

I'm getting the following error:

python predict.py -i validation.jpg --viz --no-save

Traceback (most recent call last):
  File "predict.py", line 132, in <module>
    device=device)
  File "predict.py", line 25, in predict_img
    ds = BasicDataset('', '', scale=scale_factor)
  File "C:\Users\glesx\Documents\GitHub\Pytorch-UNet\utils\dataset.py", line 18, in __init__
    self.ids = [splitext(file)[0] for file in listdir(imgs_dir)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

When I add a path, I get this error instead:

Traceback (most recent call last):
  File "predict.py", line 132, in <module>
    device=device)
  File "predict.py", line 44, in predict_img
    transforms.Resize(full_img.shape[1]),
AttributeError: 'JpegImageFile' object has no attribute 'shape'

@cmlyldz
Copy link

cmlyldz commented Dec 11, 2019

I am also getting similar error
python predict.py -i austin.png --viz --no-save
`Reloaded modules: unet, unet.unet_model, unet.unet_parts, utils.data_vis, utils.dataset
Traceback (most recent call last):

File "D:\PW\courses\neuralNetworks\repo\Pytorch-UNet\predict.py", line 141, in
device=device)

File "D:\PW\courses\neuralNetworks\repo\Pytorch-UNet\predict.py", line 26, in predict_img
ds = BasicDataset('', '', scale=scale_factor)

File "D:\PW\courses\neuralNetworks\repo\Pytorch-UNet\utils\dataset.py", line 18, in init
self.ids = [splitext(file)[0] for file in listdir(imgs_dir)

FileNotFoundError: [WinError 3] The system cannot find the path specified: ''`

@milesial
Copy link
Owner

Hi, can you try again after pulling the last commit ?

@cmlyldz
Copy link

cmlyldz commented Dec 11, 2019

Commit is works for me. But there is another problem.
image

I passing this error with - transforms.Resize(np.array(full_img).shape[1]), - but when I use this my predicted image is totally white.

I want to add my traning log, maybe there is something wrong with traning I am not sure about it.
image

@milesial
Copy link
Owner

milesial commented Dec 11, 2019

You validation DICE is > 1 and your loss is negative so there is a problem with your masks. If you have 2 classes, make sure the mask values are 0s or 1s.

@cmlyldz
Copy link

cmlyldz commented Dec 11, 2019

I have only one class. As an example my train image;
image

And my mask;
image

@milesial
Copy link
Owner

Verify that after loading your mask, the tensor contains only 0s and 1s

@cmlyldz
Copy link

cmlyldz commented Dec 12, 2019

It has only true and falses, I think it means 0 and 1;

image

image

@milesial
Copy link
Owner

can you print the resulting true mask tensor and the network output values ?

@cmlyldz
Copy link

cmlyldz commented Dec 12, 2019

Can you be more spesific? Where are they?

@milesial
Copy link
Owner

In the train loop

masks_pred = net(imgs)

print masks_pred and true_masks and make sure they are as expected

@cmlyldz
Copy link

cmlyldz commented Dec 12, 2019

True mask;
image
mask_pred;
image

How can I understand they are okay or not?

@milesial
Copy link
Owner

Please show some of the values of these tensors : min, max, type, ...

@cmlyldz
Copy link

cmlyldz commented Dec 12, 2019

I hope you mention about following images;
image

image

@milesial
Copy link
Owner

milesial commented Dec 12, 2019

Yes that what I meant. The values of the true mask should be between [0, 1], as they are probabilities. Divide your true masks by 255 in your loader.

( I'm doing that in my loader, did you bypass that ?

img_trans = img_trans / 255
)

@cmlyldz
Copy link

cmlyldz commented Dec 12, 2019

no its same. its not bypassed.

@cmlyldz
Copy link

cmlyldz commented Dec 12, 2019

I solve the problem, it is about .tif files.

I can reproduce that on Windows. Downgrading libtiff to 4.0.10 (conda install libtiff=4.0.10) works. Investigating it...

PS: it works fine on macOS and Linux, only Windows is failing.
[https://github.com/conda-forge/pillow-feedstock/issues/69]

After changing libtiff version it works properly.

@Janene-Li
Copy link

I'm getting the following error:

python predict.py -i validation.jpg --viz --no-save

Traceback (most recent call last):
  File "predict.py", line 132, in <module>
    device=device)
  File "predict.py", line 25, in predict_img
    ds = BasicDataset('', '', scale=scale_factor)
  File "C:\Users\glesx\Documents\GitHub\Pytorch-UNet\utils\dataset.py", line 18, in __init__
    self.ids = [splitext(file)[0] for file in listdir(imgs_dir)
FileNotFoundError: [WinError 3] The system cannot find the path specified: ''

When I add a path, I get this error instead:

Traceback (most recent call last):
  File "predict.py", line 132, in <module>
    device=device)
  File "predict.py", line 44, in predict_img
    transforms.Resize(full_img.shape[1]),
AttributeError: 'JpegImageFile' object has no attribute 'shape'

I have come to similar problem like this:

Traceback (most recent call last):
  File "predict.py", line 131, in <module>
    device=device)
  File "predict.py", line 43, in predict_img
    transforms.Resize(full_img.shape[2]),
AttributeError: 'PngImageFile' object has no attribute 'shape'

It seems like png picture cannot use '.shape[2]'.... I change it into '.width' and finally succesfully run the project~

@milesial
Copy link
Owner

@Janene-Li make sure you are using the latest version of Pillow

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

5 participants