iArunava/ENet-Real-Time-Semantic-Segmentation

run init.py test have a problem

Closed this issue · 18 comments

Thank you for your code sharing! When test a picture have a problem:

RuntimeError: Expected a Tensor of type torch.FloatTensor but found a type torch.cuda.FloatTensor for sequence element 1 in sequence argument at position #1 'tensors'

I don't know why it will happen like this.pytorch is 0.4

Share the stacktrace, exactly where you are getting this error. Thanks. I will get back to you.

Thank you for your reply!

/usr/bin/python3.5 /home/zhouzhubin/pythorch/Enet/ENet-Real-Time-Semantic-Segmentation/init.py --mode test -i 01.jpg
Traceback (most recent call last):
File "/home/zhouzhubin/pythorch/Enet/ENet-Real-Time-Semantic-Segmentation/init.py", line 153, in
test(FLAGS)
File "/home/zhouzhubin/pythorch/Enet/ENet-Real-Time-Semantic-Segmentation/test.py", line 36, in test
out1 = enet(tmg.float()).squeeze(0)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/zhouzhubin/pythorch/Enet/ENet-Real-Time-Semantic-Segmentation/models/ENet.py", line 194, in forward
x, i1 = self.b10(x)
File "/usr/local/lib/python3.5/dist-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "/home/zhouzhubin/pythorch/Enet/ENet-Real-Time-Semantic-Segmentation/models/RDDNeck.py", line 110, in forward
x_copy = torch.cat((x_copy, extras), dim = 1)
RuntimeError: Expected a Tensor of type torch.FloatTensor but found a type torch.cuda.FloatTensor for sequence element 1 in sequence argument at position #1 'tensors'

Process finished with exit code 1

Thank you very much!

@iArunava
image
Why is the result like this? Thank you!

Hi, how are you?
is the shown image is test image? if so can you pass training image add share the results?
by the way, did you pass this image through the preprocessing part? (resizing - if needed, normalizing)

@AvivSham Thank you for your reply! Not the test image. The image I am using is in jpg format and the image size is 266*200.I didn't train the new model, I used the model you provided.I modified your code.
Like this:
image

I just used the images in the Camvid dataset, which is the result.
image
But the class is not right, from the color point of view

Ok. first resize the input image you are using to (3,360,480) same as Camvid dataset than see the preprocess of the loader and normalize the photo in the same manner. Update me if it works for you.

@AvivSham OK. Thank you! I will try it!

@AvivSham
I tried to convert my image from jpg format to png format and it works.
image
But the Class are not the same as yours. For example: roads

Don't worry about that me and @iArunava will look into that. The main thing is that the model segments the image.
How did you load the image? which package did you use?

I used the following code to convert my image.The other is the same as the original.
im = Image.open("01.jpg")
im.save("1_test.png")

Ok we will look into it.

hello, @iArunava & @AvivSham , have u looked the above query.

@iArunava , I'm facing the same issue. I have trained the model with --cuda True and testing with the same setting.
A temporary fix I did was to comment out line 109 in models/RDDNeck.py

        if self.in_channels != self.out_channels:

            out_shape = self.out_channels - self.in_channels

            extras = torch.zeros((bs, out_shape, x.shape[2], x.shape[3]))

            #extras = extras.to(device)

            x_copy = torch.cat((x_copy, extras), dim = 1)

what's the solution of this problem???

Icouldn't change the color of the predicted image?Why?
我显示的预测图片都是蓝绿色?请问怎么才能正常显示呢?
@zhouzhubin

I think there is a problem with your channels, from what I saw the road which should be blue colored is red. This make me think that you are using BGR instead of RGB or vice versa.
@JeremyLinky