iArunava / ENet-Real-Time-Semantic-Segmentation

ENet - A Neural Net Architecture for real time Semantic Segmentation
BSD 3-Clause "New" or "Revised" License
278 stars 81 forks source link

run init.py test have a problem #3

Closed zhouzhubin closed 4 years ago

zhouzhubin commented 5 years ago

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

iArunava commented 5 years ago

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

zhouzhubin commented 5 years ago

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

iArunava commented 5 years ago

Okay. I have found what's wrong and ill make the modifications and update here.

On Fri, Mar 1, 2019, 13:20 zhouzhubin notifications@github.com wrote:

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 https://github.com/iArunava/ENet-Real-Time-Semantic-Segmentation/issues/1 'tensors'

Process finished with exit code 1

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/iArunava/ENet-Real-Time-Semantic-Segmentation/issues/3#issuecomment-468575515, or mute the thread https://github.com/notifications/unsubscribe-auth/AZBsMannZU15HK8JCBwplQYcwr_CJuSJks5vSNvFgaJpZM4bYVA- .

zhouzhubin commented 5 years ago

Thank you very much!

zhouzhubin commented 5 years ago

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

AvivSham commented 5 years ago

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)

zhouzhubin commented 5 years ago

@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

AvivSham commented 5 years ago

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.

zhouzhubin commented 5 years ago

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

zhouzhubin commented 5 years ago

@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

AvivSham commented 5 years ago

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?

zhouzhubin commented 5 years ago

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

AvivSham commented 5 years ago

Ok we will look into it.

nayanleo commented 5 years ago

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

chintler commented 5 years ago

@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)
JeremyLinky commented 4 years ago

what's the solution of this problem???

JeremyLinky commented 4 years ago

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

AvivSham commented 4 years ago

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