Paddle SSD训练模型验证评估阶段mAP值获取错误,单类目标检测问题

hgqdbh6s  于 2021-11-30  发布在  Java
关注(0)|答案(9)|浏览(341)
  • 版本、环境信息:

   1)PaddlePaddle版本:paddlepaddle-1.5.2
   2)CPU:Intel Core i7
   3)GPU:AMD (使用CPU训练)
   4)系统环境:Windows10、VS2017、Python36_64

  • 模型信息

   1)模型名称:SSD
2)使用数据集名称:pascalvoc(2007+2012)
3)使用算法名称:课程9-深度学习进阶CV-目标检测
4)模型链接:https://aistudio.baidu.com/aistudio/projectdetail/78972

  • 问题描述:

先对算法中多线程读取训练数据改成单线程获取,因为在windows中多线程会出错。
然后对针对原始数据集进行训练和验证,一切正常
修改数据集:在train.txt中筛选出“person”类的所有记录组成新的train.txt;修改label_list文件,只保留“person”
然后进行训练和验证,训练阶段没问题,验证阶段执行到获取mAP值时出现错误,出错位置代码如下:
map_eval = fluid.metrics.DetectionMAP(nmsed_out, gt_label, gt_box, difficult,
train_parameters['class_dim'], overlap_threshold=0.5,
evaluate_difficult=False, ap_version='11point')
错误信息如下:
Invoke operator detection_map error. Python Call stacks: File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\framework.py", line 1774, in append_op attrs=kwargs.get("attrs", None)) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\layer_helper.py", line 43, in append_op return self.main_program.current_block().append_op(*kwargs) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\layers\detection.py", line 1058, in detection_map 'class_num': class_num, File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\metrics.py", line 802, ininitap_version=ap_version) File "C:\Users\lxw\source\repos\PythonApplication1\PythonApplication1\module2.py", line 663, in build_eval_program_with_feeder evaluate_difficult=False, ap_version='11point') File "C:\Users\lxw\source\repos\PythonApplication1\PythonApplication1\module2.py", line 765, in eval_feeder, eval_reader, cur_map, accum_map, nmsed_out = build_eval_program_with_feeder(eval_program, start_program) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd_pydev_imps_pydev_execfile.py", line 25, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd\pydevd.py", line 1106, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd\pydevd.py", line 1099, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd\pydevd.py", line 1752, in main globals = debugger.run(setup['file'], None, None, is_module) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_local.py", line 125, in _run _pydevd.main() File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_local.py", line 64, in run_file run(argv, addr, kwargs) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\debugger.py", line 37, in debug run(address, filename, *args, kwargs) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\ptvsd_launcher.py", line 119, in vspd.debug(filename, port_num, debug_id, debug_options, run_as) C++ Call stacks: Enforce failed. Expected det_dims[1] == 6UL, but received det_dims[1]:1 != 6UL:6. The shape is of Input(DetectRes) [N, 6]. at [D:\1.5.2\paddle\paddle\fluid\operators\detection_map_op.cc:49] PaddlePaddle Call Stacks: Windows not support stack backtrace yet.

中断在如下位置:
except fluid.core.EOFException:
train_reader.reset()

log信息如下:
2019-09-25 23:02:43,359 - module2.py[line:750] - INFO: start ssd, train params: {'input_size': [3, 300, 300], 'class_dim': 1, 'label_dict': {'person': 0}, 'image_count': 128, 'log_feed_image': False, 'pretrained': True, 'pretrained_model_dir': './pretrained-model', 'continue_train': True, 'save_model_dir': './ssd-model', 'model_prefix': 'mobilenet-ssd', 'data_dir': 'c:/pascalvoc', 'mean_rgb': [127.5, 127.5, 127.5], 'file_list': 'train_person.txt', 'eval_file_list': 'eval_person1111.txt', 'label_list': 'label_list11111', 'mode': 'train', 'num_epochs': 400, 'train_batch_size': 64, 'use_gpu': False, 'apply_distort': True, 'apply_expand': True, 'apply_corp': True, 'image_distort_strategy': {'expand_prob': 0.5, 'expand_max_ratio': 4, 'hue_prob': 0.5, 'hue_delta': 18, 'contrast_prob': 0.5, 'contrast_delta': 0.5, 'saturation_prob': 0.5, 'saturation_delta': 0.5, 'brightness_prob': 0.5, 'brightness_delta': 0.125}, 'rsm_strategy': {'learning_rate': 0.001, 'lr_epochs': [40, 60, 80, 100], 'lr_decay': [1, 0.5, 0.25, 0.1, 0.01]}, 'momentum_strategy': {'learning_rate': 0.1, 'decay_steps': 128, 'decay_rate': 0.8}, 'early_stop': {'sample_frequency': 50, 'successive_limit': 3, 'min_loss': 1.28, 'min_curr_map': 0.86}}
2019-09-25 23:02:43,360 - module2.py[line:753] - INFO: create place, use gpu:False
2019-09-25 23:02:43,360 - module2.py[line:757] - INFO: build network and program
2019-09-25 23:02:49,436 - module2.py[line:768] - INFO: build executor and init params
2019-09-25 23:02:49,736 - module2.py[line:729] - INFO: load param from pretrained model
2019-09-25 23:02:49,966 - module2.py[line:790] - INFO: current pass: 0, start read image
2019-09-25 23:03:28,768 - module2.py[line:803] - INFO: Pass 0, trainbatch 1, loss 4.720804214477539 time 38.77 sec

