未验证 提交 50381eda 编写于 作者: W wangguanzhong 提交者: GitHub

revert fluid.data to fluid.layers.data (#42)

上级 9229209b
...@@ -14,14 +14,14 @@ ...@@ -14,14 +14,14 @@
使用[训练/评估/推断](GETTING_STARTED_cn.md)中训练得到的模型进行试用,脚本如下 使用[训练/评估/推断](GETTING_STARTED_cn.md)中训练得到的模型进行试用,脚本如下
```bash ```bash
# 导出FasterRCNN模型 # 导出FasterRCNN模型, 模型中data层默认的shape为3x800x1333
python tools/export_model.py -c configs/faster_rcnn_r50_1x.yml \ python tools/export_model.py -c configs/faster_rcnn_r50_1x.yml \
--output_dir=./inference_model \ --output_dir=./inference_model \
-o weights=output/faster_rcnn_r50_1x/model_final \ -o weights=output/faster_rcnn_r50_1x/model_final \
``` ```
- 预测模型会导出到`inference_model/faster_rcnn_r50_1x`目录下,模型名和参数名分别为`__model__``__params__` 预测模型会导出到`inference_model/faster_rcnn_r50_1x`目录下,模型名和参数名分别为`__model__``__params__`
## 设置导出模型的输入大小 ## 设置导出模型的输入大小
...@@ -46,5 +46,3 @@ python tools/export_model.py -c configs/ssd/ssd_mobilenet_v1_voc.yml \ ...@@ -46,5 +46,3 @@ python tools/export_model.py -c configs/ssd/ssd_mobilenet_v1_voc.yml \
-o weights= https://paddlemodels.bj.bcebos.com/object_detection/ssd_mobilenet_v1_voc.tar \ -o weights= https://paddlemodels.bj.bcebos.com/object_detection/ssd_mobilenet_v1_voc.tar \
SSDTestFeed.image_shape=[3,300,300] SSDTestFeed.image_shape=[3,300,300]
``` ```
- 保存FPN系列模型时,需要保证上下采样维度一致,因此image_shape须设置为32的倍数
...@@ -453,7 +453,7 @@ class FasterRCNNTrainFeed(DataFeed): ...@@ -453,7 +453,7 @@ class FasterRCNNTrainFeed(DataFeed):
'image', 'im_info', 'im_id', 'gt_box', 'gt_label', 'image', 'im_info', 'im_id', 'gt_box', 'gt_label',
'is_crowd' 'is_crowd'
], ],
image_shape=[3, None, None], image_shape=[3, 800, 1333],
sample_transforms=[ sample_transforms=[
DecodeImage(to_rgb=True), DecodeImage(to_rgb=True),
RandomFlipImage(prob=0.5), RandomFlipImage(prob=0.5),
...@@ -505,7 +505,7 @@ class FasterRCNNEvalFeed(DataFeed): ...@@ -505,7 +505,7 @@ class FasterRCNNEvalFeed(DataFeed):
COCO_VAL_IMAGE_DIR).__dict__, COCO_VAL_IMAGE_DIR).__dict__,
fields=['image', 'im_info', 'im_id', 'im_shape', 'gt_box', fields=['image', 'im_info', 'im_id', 'im_shape', 'gt_box',
'gt_label', 'is_difficult'], 'gt_label', 'is_difficult'],
image_shape=[3, None, None], image_shape=[3, 800, 1333],
sample_transforms=[ sample_transforms=[
DecodeImage(to_rgb=True), DecodeImage(to_rgb=True),
NormalizeImage(mean=[0.485, 0.456, 0.406], NormalizeImage(mean=[0.485, 0.456, 0.406],
...@@ -552,7 +552,7 @@ class FasterRCNNTestFeed(DataFeed): ...@@ -552,7 +552,7 @@ class FasterRCNNTestFeed(DataFeed):
dataset=SimpleDataSet(COCO_VAL_ANNOTATION, dataset=SimpleDataSet(COCO_VAL_ANNOTATION,
COCO_VAL_IMAGE_DIR).__dict__, COCO_VAL_IMAGE_DIR).__dict__,
fields=['image', 'im_info', 'im_id', 'im_shape'], fields=['image', 'im_info', 'im_id', 'im_shape'],
image_shape=[3, None, None], image_shape=[3, 800, 1333],
sample_transforms=[ sample_transforms=[
DecodeImage(to_rgb=True), DecodeImage(to_rgb=True),
NormalizeImage(mean=[0.485, 0.456, 0.406], NormalizeImage(mean=[0.485, 0.456, 0.406],
...@@ -600,7 +600,7 @@ class MaskRCNNTrainFeed(DataFeed): ...@@ -600,7 +600,7 @@ class MaskRCNNTrainFeed(DataFeed):
'image', 'im_info', 'im_id', 'gt_box', 'gt_label', 'image', 'im_info', 'im_id', 'gt_box', 'gt_label',
'is_crowd', 'gt_mask' 'is_crowd', 'gt_mask'
], ],
image_shape=[3, None, None], image_shape=[3, 800, 1333],
sample_transforms=[ sample_transforms=[
DecodeImage(to_rgb=True), DecodeImage(to_rgb=True),
RandomFlipImage(prob=0.5, is_mask_flip=True), RandomFlipImage(prob=0.5, is_mask_flip=True),
...@@ -646,7 +646,7 @@ class MaskRCNNEvalFeed(DataFeed): ...@@ -646,7 +646,7 @@ class MaskRCNNEvalFeed(DataFeed):
dataset=CocoDataSet(COCO_VAL_ANNOTATION, dataset=CocoDataSet(COCO_VAL_ANNOTATION,
COCO_VAL_IMAGE_DIR).__dict__, COCO_VAL_IMAGE_DIR).__dict__,
fields=['image', 'im_info', 'im_id', 'im_shape'], fields=['image', 'im_info', 'im_id', 'im_shape'],
image_shape=[3, None, None], image_shape=[3, 800, 1333],
sample_transforms=[ sample_transforms=[
DecodeImage(to_rgb=True), DecodeImage(to_rgb=True),
NormalizeImage(mean=[0.485, 0.456, 0.406], NormalizeImage(mean=[0.485, 0.456, 0.406],
...@@ -698,7 +698,7 @@ class MaskRCNNTestFeed(DataFeed): ...@@ -698,7 +698,7 @@ class MaskRCNNTestFeed(DataFeed):
dataset=SimpleDataSet(COCO_VAL_ANNOTATION, dataset=SimpleDataSet(COCO_VAL_ANNOTATION,
COCO_VAL_IMAGE_DIR).__dict__, COCO_VAL_IMAGE_DIR).__dict__,
fields=['image', 'im_info', 'im_id', 'im_shape'], fields=['image', 'im_info', 'im_id', 'im_shape'],
image_shape=[3, None, None], image_shape=[3, 800, 1333],
sample_transforms=[ sample_transforms=[
DecodeImage(to_rgb=True), DecodeImage(to_rgb=True),
NormalizeImage( NormalizeImage(
......
...@@ -25,22 +25,22 @@ __all__ = ['create_feed'] ...@@ -25,22 +25,22 @@ __all__ = ['create_feed']
# yapf: disable # yapf: disable
feed_var_def = [ feed_var_def = [
{'name': 'im_info', 'shape': [None, 3], 'dtype': 'float32', 'lod_level': 0}, {'name': 'im_info', 'shape': [3], 'dtype': 'float32', 'lod_level': 0},
{'name': 'im_id', 'shape': [None, 1], 'dtype': 'int32', 'lod_level': 0}, {'name': 'im_id', 'shape': [1], 'dtype': 'int32', 'lod_level': 0},
{'name': 'gt_box', 'shape': [None, 4], 'dtype': 'float32', 'lod_level': 1}, {'name': 'gt_box', 'shape': [4], 'dtype': 'float32', 'lod_level': 1},
{'name': 'gt_label', 'shape': [None, 1], 'dtype': 'int32', 'lod_level': 1}, {'name': 'gt_label', 'shape': [1], 'dtype': 'int32', 'lod_level': 1},
{'name': 'is_crowd', 'shape': [None, 1], 'dtype': 'int32', 'lod_level': 1}, {'name': 'is_crowd', 'shape': [1], 'dtype': 'int32', 'lod_level': 1},
{'name': 'gt_mask', 'shape': [None, 2], 'dtype': 'float32', 'lod_level': 3}, {'name': 'gt_mask', 'shape': [2], 'dtype': 'float32', 'lod_level': 3},
{'name': 'is_difficult', 'shape': [None, 1], 'dtype': 'int32', 'lod_level': 1}, {'name': 'is_difficult', 'shape': [1], 'dtype': 'int32', 'lod_level': 1},
{'name': 'gt_score', 'shape': [None, 1], 'dtype': 'float32', 'lod_level': 0}, {'name': 'gt_score', 'shape': [1], 'dtype': 'float32', 'lod_level': 0},
{'name': 'im_shape', 'shape': [None, 3], 'dtype': 'float32', 'lod_level': 0}, {'name': 'im_shape', 'shape': [3], 'dtype': 'float32', 'lod_level': 0},
{'name': 'im_size', 'shape': [None, 2], 'dtype': 'int32', 'lod_level': 0}, {'name': 'im_size', 'shape': [2], 'dtype': 'int32', 'lod_level': 0},
] ]
# yapf: enable # yapf: enable
def create_feed(feed, iterable=False, sub_prog_feed=False): def create_feed(feed, iterable=False, sub_prog_feed=False):
image_shape = [None] + feed.image_shape image_shape = feed.image_shape
feed_var_map = {var['name']: var for var in feed_var_def} feed_var_map = {var['name']: var for var in feed_var_def}
feed_var_map['image'] = { feed_var_map['image'] = {
'name': 'image', 'name': 'image',
...@@ -52,10 +52,10 @@ def create_feed(feed, iterable=False, sub_prog_feed=False): ...@@ -52,10 +52,10 @@ def create_feed(feed, iterable=False, sub_prog_feed=False):
# tensor padding with 0 is used instead of LoD tensor when # tensor padding with 0 is used instead of LoD tensor when
# num_max_boxes is set # num_max_boxes is set
if getattr(feed, 'num_max_boxes', None) is not None: if getattr(feed, 'num_max_boxes', None) is not None:
feed_var_map['gt_label']['shape'] = [None, feed.num_max_boxes] feed_var_map['gt_label']['shape'] = [feed.num_max_boxes]
feed_var_map['gt_score']['shape'] = [None, feed.num_max_boxes] feed_var_map['gt_score']['shape'] = [feed.num_max_boxes]
feed_var_map['gt_box']['shape'] = [None, feed.num_max_boxes, 4] feed_var_map['gt_box']['shape'] = [feed.num_max_boxes, 4]
feed_var_map['is_difficult']['shape'] = [None, feed.num_max_boxes] feed_var_map['is_difficult']['shape'] = [feed.num_max_boxes]
feed_var_map['gt_label']['lod_level'] = 0 feed_var_map['gt_label']['lod_level'] = 0
feed_var_map['gt_score']['lod_level'] = 0 feed_var_map['gt_score']['lod_level'] = 0
feed_var_map['gt_box']['lod_level'] = 0 feed_var_map['gt_box']['lod_level'] = 0
...@@ -98,14 +98,14 @@ def create_feed(feed, iterable=False, sub_prog_feed=False): ...@@ -98,14 +98,14 @@ def create_feed(feed, iterable=False, sub_prog_feed=False):
'lod_level': 0 'lod_level': 0
} }
image_name_list.append(name) image_name_list.append(name)
feed_var_map['im_info']['shape'] = [None, feed.num_scale * 3] feed_var_map['im_info']['shape'] = [feed.num_scale * 3]
feed.fields = image_name_list + feed.fields[1:] feed.fields = image_name_list + feed.fields[1:]
if sub_prog_feed: if sub_prog_feed:
box_names = ['bbox', 'bbox_flip'] box_names = ['bbox', 'bbox_flip']
for box_name in box_names: for box_name in box_names:
sub_prog_feed = { sub_prog_feed = {
'name': box_name, 'name': box_name,
'shape': [None, 6], 'shape': [6],
'dtype': 'float32', 'dtype': 'float32',
'lod_level': 1 'lod_level': 1
} }
...@@ -113,7 +113,7 @@ def create_feed(feed, iterable=False, sub_prog_feed=False): ...@@ -113,7 +113,7 @@ def create_feed(feed, iterable=False, sub_prog_feed=False):
feed.fields = feed.fields + [box_name] feed.fields = feed.fields + [box_name]
feed_var_map[box_name] = sub_prog_feed feed_var_map[box_name] = sub_prog_feed
feed_vars = OrderedDict([(key, fluid.data( feed_vars = OrderedDict([(key, fluid.layers.data(
name=feed_var_map[key]['name'], name=feed_var_map[key]['name'],
shape=feed_var_map[key]['shape'], shape=feed_var_map[key]['shape'],
dtype=feed_var_map[key]['dtype'], dtype=feed_var_map[key]['dtype'],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册