pytorch0.4+cuda10.0+py3.6.5的ssd问题集锦


pytorch0.4+cuda10.0+py3.6.5

 

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

 

问题1:RuntimeError: The shape of the mask [32, 8732] at index 0 does not match the shape of the indexed tensor [279424, 1] at index 0

解决:
修改multibox_loss.py

step1: switch the two lines 97,98:
loss_c = loss_c.view(num, -1)
loss_c[pos] = 0 # filter out pos boxes for now
step2: change the line144 N = num_pos.data.sum() to
N = num_pos.data.sum().double()
loss_l = loss_l.double()/N
loss_c = loss_c.double()/N

问题2:自动跳出迭代:

需要修改3个文件:detection.py; multibox_loss.py; train.py

https://github.com/kentaroy47/ssd.pytorch/commit/4dc4bcead9b5f2d12108a935c85a87dfca83fe82

在运行到3670 后,仍然跳出迭代

再次修改:train.py
batch_iterator = None
    for iteration in range(args.start_iter, cfg['max_iter']):
        if (not batch_iterator) or (iteration % epoch_size == 0):
            batch_iterator = iter(data_loader)
            loc_loss = 0
            conf_loss = 0
            epoch += 1

二:
iter_datasets = len(dataset) // args.batch_size
    epoch_size = cfg['max_iter'] // iter_datasets

    for iteration in range(0, epoch_size):
        for i_batch, (images, targets) in enumerate(data_loader):
            if args.visdom and iteration != 0 and (iteration % epoch_size == 0):
                update_vis_plot(epoch, loc_loss, conf_loss, epoch_plot, None,
                                'append', epoch_size)
                # reset epoch loss counters
                loc_loss = 0
                conf_loss = 0

仍然不解决问题

接着:
这个方案成功:

epoch_size = len(data_loader)

#yxf
        # load train data
        #images, targets = next(batch_iterator)

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


结果:

训练到105000次。精度88%; LOSS: 2.7左右

第一张图:单个鱼可以识别到;  第二张:两个胀气鱼识别到一个;还有一张3条鱼的都可以识别到。

 

 

 

 

你可能感兴趣的:(ssd)