问题诊断(定位)方法(思路):
1、修改label_list文件,使之多于一个类,如再加入“cat”类。实际上随便加任何名字的类如“aaa”。程序都能正常训练和验证,不会报错。
2、注解掉
map_eval = fluid.metrics.DetectionMAP(nmsed_out, gt_label, gt_box, difficult,
train_parameters['class_dim'], overlap_threshold=0.5,
evaluate_difficult=False, ap_version='11point')
这条语句。以及注解或修改与这条语句返回值有关语句若干条语句,使之验证过程中不需要使用cur_map_v和accum_map_v,程序能正常训练和验证,不会报错。

pgpifvop

pgpifvop1#

可以打印下nmsed_out 的shape是不是空,还有label里还需要有背景类

mzsu5hc0

mzsu5hc02#

如何打印shape?背景类是什么?是指训练时需要有不存在目标类的样本吗?

sycxhyv7

sycxhyv73#

1、我先修改了build_train_program_with_async_reader函数,使之与build_eval_program_with_feeder函数除误差估计、优化算法不一样外,读取数据的形式完全一致。函数如下:
def build_train_program_with_async_reader(main_prog, startup_prog):
with fluid.program_guard(main_prog, startup_prog): #该函数应配合使用python的“with”语句来改变全局主程序(main program)和启动程序(startup program)。
#定义下面四个数据格式,因为create_py_reader_by_data里面需要告诉它这些格式
img = fluid.layers.data(name='img', shape=train_parameters['input_size'], dtype='float32')
gt_box = fluid.layers.data(name='gt_box', shape=[4], dtype='float32', lod_level=1)
gt_label = fluid.layers.data(name='gt_label', shape=[1], dtype='int32', lod_level=1)
difficult = fluid.layers.data(name='difficult', shape=[1], dtype='int32', lod_level=1) #一个整数,表示目标是否容易识别,0表示容易识别
#负责将reader(读取器)返回的数据转成一种特殊的数据结构,使它们可以输入到 Executor 和 ParallelExecutor 中
feeder = fluid.DataFeeder(feed_list=[img, gt_box, gt_label, difficult], place=place, program=main_prog)


# 获取按照数据集形式组织好的所有训练数据

    reader = create_eval_reader(train_parameters['file_list'], train_parameters['data_dir'], 'train')
    with fluid.unique_name.guard():
        model = MobileNetSSD()
        #输出:预测框(人们标定好的目标框)的输入位置(中心点的坐标、长、宽)[N,H * W * Priors,4]、预测框对输入的置信度[N,H * W * Priors,C]、候选框[num_priors,4]、方差[num_priors,4]。
        #其中Priors 是每个输入位置的预测框数,C是类的数量,num_priors 是每个输入位置的总框数
        locs, confs, box, box_var = model.net(train_parameters['class_dim'], img, train_parameters['input_size'])  #class_dim:图像分类数;img:图像(一张);input_size:图像大小

        with fluid.unique_name.guard('train'): #更改全局命名空间
            ''' 
            locs:预测得到的候选框的位置(中心点的坐标、长、宽)
            confs:每个类别的置信度
            gt_box:groud_truth的位置
            gt_label:ground_tru
            box:候选框的位置
            box_var:方差
            '''
            #paddlepaddle提供了ssd_loss(),返回ssd算法中回归损失和分类损失的加权和
            loss = fluid.layers.ssd_loss(locs, confs, gt_box, gt_label, box, box_var)
            loss = fluid.layers.reduce_sum(loss)
            optimizer = optimizer_rms_setting()   #调用自适应学习率
            optimizer.minimize(loss)
            return feeder, reader, loss, locs, confs, box, box_var

def build_eval_program_with_feeder(main_prog, startup_prog):
with fluid.program_guard(main_prog, startup_prog):
img = fluid.layers.data(name='img', shape=train_parameters['input_size'], dtype='float32')
gt_box = fluid.layers.data(name='gt_box', shape=[4], dtype='float32', lod_level=1)
gt_label = fluid.layers.data(name='gt_label', shape=[1], dtype='int32', lod_level=1)
difficult = fluid.layers.data(name='difficult', shape=[1], dtype='int32', lod_level=1)
#负责将reader(读取器)返回的数据转成一种特殊的数据结构,使它们可以输入到 Executor 和 ParallelExecutor 中
feeder = fluid.DataFeeder(feed_list=[img, gt_box, gt_label, difficult], place=place, program=main_prog)


# 获取按照数据集形式组织好的所有验证数据

    reader = create_eval_reader(train_parameters['eval_file_list'], train_parameters['data_dir'], 'eval')
    with fluid.unique_name.guard():
        model = MobileNetSSD()
        #输出:预测框(人们标定好的目标框)的输入位置(中心点的坐标、长、宽)[N,H * W * Priors,4]、预测框对输入的置信度[N,H * W * Priors,C]、候选框[num_priors,4]、方差[num_priors,4]。
        #其中Priors 是每个输入位置的预测框数,C是类的数量,num_priors 是每个输入位置的总框数
        locs, confs, box, box_var = model.net(train_parameters['class_dim'], img, train_parameters['input_size'])  #class_dim:图像分类数;img:图像(一张);input_size:图像大小
        with fluid.unique_name.guard('eval'):  #更改全局命名空间
            nmsed_out = fluid.layers.detection_output(locs, confs, box, box_var, nms_threshold=0.45)   #非极大值抑制得到的结果
            #nmsed_out = fluid.create_lod_tensor(np.array([[0.1], [0.1],[0.3],[0.3]]).astype('float32'), [[1,3]], fluid.CPUPlace())
            map_eval = fluid.metrics.DetectionMAP(nmsed_out, gt_label, gt_box, difficult,              #计算map,单类目标会出错
                                                  train_parameters['class_dim'], overlap_threshold=0.5,
                                                  evaluate_difficult=False, ap_version='11point')
            '''
            “cur_map” 是当前 mini-batch 的 mAP
            "accum_map"是一个pass的mAP的累加和  
            '''
            cur_map, accum_map = map_eval.get_map_var()
            return feeder, reader, cur_map, accum_map, nmsed_out

2、修改train_parameters的file_list和eval_file_list都为train_person.txt,使之训练和验证的数据集完全一致。
3、修改train_batch_size为1,并且训练一个样本就马上用一个样本验证。目的是比较两个run为什么一个能执行,一个会出错。并且方便把验证样本和训练样本打印出来比较。
4、修改
try:
while True:
t1 = time.time()
loss = exe.run(train_program, fetch_list=train_fetch_list)
…………
语句段为下列形式:
for train_data in train_reader():
logger.info('train_data大小:%d',len(train_data))
logger.info(train_data[0])
logger.info('==================\n')
t1 = time.time()
loss = exe.run(train_program,feed=train_feeder.feed(train_data), fetch_list=train_fetch_list)
…………
修改
for data in eval_reader():
cur_map_v, accum_map_v = exe.run(eval_program, feed=eval_feeder.feed(data), fetch_list=eval_fetch_list)
…………
语句段为下列形式:
for eval_data in eval_reader():
logger.info('eval_data大小:%d',len(eval_data))
logger.info(eval_data[0])
logger.info('==================\n')
cur_map_v, accum_map_v = exe.run(eval_program, feed=eval_feeder.feed(eval_data), fetch_list=eval_fetch_list)
…………
5、当目标类别多于一类时(用了person和cat),训练和验证都能正确执行,log中打印了训练和验证数据:
2019-09-27 00:59:08,382 - MobileNet-SSD.py[line:746] - INFO: start ssd, train params: {'input_size': [3, 300, 300], 'class_dim': 2, 'label_dict': {'person': 0, 'cat': 1}, 'image_count': 128, 'log_feed_image': False, 'pretrained': True, 'pretrained_model_dir': './pretrained-model', 'continue_train': True, 'save_model_dir': './ssd-model', 'model_prefix': 'mobilenet-ssd', 'data_dir': 'c:/pascalvoc', 'mean_rgb': [127.5, 127.5, 127.5], 'file_list': 'train_person.txt', 'eval_file_list': 'train_person.txt', 'label_list': 'label_list11111', 'mode': 'train', 'num_epochs': 400, 'train_batch_size': 1, 'use_gpu': False, 'apply_distort': True, 'apply_expand': True, 'apply_corp': True, 'image_distort_strategy': {'expand_prob': 0.5, 'expand_max_ratio': 4, 'hue_prob': 0.5, 'hue_delta': 18, 'contrast_prob': 0.5, 'contrast_delta': 0.5, 'saturation_prob': 0.5, 'saturation_delta': 0.5, 'brightness_prob': 0.5, 'brightness_delta': 0.125}, 'rsm_strategy': {'learning_rate': 0.001, 'lr_epochs': [40, 60, 80, 100], 'lr_decay': [1, 0.5, 0.25, 0.1, 0.01]}, 'momentum_strategy': {'learning_rate': 0.1, 'decay_steps': 128, 'decay_rate': 0.8}, 'early_stop': {'sample_frequency': 50, 'successive_limit': 3, 'min_loss': 1.28, 'min_curr_map': 0.86}}
2019-09-27 00:59:08,383 - MobileNet-SSD.py[line:749] - INFO: create place, use gpu:False
2019-09-27 00:59:08,383 - MobileNet-SSD.py[line:753] - INFO: build network and program
2019-09-27 00:59:14,048 - MobileNet-SSD.py[line:764] - INFO: build executor and init params
2019-09-27 00:59:14,353 - MobileNet-SSD.py[line:725] - INFO: load param from pretrained model
2019-09-27 00:59:14,599 - MobileNet-SSD.py[line:789] - INFO: current pass: 0, start read image
2019-09-27 00:59:14,675 - MobileNet-SSD.py[line:793] - INFO: train_data大小:1
2019-09-27 00:59:14,675 - MobileNet-SSD.py[line:794] - INFO: (array([[[ 0.0431365 , 0.0823515 , 0.0666655 , ..., -0.21568249,
-0.1607815 , -0.2078395 ],
[ 0.0274505 , 0.0431365 , 0.0352935 , ..., -0.1843105 ,
-0.2235255 , -0.1607815 ],
[ 0.0823515 , 0.0509795 , 0.0431365 , ..., -0.1529385 ,
-0.1058805 , -0.12940949],
...,
[-0.8744945 , -0.8195935 , -0.8823375 , ..., -0.8823375 ,
-0.83527946, -0.9058665 ],
[-0.7882215 , -0.8117505 , -0.7882215 , ..., -0.9293955 ,
-0.83527946, -0.85880846],
[-0.8509655 , -0.8823375 , -0.8274365 , ..., -0.89018047,
-0.8744945 , -0.9215525 ]],

[[ 0.1137235 ,  0.12940949,  0.1372525 , ..., -0.0274505 ,
      0.0509795 , -0.0509795 ],
    [ 0.0901945 ,  0.1137235 ,  0.1058805 , ..., -0.0431365 ,
     -0.0509795 , -0.0196075 ],
    [ 0.1372525 ,  0.0823515 ,  0.1137235 , ..., -0.0901945 ,
     -0.0352935 , -0.0117645 ],
    ...,
    [-0.8509655 , -0.8117505 , -0.8509655 , ..., -0.91370946,
     -0.8666515 , -0.9372385 ],
    [-0.8117505 , -0.8195935 , -0.8039075 , ..., -0.9607675 ,
     -0.8666515 , -0.8823375 ],
    [-0.8509655 , -0.8980235 , -0.8509655 , ..., -0.91370946,
     -0.8980235 , -0.9450815 ]],

   [[-0.0196075 ,  0.0274505 ,  0.0274505 , ..., -0.0039215 ,
      0.0666655 , -0.0431365 ],
    [-0.0509795 , -0.0196075 , -0.0039215 , ..., -0.0039215 ,
     -0.0431365 , -0.0117645 ],
    [ 0.0196075 , -0.0039215 , -0.0039215 , ..., -0.0666655 ,
     -0.0352935 , -0.0039215 ],
    ...,
    [-0.85880846, -0.8117505 , -0.8744945 , ..., -0.9529245 ,
     -0.9215525 , -0.9842965 ],
    [-0.7960645 , -0.8195935 , -0.83527946, ..., -0.9999825 ,
     -0.9450815 , -0.96861047],
    [-0.8509655 , -0.89018047, -0.8744945 , ..., -0.96861047,
     -0.9764535 , -0.9999825 ]]], dtype=float32), array([[0.05826534, 0.1108887 , 0.93554619, 1.        ]]), array([0]), array([0]))

