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

error when testing forward pass #29

Open
Anikily opened this issue Nov 4, 2018 · 4 comments
Open

error when testing forward pass #29

Anikily opened this issue Nov 4, 2018 · 4 comments

Comments

@Anikily
Copy link

Anikily commented Nov 4, 2018

when I test forward pass ,I got such error:
Traceback (most recent call last):
File "darknet_debug.py", line 317, in
model = Darknet('cfg/yolov3.cfg')
File "darknet_debug.py", line 172, in init
self.net_info, self.module_list = create_modules(self.blocks)
File "darknet_debug.py", line 154, in create_modules
anchors = x["anchors"].split(",")
TypeError: string indices must be integers, not str
and I don't think the error originated from my code, because it was reported later on the code that I copied for GitHub.
os:ubontu16.04

@allenwu5
Copy link

allenwu5 commented Nov 4, 2018

Hi @Anikily ,
Maybe you can debug value of x["anchors"] first.
E.g. my case would be this:
x["anchors"] = '10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326'

which is come from https://github.com/ayooshkathuria/YOLO_v3_tutorial_from_scratch/blob/master/cfg/yolov3.cfg

os: macos

@Anikily
Copy link
Author

Anikily commented Nov 4, 2018

thanks ,I have solved this problem, and I encountered another problem :
Traceback (most recent call last):
File "darknet.py", line 238, in
pred = model(inp,torch.cuda.is_available())
File "/home/tensor/anaconda2/envs/py36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 477, in call
result = self.forward(*input, **kwargs)
File "darknet.py", line 227, in forward
x = predict_transform(x,inp_dim,anchors,num_classes,CUDA)
File "/home/tensor/jupyter/luyu/yolo3/util.py", line 79, in predict_transform
prediction[:,:,:2] += x_y_offset
RuntimeError: Expected object of type torch.FloatTensor but found type torch.cuda.FloatTensor for argument #4 'other'
maybe it means that the type of x_y_offset is torch,cuda.FloatTensor,but the type of prediction is torch.FloatTensor and they are not at the same memory address.How should I do?Transform the type of prediction to Cuda?

@allenwu5
Copy link

allenwu5 commented Nov 4, 2018

HI @Anikily ,
I can reproduce the error you encountered on my PC (os: windows10, cuda: available).
Then I do the debug, where x_y_offset.is_cuda = True, but prediction.is_cuda = False.

So I think you might be right, one in GPU but the other in CPU.
Then I added few lines in darknet.py (just pick somewhere looks suitable ...) so that prediction.is_cuda can be True later.

                # Transform
                x = x.data
                if CUDA:
                    x = x.cuda()

Now it pass with exit code 0.

But I still not sure where is a good place to put x = x.cuda() ...

@Anikily
Copy link
Author

Anikily commented Nov 5, 2018

Hi @arashilen , thansks for your reply.I have solved this problem yesterday in a similar way to yours.And I did this step in util.py...in just ablove the line which reported the error.

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