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

TypeError: string indices must be integers #86

Closed
markdjthomas opened this issue Mar 27, 2021 · 3 comments · Fixed by #87
Closed

TypeError: string indices must be integers #86

markdjthomas opened this issue Mar 27, 2021 · 3 comments · Fixed by #87
Labels
bug / fix Something isn't working question Further information is requested

Comments

@markdjthomas
Copy link

I am trying to train a model using some custom data and keep running into this issue when in model.train() mode.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-49-125710d48032> in <module>
----> 1 out = model(f, t)

~/pytorch/lib/python3.6/site-packages/torch/nn/modules/module.py in _call_impl(self, *input, **kwargs)
    725             result = self._slow_forward(*input, **kwargs)
    726         else:
--> 727             result = self.forward(*input, **kwargs)
    728         for hook in itertools.chain(
    729                 _global_forward_hooks.values(),

yolov5-rt-stack/yolort/models/yolo_module.py in forward(self, inputs, targets)

yolov5-rt-stack/yolort/models/transform.py in postprocess(self, result, image_shapes, original_image_sizes)

TypeError: string indices must be integers

For context f is a list of tensors of shape [3, 257, 79] and t is a list of dicts that look like the following:

{
   'boxes': tensor([[ 6., 14., 21., 61.], [34., 15., 48., 57.]]),
   'labels': tensor([3, 3]),
   'id': tensor([0]),
   'area': tensor([705., 588.]),
   'iscrowd': tensor([0, 0])
}

I feel like this is likely a very obvious issue on my end, but I can't seem to figure it out.

@markdjthomas markdjthomas added the question Further information is requested label Mar 27, 2021
@zhiqwang
Copy link
Owner

zhiqwang commented Mar 29, 2021

Hi @markdjthomas ,

Thanks for the report and your attention here! The trainer with lightning is not stable now, but I'll be looking into fixing this!

@zhiqwang
Copy link
Owner

zhiqwang commented Apr 8, 2021

Hi @markdjthomas

Sorry for not solving this problem for a while, I was on vacation a few days ago.

I've written a unit-test in #87 to reproduce this bug and now it can report the same error in GH Actions. It seems that there are some bugs in the vanilla yolov5 module

https://github.com/zhiqwang/yolov5-rt-stack/blob/c4d3962bc4bb4dccf612dedf67aa9cc9eb89376a/yolort/models/yolo_module.py#L19

One should use the training_step to train a model.

https://github.com/zhiqwang/yolov5-rt-stack/blob/c4d3962bc4bb4dccf612dedf67aa9cc9eb89376a/yolort/models/yolo_module.py#L86-L95

In other words, yolort currently only supports training with following interface (Just test for VOC datasets)

CUDA_VISIBLE_DEVICES=0 python -m yolort.train --data_path ./data-bin/voc_devkit --dataset_type voc --years 2007 2012 --num_gpus 1

And there is a unit-test for training with COCO type dataset here.

My next plan is to integrate self.transform into the model to eliminate this problem.

@zhiqwang
Copy link
Owner

zhiqwang commented Apr 8, 2021

@markdjthomas

I've fixed training with the vanilla module, you can check the unit-test for more details, therefore I'm closing this issue. And please let me know if you have more questions.

zhiqwang added a commit that referenced this issue Apr 8, 2021
* Fix UserWarning of torch.tensor(sourceTensor)

* Reproduce the bug in #86

* Support training with the vanilla module

* Fix jit scripting bugs
@zhiqwang zhiqwang added the bug / fix Something isn't working label Apr 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug / fix Something isn't working question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants