Пример #1
0
def CreateAnnotatedDataLayer(source, batch_size=32, backend=P.Data.LMDB,
                             output_label=True, train=True, label_map_file='',
                             transform_param={}, batch_sampler=[{}]):
    if train:
        kwargs = {
            'include': dict(phase=caffe_pb2.Phase.Value('TRAIN')),
            'transform_param': transform_param,
        }
    else:
        kwargs = {
            'include': dict(phase=caffe_pb2.Phase.Value('TEST')),
            'transform_param': transform_param,
        }
    if output_label:
        data, label = L.AnnotatedData(name="data",
                                      annotated_data_param=dict(label_map_file=label_map_file,
                                                                batch_sampler=batch_sampler),
                                      data_param=dict(batch_size=batch_size, backend=backend, source=source),
                                      ntop=2, **kwargs)
        return [data, label]
    else:
        data = L.AnnotatedData(name="data",
                               annotated_data_param=dict(label_map_file=label_map_file,
                                                         batch_sampler=batch_sampler),
                               data_param=dict(batch_size=batch_size, backend=backend, source=source),
                               ntop=1, **kwargs)
        return data
def CreateAnnotatedDataLayer(source, batch_size=32, backend=P.Data.LMDB,
        output_label=True, train=True, label_map_file='', anno_type=None,
        transform_param={}, batch_sampler=[{}]):
    if train:
        kwargs = {
                'include': dict(phase=caffe_pb2.Phase.Value('TRAIN')),
                'transform_param': transform_param,
                }
    else:
        kwargs = {
                'include': dict(phase=caffe_pb2.Phase.Value('TEST')),
                'transform_param': transform_param,
                }
    ntop = 1
    if output_label:
        ntop = 3
    annotated_data_param = {
        'label_map_file': label_map_file,
        'batch_sampler': batch_sampler,
        }
    if anno_type is not None:
        annotated_data_param.update({'anno_type': anno_type})
    return L.AnnotatedData(name="data", annotated_data_param=annotated_data_param,
        data_param=dict(batch_size=batch_size, backend=backend, source=source),
        ntop=ntop, **kwargs)
Пример #3
0
def add_yolo_data_header(net):
  resize_kwargs = [
        dict(prob=0.1,resize_mode=1,height=416,width=416,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=448,width=448,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=480,width=480,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=512,width=512,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=544,width=544,interp_mode=[1,2,3,4,5]),
        #dict(prob=0.1,resize_mode=1,height=576,width=576,interp_mode=[1,2,3,4,5]),
        #dict(prob=0.1,resize_mode=1,height=608,width=608,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=384,width=384,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=352,width=352,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=320,width=320,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=288,width=288,interp_mode=[1,2,3,4,5]),
        dict(prob=0.1,resize_mode=1,height=256,width=256,interp_mode=[1,2,3,4,5])
  ]
  net.data,net.label = L.AnnotatedData(name='data', data_param=dict(batch_size=4, backend=P.Data.LMDB,source='examples/VOC0712/VOC0712_trainval_lmdb'),
                             transform_param=dict(mean_value=[127.5,127.5,127.5],scale=1/127.5, mirror=False,resize_param=resize_kwargs,
                             emit_constraint=dict(emit_type=0),distort_param=dict(brightness_prob=0.5,brightness_delta=32.0,contrast_prob=0.5,contrast_lower=0.5,contrast_upper=1.5,hue_prob=0.5,
                             hue_delta=18.0,saturation_prob=0.5,saturation_lower=0.5,saturation_upper=1.5,random_order_prob=0.0),expand_param=dict(prob=0.5,max_expand_ratio=4.0)),
                             annotated_data_param=dict(yolo_data_type=1,yolo_data_jitter=0.3,label_map_file='data/VOC0712/labelmap_voc.prototxt'),ntop=2, include={'phase':caffe.TRAIN})    
  net.test_data,net.test_label = L.AnnotatedData(name='data', data_param=dict(batch_size=1, backend=P.Data.LMDB,source='examples/VOC0712/VOC0712_test_lmdb'),
                             transform_param=dict(mean_value=[127.5,127.5,127.5],scale=1/127.5, mirror=False,resize_param=dict(prob=1,resize_mode=1,height=416,width=416,interp_mode=[2])),
                             annotated_data_param=dict(batch_sampler=dict(),label_map_file='data/VOC0712/labelmap_voc.prototxt'), top=['data','label'],ntop=2, include={'phase':caffe.TEST})