Solution: A series of problems encountered by pytorch-ssd during the training process

1. 问题一:pytroch-ssd : RuntimeError: Expected a 'cuda' device type for generator but found 'cpu'

Solution: File "C:\ProgramData\Anaconda3\lib\site-packages\torch\utils\data\sampler.py", line 133, in __iter__ yield from torch.randperm(n, generator=generator).tolist() . Click the link of the error report, navigate to the sampler.py file, find the location shown in Figure 1, modify lines 121 and 122, and change generator = troch.Generator() to generator = torch.Generator(device= 39;cuda').

figure 1

2. Question 2: IndexError: Caught IndexError in DataLoader worker process 0.

Solution: Set num_works to 0, parser.add_argument('--num_workers', default=0, type=int,help='Number of workers used in dataloading')

3. Question 3: When there is only one category, pay attention to

When there is only one category, you need to modify it to NUM_CLASSES= [('people')], and add a square bracket outside the brackets in the category.

4. 问题四:IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

Solution: It means that there are no tags in some xml files, that is, there is no object, so such xml files need to be deleted.

5. 问题五:IndexError: invalid index of a 0-dim tensor. Use tensor.item() in Python or tensor.item<T>()

解决:由于pytorch版本不一致导致的问题,将所有类似报错中的.data[0]改为.item()

# 把data[0]全部改为.item()
self.losses[loss name] = losses [loss name] .data[0]
self.losses[loss name] = losses [loss name] .item()

6. Question 6: StopIteration

Solution: Change 165 lines of code in train.py

images, targets = next(batch_iterator)

Change to:

try:
        images, targets = next(batch_iterator)
except StopIteration:
        batch_iterator = iter(data_loader)
        images, targets = next(batch_iterator)

7. Question 7: During training, LOSS is nan

Solution: You can try changing the learning rate in train.py from 0.001 to 1e-4

8. Question 8: When running eval.py, an error is reported at args = parser.parse_args().pytest errors may occur during the running process

Solution: Change the test_net in the last three lines of the eval.py file to set_net, and change the specific implementation of the method to set_net. When you right-click to run eval.py, it will change from the original run pytest in eval.py to run eval

9. Question 9: When running eval.py, an error is reported: TypeError: can only concatenate str(not "int") to str

Solution: Modify the code in eval.py

# 原代码
# dataset = MaizeDetection(args.voc_root, [('2007', set_type)],
#                        BaseTransform(300, dataset_mean),
#                        MaizeAnnotationTransform())
# 修改后
dataset = MaizeDetection(args.voc_root, set_type,
                       BaseTransform(300, dataset_mean),
                       MaizeAnnotationTransform())

10. 问题十:RuntimeError: Legacy autograd function with non-static forward method is deprecated. Please use new-style autograd function with static forward method. (Example: 

Solution: First modify the contents in detection.py according to http://t.csdnimg.cn/nQ4NQ, and then make the following modifications in ssd.py

# if self.phase == "test":
#    output = self.detect(
#        loc.view(loc.size(0), -1, 4),                   # loc preds
#        self.softmax(conf.view(conf.size(0), -1,
#                     self.num_classes)),                # conf preds
#        self.priors.type(type(x.data))                  # default boxes
#     )
#修改为
if self.phase == "test":
    output = self.detect.apply(self.num_classes, 0, 200, 0.01, 0.45, 
        loc.view(loc.size(0), -1, 4),  # loc preds
        self.softmax(conf.view(-1,
                     self.num_classes)),  # conf preds
        self.priors.type(type(x.data))  # default boxes
             )

11. 问题十一:UserWarning: An output with one or more elements was resized since it had shape [80], which does not match the required output shape [84].

解决: http://t.csdnimg.cn/HmaR3

12. 问题十二:DeprecationWarning: elementwise comparison failed; this will raise an error in the future.   if dets == []: 

Solution: Replace if dets == []: with if len(dets) == 0:.

13. Question 13: DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`.

Solution: Replace the np.bool that appears with bool.

Summary:During the experiment using pytorch-ssd, the data set format was converted in my ownhttp://t.csdnimg. cn/Xahl7The third part of this article; this article is just to record some errors encountered during the experiment and their solutions... 

References:

http://t.csdnimg.cn/5Fiz3

http://t.csdnimg.cn/qLASF

 http://t.csdnimg.cn/EXfQw

 SSD trains its own data set (pytorch version)_ssd trains its own data set pytorch-CSDN blog

 http://t.csdnimg.cn/OFKG4

 http://t.csdnimg.cn/l63YE

 http://t.csdnimg.cn/SkLk0

Guess you like

Origin blog.csdn.net/weixin_44813538/article/details/134480139