2019-09-27 00:59:14,679 - MobileNet-SSD.py[line:795] - INFO: ====================================================================================

2019-09-27 00:59:15,185 - MobileNet-SSD.py[line:807] - INFO: Pass 0, trainbatch 1, loss 13.74333381652832 time 0.51 sec
2019-09-27 00:59:15,194 - MobileNet-SSD.py[line:823] - INFO: eval_data大小:1
2019-09-27 00:59:15,194 - MobileNet-SSD.py[line:824] - INFO: (array([[[-0.36469948, -0.1843105 , -0.1764675 , ..., -0.1529385 ,
-0.1529385 , -0.1529385 ],
[-0.32548448, -0.2235255 , -0.1843105 , ..., -0.1843105 ,
-0.1607815 , -0.1921535 ],
[-0.3882285 , -0.2470545 , -0.1921535 , ..., -0.1843105 ,
-0.1921535 , -0.2078395 ],
...,
[-0.2078395 , -0.2078395 , -0.2862695 , ..., -0.9058665 ,
-0.9372385 , -0.9215525 ],
[-0.2627405 , -0.2470545 , -0.2313685 , ..., -0.9215525 ,
-0.9372385 , -0.9450815 ],
[-0.2784265 , -0.1921535 , -0.1921535 , ..., -0.8666515 ,
-0.9058665 , -0.9215525 ]],

[[-0.3490135 , -0.1764675 , -0.1137235 , ..., -0.0666655 ,
     -0.0745085 , -0.0745085 ],
    [-0.3097985 , -0.2078395 , -0.0980375 , ..., -0.0745085 ,
     -0.0588225 , -0.0823515 ],
    [-0.36469948, -0.21568249, -0.1058805 , ..., -0.0509795 ,
     -0.0588225 , -0.0666655 ],
    ...,
    [-0.2235255 , -0.2392115 , -0.2627405 , ..., -0.9450815 ,
     -0.9607675 , -0.9293955 ],
    [-0.2235255 , -0.2548975 , -0.2313685 , ..., -0.9607675 ,
     -0.9607675 , -0.9529245 ],
    [-0.2313685 , -0.2078395 , -0.21568249, ..., -0.9215525 ,
     -0.9529245 , -0.9529245 ]],

   [[-0.4352865 , -0.2313685 , -0.1607815 , ..., -0.0901945 ,
     -0.0823515 , -0.0901945 ],
    [-0.3960715 , -0.2705835 , -0.1529385 , ..., -0.1058805 ,
     -0.0745085 , -0.0980375 ],
    [-0.4509725 , -0.2784265 , -0.1607815 , ..., -0.0901945 ,
     -0.0823515 , -0.0901945 ],
    ...,
    [-0.3097985 , -0.3176415 , -0.3411705 , ..., -0.9607675 ,
     -0.9842965 , -0.9529245 ],
    [-0.3097985 , -0.3176415 , -0.2784265 , ..., -0.9764535 ,
     -0.99213946, -0.9764535 ],
    [-0.3019555 , -0.2548975 , -0.2470545 , ..., -0.9450815 ,
     -0.96861047, -0.9607675 ]]], dtype=float32), array([[0.248     , 0.14933333, 0.932     , 1.        ]]), array([0]), array([0]))

2019-09-27 00:59:15,198 - MobileNet-SSD.py[line:825] - INFO: ====================================================================================

四个array分别是img、box、label、difficult。两个样本的数据格式一致

