调试SSD-pytorch代码问题汇总

代码链接:https://github.com/amdegroot/ssd.pytorch

1.执行demo-ssd.py,改动detection.py中49行:

if scores.numel() == 0:#scores.dim()

2. multibox_loss.py 中,97行

“loss_c[pos] = 0” 调试过程中发现 loss_c的shape与pos的shape 不同,会出现不匹配错误,因此将此句改为以下:
loss_c[pos.view(-1,1)] = 0

将pos通过view(-1,1) 改为与loss_c相匹配的shape。

3.multibox_loss.py中 N=num_pos.data.sum()的dtype为torch.int64,而进行除法操作的 loss_l 与loss_c的dtype为torch.float32,执行时会出现 ‘torch.cuda.LongTensor but found type torch.cuda.FloatTensor for argument’类似错误,此时需要查看参数类型,将N的类型改为torch.float32即可。 

N = num_pos.data.sum()
N=N.float()

4.train.py代码中,在迭代过程中,每次执行batch张图片,通过images, targets = next(batch_iterator)读取图片时,如果next()中没有数据后会触发Stoplteration异常,使用下面语句替换 images, targets = next(batch_iterator)将解决这种异常问题。

while True:
    try:
        # 获得下一个值:
        images, targets = next(batch_iterator)

    except StopIteration:
        # 遇到StopIteration就退出循环
        break

5.RuntimeError: CUDNN_STATUS_INTERNAL_ERROR的解决办法:

需要清除CUDA缓存,使用sudo进行,但它属于Linux命令,windows中需要进行以下操作:

(1).在任意目录中新建文本文件,命名为sudo.js

(2).用记事本打开刚才新建的文件,粘贴下面代码

var command = WScript.Arguments.Item(0);
var argument = "";
for (var i = 0; i < WScript.Arguments.Count(); ++i){
    argument += WScript.Arguments.Item(i) + " ";
}

try{
    var shellapp = new ActiveXObject("Shell.Application");
    shellapp.ShellExecute(command, argument, null, "runas", 1);
}

catch(e){
    WScript.Echo("Something wrong: " + e.description + " By http://www.alexblair.org");
}

使用cmd打开sudo.js文件即可进行sudo操作。

(3).执行sudo rm -f ~/.nv/    (一定最后边不要漏掉“/”,否则会提示“.nv”是目录)

猜你喜欢

转载自blog.csdn.net/sinat_39307513/article/details/84646177