5、当目标类别只有一类时(用了person),训练能正确执行,验证的run出错,log中打印了训练和验证数据:
2019-09-27 01:02:36,767 - MobileNet-SSD.py[line:746] - INFO: start ssd, train params: {'input_size': [3, 300, 300], 'class_dim': 1, 'label_dict': {'person': 0}, 'image_count': 128, 'log_feed_image': False, 'pretrained': True, 'pretrained_model_dir': './pretrained-model', 'continue_train': True, 'save_model_dir': './ssd-model', 'model_prefix': 'mobilenet-ssd', 'data_dir': 'c:/pascalvoc', 'mean_rgb': [127.5, 127.5, 127.5], 'file_list': 'train_person.txt', 'eval_file_list': 'train_person.txt', 'label_list': 'label_list11111', 'mode': 'train', 'num_epochs': 400, 'train_batch_size': 1, 'use_gpu': False, 'apply_distort': True, 'apply_expand': True, 'apply_corp': True, 'image_distort_strategy': {'expand_prob': 0.5, 'expand_max_ratio': 4, 'hue_prob': 0.5, 'hue_delta': 18, 'contrast_prob': 0.5, 'contrast_delta': 0.5, 'saturation_prob': 0.5, 'saturation_delta': 0.5, 'brightness_prob': 0.5, 'brightness_delta': 0.125}, 'rsm_strategy': {'learning_rate': 0.001, 'lr_epochs': [40, 60, 80, 100], 'lr_decay': [1, 0.5, 0.25, 0.1, 0.01]}, 'momentum_strategy': {'learning_rate': 0.1, 'decay_steps': 128, 'decay_rate': 0.8}, 'early_stop': {'sample_frequency': 50, 'successive_limit': 3, 'min_loss': 1.28, 'min_curr_map': 0.86}}
2019-09-27 01:02:36,768 - MobileNet-SSD.py[line:749] - INFO: create place, use gpu:False
2019-09-27 01:02:36,768 - MobileNet-SSD.py[line:753] - INFO: build network and program
2019-09-27 01:02:42,605 - MobileNet-SSD.py[line:764] - INFO: build executor and init params
2019-09-27 01:02:42,926 - MobileNet-SSD.py[line:725] - INFO: load param from pretrained model
2019-09-27 01:02:43,172 - MobileNet-SSD.py[line:789] - INFO: current pass: 0, start read image
2019-09-27 01:02:43,238 - MobileNet-SSD.py[line:793] - INFO: train_data大小:1
2019-09-27 01:02:43,238 - MobileNet-SSD.py[line:794] - INFO: (array([[[ 0.12940949, 0.1529385 , 0.1764675 , ..., -0.1372525 ,
-0.1764675 , -0.2392115 ],
[ 0.1529385 , 0.1764675 , 0.1921535 , ..., -0.1764675 ,
-0.1843105 , -0.21568249],
[ 0.1764675 , 0.1843105 , 0.1921535 , ..., -0.2470545 ,
-0.1921535 , -0.1529385 ],
...,
[-0.3411705 , -0.36469948, -0.4196005 , ..., -0.3490135 ,
-0.3490135 , -0.3019555 ],
[-0.3725425 , -0.40391448, -0.4274435 , ..., -0.3019555 ,
-0.3333275 , -0.3411705 ],
[-0.4274435 , -0.4352865 , -0.4509725 , ..., -0.2862695 ,
-0.3097985 , -0.3490135 ]],

[[ 0.1529385 ,  0.1764675 ,  0.1999965 , ..., -0.0666655 ,
     -0.1137235 , -0.1921535 ],
    [ 0.1764675 ,  0.1999965 ,  0.2078395 , ..., -0.1058805 ,
     -0.1215665 , -0.1529385 ],
    [ 0.2078395 ,  0.21568249,  0.2235255 , ..., -0.1764675 ,
     -0.1215665 , -0.0745085 ],
    ...,
    [-0.3019555 , -0.3176415 , -0.36469948, ..., -0.3019555 ,
     -0.3097985 , -0.2705835 ],
    [-0.3490135 , -0.36469948, -0.3725425 , ..., -0.2705835 ,
     -0.3019555 , -0.3176415 ],
    [-0.3725425 , -0.3882285 , -0.3960715 , ..., -0.2627405 ,
     -0.2862695 , -0.32548448]],

   [[ 0.1607815 ,  0.1764675 ,  0.1921535 , ..., -0.0588225 ,
     -0.1137235 , -0.1921535 ],
    [ 0.1764675 ,  0.1921535 ,  0.2078395 , ..., -0.1137235 ,
     -0.1215665 , -0.1607815 ],
    [ 0.1999965 ,  0.2078395 ,  0.2235255 , ..., -0.1764675 ,
     -0.12940949, -0.0823515 ],
    ...,
    [-0.2784265 , -0.3097985 , -0.3490135 , ..., -0.3411705 ,
     -0.3568565 , -0.3176415 ],
    [-0.3176415 , -0.3411705 , -0.36469948, ..., -0.3097985 ,
     -0.3490135 , -0.36469948],
    [-0.3490135 , -0.3725425 , -0.3882285 , ..., -0.3019555 ,
     -0.3333275 , -0.3725425 ]]], dtype=float32), array([[0.        , 0.12889219, 0.87890917, 1.        ]]), array([0]), array([0]))

2019-09-27 01:02:43,242 - MobileNet-SSD.py[line:795] - INFO: ====================================================================================

2019-09-27 01:02:43,720 - MobileNet-SSD.py[line:807] - INFO: Pass 0, trainbatch 1, loss 3.3073534965515137 time 0.48 sec
2019-09-27 01:02:43,728 - MobileNet-SSD.py[line:823] - INFO: eval_data大小:1
2019-09-27 01:02:43,728 - MobileNet-SSD.py[line:824] - INFO: (array([[[-0.36469948, -0.1843105 , -0.1764675 , ..., -0.1529385 ,
-0.1529385 , -0.1529385 ],
[-0.32548448, -0.2235255 , -0.1843105 , ..., -0.1843105 ,
-0.1607815 , -0.1921535 ],
[-0.3882285 , -0.2470545 , -0.1921535 , ..., -0.1843105 ,
-0.1921535 , -0.2078395 ],
...,
[-0.2078395 , -0.2078395 , -0.2862695 , ..., -0.9058665 ,
-0.9372385 , -0.9215525 ],
[-0.2627405 , -0.2470545 , -0.2313685 , ..., -0.9215525 ,
-0.9372385 , -0.9450815 ],
[-0.2784265 , -0.1921535 , -0.1921535 , ..., -0.8666515 ,
-0.9058665 , -0.9215525 ]],

[[-0.3490135 , -0.1764675 , -0.1137235 , ..., -0.0666655 ,
     -0.0745085 , -0.0745085 ],
    [-0.3097985 , -0.2078395 , -0.0980375 , ..., -0.0745085 ,
     -0.0588225 , -0.0823515 ],
    [-0.36469948, -0.21568249, -0.1058805 , ..., -0.0509795 ,
     -0.0588225 , -0.0666655 ],
    ...,
    [-0.2235255 , -0.2392115 , -0.2627405 , ..., -0.9450815 ,
     -0.9607675 , -0.9293955 ],
    [-0.2235255 , -0.2548975 , -0.2313685 , ..., -0.9607675 ,
     -0.9607675 , -0.9529245 ],
    [-0.2313685 , -0.2078395 , -0.21568249, ..., -0.9215525 ,
     -0.9529245 , -0.9529245 ]],

   [[-0.4352865 , -0.2313685 , -0.1607815 , ..., -0.0901945 ,
     -0.0823515 , -0.0901945 ],
    [-0.3960715 , -0.2705835 , -0.1529385 , ..., -0.1058805 ,
     -0.0745085 , -0.0980375 ],
    [-0.4509725 , -0.2784265 , -0.1607815 , ..., -0.0901945 ,
     -0.0823515 , -0.0901945 ],
    ...,
    [-0.3097985 , -0.3176415 , -0.3411705 , ..., -0.9607675 ,
     -0.9842965 , -0.9529245 ],
    [-0.3097985 , -0.3176415 , -0.2784265 , ..., -0.9764535 ,
     -0.99213946, -0.9764535 ],
    [-0.3019555 , -0.2548975 , -0.2470545 , ..., -0.9450815 ,
     -0.96861047, -0.9607675 ]]], dtype=float32), array([[0.248     , 0.14933333, 0.932     , 1.        ]]), array([0]), array([0]))

2019-09-27 01:02:43,732 - MobileNet-SSD.py[line:825] - INFO: ====================================================================================

两个样本的数据格式一致,并且与多目标测试时的数据格式也一致。

错误信息如下:
Invoke operator detection_map error. Python Call stacks: File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\framework.py", line 1774, in append_op attrs=kwargs.get("attrs", None)) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\layer_helper.py", line 43, in append_op return self.main_program.current_block().append_op(*kwargs) File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\layers\detection.py", line 1058, in detection_map 'class_num': class_num, File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\paddle\fluid\metrics.py", line 802, ininitap_version=ap_version) File "C:\Users\lxw\source\repos\PythonApplication1\PythonApplication1\MobileNet-SSD.py", line 659, in build_eval_program_with_feeder evaluate_difficult=False, ap_version='11point') File "C:\Users\lxw\source\repos\PythonApplication1\PythonApplication1\MobileNet-SSD.py", line 761, in eval_feeder, eval_reader, cur_map, accum_map, nmsed_out = build_eval_program_with_feeder(eval_program, start_program) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd_pydev_imps_pydev_execfile.py", line 25, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd\pydevd.py", line 1106, in _exec pydev_imports.execfile(file, globals, locals) # execute the script File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd\pydevd.py", line 1099, in run return self._exec(is_module, entry_point_fn, module_name, file, globals, locals) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_vendored\pydevd\pydevd.py", line 1752, in main globals = debugger.run(setup['file'], None, None, is_module) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_local.py", line 125, in _run _pydevd.main() File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd_local.py", line 64, in run_file run(argv, addr, kwargs) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\Packages\ptvsd\debugger.py", line 37, in debug run(address, filename, *args, kwargs) File "c:\program files (x86)\microsoft visual studio\2017\enterprise\common7\ide\extensions\microsoft\python\core\ptvsd_launcher.py", line 119, in vspd.debug(filename, port_num, debug_id, debug_options, run_as) C++ Call stacks: Enforce failed. Expected det_dims[1] == 6UL, but received det_dims[1]:1 != 6UL:6. The shape is of Input(DetectRes) [N, 6]. at [D:\1.5.2\paddle\paddle\fluid\operators\detection_map_op.cc:49] PaddlePaddle Call Stacks: Windows not support stack backtrace yet.

问题到底出在哪里???????????
通过注解相关代码来定位出错位置可以发现,只要不使用fluid.metrics.DetectionMAP函数,单分类就不会出错。

daupos2t

daupos2t4#

为了便于比较,我注解掉了reader函数的np.random.shuffle(file_list)语句,目的是为了每次测试用的是同一个样本:
def custom_reader(file_list, data_dir, mode):
def reader():
#np.random.shuffle(file_list)
for line in file_list:
if mode == 'train' or mode == 'eval':
………………
上面两次测试运行的run确实取得是同一个样本,可以通过两次测试的验证阶段的log数据可以看出来。两个log的验证数据是完全一致的。

smdnsysy

smdnsysy5#

background_label默认是0,而如果label_list里只有一类,那获得的person类就是0,最后在计算时,相当于没有正样本,报错了;可以修改background_label这个参数,或者修改label_list

dgiusagp

dgiusagp6#

非常感谢!症结应该就在这里。关于metrics.DetectionMAP函数的细节上再请教一下。
(1)若把background_label设成-1,若只有一类,还是会出错,出错原因是否是只存在一类样本而无法分成正类样本和负类样本所以无法计算是吗?(label_list中有两个类就不会出错)
(2)若把background_label设为1(目的是避开只有一类样本时,样本类别为0而被作为背景类),单目标还是会出错,出错原因跟(1)一致,是吗?
(3)若background_label默认为0,在多目标检测中,第一类(就是被标为0的那类)就会作为背景类,因为mAP是每个类的平均精度的平均值,作为背景类从而不参与计算mAP,是吗?也就是说计算存在误差,若只有两类,那误差会比较大是吗?
(4)根据文档说明,若把background_label设成-1,所以类都被考虑,不知是何意思。是否指每个类都会参与mAP计算,与(3)相比就不存在上述误差,是吗?若是这样,这个函数设计时不是默认为-1更好?因为列在label_list中的类别都是需要识别的,而不会把第一个类别作为背景类来用。
(5)按照mAP的定义,似乎不需要存在负类的说法,只需计算每个类的平均精度然后再求所有类的平均精度即可,那为什么还要有个背景类呢?背景类有什么用处?是否就是负类?
请按照上述顺序给予一一解惑,不胜感激!

pxy2qtax

pxy2qtax7#

还要,若就想检测一个类得怎么办?难道一定得弄个背景类放到label_list中吗?背景类是否需要有实际数据,比如只要识别person,但在label_list中放cat和person,计算所得是否就是person的mAP吗?而在实际样本中可以没有cat,是吗?

wnrlj8wa

wnrlj8wa8#

你就在label_list里第一个位置,放个background就行了

tmb3ates

tmb3ates9#

那这个函数不是设计的有点莫名其妙吗,还非得让用户在label_list里面的第一行放一个“垃圾类”background

相关问题