未验证 提交 1137c0c0 编写于 作者: S SunGaofeng 提交者: GitHub

Revert "fix fluid.data and fluid.io.DataLoader (#3533)" (#3560)

This reverts commit 0be3697c.
上级 8be4d011
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
## 安装 ## 安装
在当前模型库运行样例代码需要PaddlePaddle Fluid v.1.6.0或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据[安装文档](http://www.paddlepaddle.org/documentation/docs/zh/1.6/beginners_guide/install/index_cn.html)中的说明来更新PaddlePaddle。 在当前模型库运行样例代码需要PaddlePaddle Fluid v.1.5.0或以上的版本。如果你的运行环境中的PaddlePaddle低于此版本,请根据[安装文档](http://www.paddlepaddle.org/documentation/docs/zh/1.5/beginners_guide/install/index_cn.html)中的说明来更新PaddlePaddle。
### 其他环境依赖 ### 其他环境依赖
......
...@@ -26,7 +26,6 @@ import models ...@@ -26,7 +26,6 @@ import models
from reader import get_reader from reader import get_reader
from metrics import get_metrics from metrics import get_metrics
from utils.utility import check_cuda from utils.utility import check_cuda
from utils.utility import check_version
logging.root.handlers = [] logging.root.handlers = []
FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s' FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s'
...@@ -84,7 +83,7 @@ def test(args): ...@@ -84,7 +83,7 @@ def test(args):
# build model # build model
test_model = models.get_model(args.model_name, test_config, mode='test') test_model = models.get_model(args.model_name, test_config, mode='test')
test_model.build_input(use_dataloader=False) test_model.build_input(use_pyreader=False)
test_model.build_model() test_model.build_model()
test_feeds = test_model.feeds() test_feeds = test_model.feeds()
test_fetch_list = test_model.fetches() test_fetch_list = test_model.fetches()
...@@ -131,7 +130,6 @@ if __name__ == "__main__": ...@@ -131,7 +130,6 @@ if __name__ == "__main__":
args = parse_args() args = parse_args()
# check whether the installed paddle is compiled with GPU # check whether the installed paddle is compiled with GPU
check_cuda(args.use_gpu) check_cuda(args.use_gpu)
check_version()
logger.info(args) logger.info(args)
test(args) test(args)
...@@ -80,7 +80,7 @@ def save_inference_model(args): ...@@ -80,7 +80,7 @@ def save_inference_model(args):
infer_config = merge_configs(config, 'infer', vars(args)) infer_config = merge_configs(config, 'infer', vars(args))
print_configs(infer_config, "Infer") print_configs(infer_config, "Infer")
infer_model = models.get_model(args.model_name, infer_config, mode='infer') infer_model = models.get_model(args.model_name, infer_config, mode='infer')
infer_model.build_input(use_dataloader=False) infer_model.build_input(use_pyreader=False)
infer_model.build_model() infer_model.build_model()
infer_feeds = infer_model.feeds() infer_feeds = infer_model.feeds()
infer_outputs = infer_model.outputs() infer_outputs = infer_model.outputs()
......
...@@ -41,21 +41,21 @@ class AttentionCluster(ModelBase): ...@@ -41,21 +41,21 @@ class AttentionCluster(ModelBase):
self.learning_rate = self.get_config_from_sec('train', self.learning_rate = self.get_config_from_sec('train',
'learning_rate', 1e-3) 'learning_rate', 1e-3)
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
self.feature_input = [] self.feature_input = []
for name, dim in zip(self.feature_names, self.feature_dims): for name, dim in zip(self.feature_names, self.feature_dims):
self.feature_input.append( self.feature_input.append(
fluid.data( fluid.layers.data(
shape=[None, self.seg_num, dim], dtype='float32', name=name)) shape=[self.seg_num, dim], dtype='float32', name=name))
if self.mode != 'infer': if self.mode != 'infer':
self.label_input = fluid.data( self.label_input = fluid.layers.data(
shape=[None, self.class_num], dtype='float32', name='label') shape=[self.class_num], dtype='float32', name='label')
else: else:
self.label_input = None self.label_input = None
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=self.feature_input + [self.label_input], feed_list=self.feature_input + [self.label_input],
capacity=8, capacity=8,
iterable=True) iterable=True)
......
...@@ -52,21 +52,21 @@ class AttentionLSTM(ModelBase): ...@@ -52,21 +52,21 @@ class AttentionLSTM(ModelBase):
self.decay_gamma = self.get_config_from_sec('train', 'decay_gamma', self.decay_gamma = self.get_config_from_sec('train', 'decay_gamma',
0.1) 0.1)
def build_input(self, use_dataloader): def build_input(self, use_pyreader):
self.feature_input = [] self.feature_input = []
for name, dim in zip(self.feature_names, self.feature_dims): for name, dim in zip(self.feature_names, self.feature_dims):
self.feature_input.append( self.feature_input.append(
fluid.data( fluid.layers.data(
shape=[None, dim], lod_level=1, dtype='float32', name=name)) shape=[dim], lod_level=1, dtype='float32', name=name))
if self.mode != 'infer': if self.mode != 'infer':
self.label_input = fluid.data( self.label_input = fluid.layers.data(
shape=[None, self.num_classes], dtype='float32', name='label') shape=[self.num_classes], dtype='float32', name='label')
else: else:
self.label_input = None self.label_input = None
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=self.feature_input + [self.label_input], feed_list=self.feature_input + [self.label_input],
capacity=8, capacity=8,
iterable=True) iterable=True)
......
...@@ -52,46 +52,47 @@ class BMN(ModelBase): ...@@ -52,46 +52,47 @@ class BMN(ModelBase):
'l2_weight_decay') 'l2_weight_decay')
self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter') self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
feat_shape = [None, self.feat_dim, self.tscale] feat_shape = [self.feat_dim, self.tscale]
gt_iou_map_shape = [None, self.dscale, self.tscale] gt_iou_map_shape = [self.dscale, self.tscale]
gt_start_shape = [None, self.tscale] gt_start_shape = [self.tscale]
gt_end_shape = [None, self.tscale] gt_end_shape = [self.tscale]
fileid_shape = [None, 1] fileid_shape = [1]
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
# set init data to None # set init data to None
py_reader = None
feat = None feat = None
gt_iou_map = None gt_iou_map = None
gt_start = None gt_start = None
gt_end = None gt_end = None
fileid = None fileid = None
feat = fluid.data(name='feat', shape=feat_shape, dtype='float32') feat = fluid.layers.data(name='feat', shape=feat_shape, dtype='float32')
feed_list = [] feed_list = []
feed_list.append(feat) feed_list.append(feat)
if (self.mode == 'train') or (self.mode == 'valid'): if (self.mode == 'train') or (self.mode == 'valid'):
gt_start = fluid.data( gt_start = fluid.layers.data(
name='gt_start', shape=gt_start_shape, dtype='float32') name='gt_start', shape=gt_start_shape, dtype='float32')
gt_end = fluid.data( gt_end = fluid.layers.data(
name='gt_end', shape=gt_end_shape, dtype='float32') name='gt_end', shape=gt_end_shape, dtype='float32')
gt_iou_map = fluid.data( gt_iou_map = fluid.layers.data(
name='gt_iou_map', shape=gt_iou_map_shape, dtype='float32') name='gt_iou_map', shape=gt_iou_map_shape, dtype='float32')
feed_list.append(gt_iou_map) feed_list.append(gt_iou_map)
feed_list.append(gt_start) feed_list.append(gt_start)
feed_list.append(gt_end) feed_list.append(gt_end)
elif self.mode == 'test': elif self.mode == 'test':
gt_start = fluid.data( gt_start = fluid.layers.data(
name='gt_start', shape=gt_start_shape, dtype='float32') name='gt_start', shape=gt_start_shape, dtype='float32')
gt_end = fluid.data( gt_end = fluid.layers.data(
name='gt_end', shape=gt_end_shape, dtype='float32') name='gt_end', shape=gt_end_shape, dtype='float32')
gt_iou_map = fluid.data( gt_iou_map = fluid.layers.data(
name='gt_iou_map', shape=gt_iou_map_shape, dtype='float32') name='gt_iou_map', shape=gt_iou_map_shape, dtype='float32')
feed_list.append(gt_iou_map) feed_list.append(gt_iou_map)
feed_list.append(gt_start) feed_list.append(gt_start)
feed_list.append(gt_end) feed_list.append(gt_end)
fileid = fluid.data( fileid = fluid.layers.data(
name='fileid', shape=fileid_shape, dtype='int64') name='fileid', shape=fileid_shape, dtype='int64')
feed_list.append(fileid) feed_list.append(fileid)
elif self.mode == 'infer': elif self.mode == 'infer':
...@@ -101,10 +102,10 @@ class BMN(ModelBase): ...@@ -101,10 +102,10 @@ class BMN(ModelBase):
raise NotImplementedError('mode {} not implemented'.format( raise NotImplementedError('mode {} not implemented'.format(
self.mode)) self.mode))
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=feed_list, capacity=8, iterable=True) feed_list=feed_list, capacity=8, iterable=True)
self.feat_input = [feat] self.feat_input = [feat]
......
...@@ -47,46 +47,47 @@ class BsnTem(ModelBase): ...@@ -47,46 +47,47 @@ class BsnTem(ModelBase):
'l2_weight_decay') 'l2_weight_decay')
self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter') self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
feat_shape = [None, self.feat_dim, self.tscale] feat_shape = [self.feat_dim, self.tscale]
gt_start_shape = [None, self.tscale] gt_start_shape = [self.tscale]
gt_end_shape = [None, self.tscale] gt_end_shape = [self.tscale]
gt_action_shape = [None, self.tscale] gt_action_shape = [self.tscale]
fileid_shape = [None, 1] fileid_shape = [1]
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
# set init data to None # set init data to None
py_reader = None
feat = None feat = None
gt_start = None gt_start = None
gt_end = None gt_end = None
gt_action = None gt_action = None
fileid = None fileid = None
feat = fluid.data(name='feat', shape=feat_shape, dtype='float32') feat = fluid.layers.data(name='feat', shape=feat_shape, dtype='float32')
feed_list = [] feed_list = []
feed_list.append(feat) feed_list.append(feat)
if (self.mode == 'train') or (self.mode == 'valid'): if (self.mode == 'train') or (self.mode == 'valid'):
gt_start = fluid.data( gt_start = fluid.layers.data(
name='gt_start', shape=gt_start_shape, dtype='float32') name='gt_start', shape=gt_start_shape, dtype='float32')
gt_end = fluid.data( gt_end = fluid.layers.data(
name='gt_end', shape=gt_end_shape, dtype='float32') name='gt_end', shape=gt_end_shape, dtype='float32')
gt_action = fluid.data( gt_action = fluid.layers.data(
name='gt_action', shape=gt_action_shape, dtype='float32') name='gt_action', shape=gt_action_shape, dtype='float32')
feed_list.append(gt_start) feed_list.append(gt_start)
feed_list.append(gt_end) feed_list.append(gt_end)
feed_list.append(gt_action) feed_list.append(gt_action)
elif self.mode == 'test': elif self.mode == 'test':
gt_start = fluid.data( gt_start = fluid.layers.data(
name='gt_start', shape=gt_start_shape, dtype='float32') name='gt_start', shape=gt_start_shape, dtype='float32')
gt_end = fluid.data( gt_end = fluid.layers.data(
name='gt_end', shape=gt_end_shape, dtype='float32') name='gt_end', shape=gt_end_shape, dtype='float32')
gt_action = fluid.data( gt_action = fluid.layers.data(
name='gt_action', shape=gt_action_shape, dtype='float32') name='gt_action', shape=gt_action_shape, dtype='float32')
feed_list.append(gt_start) feed_list.append(gt_start)
feed_list.append(gt_end) feed_list.append(gt_end)
feed_list.append(gt_action) feed_list.append(gt_action)
fileid = fluid.data( fileid = fluid.layers.data(
name='fileid', shape=fileid_shape, dtype='int64') name='fileid', shape=fileid_shape, dtype='int64')
feed_list.append(fileid) feed_list.append(fileid)
elif self.mode == 'infer': elif self.mode == 'infer':
...@@ -96,10 +97,10 @@ class BsnTem(ModelBase): ...@@ -96,10 +97,10 @@ class BsnTem(ModelBase):
raise NotImplementedError('mode {} not implemented'.format( raise NotImplementedError('mode {} not implemented'.format(
self.mode)) self.mode))
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=feed_list, capacity=8, iterable=True) feed_list=feed_list, capacity=8, iterable=True)
self.feat_input = [feat] self.feat_input = [feat]
...@@ -211,49 +212,50 @@ class BsnPem(ModelBase): ...@@ -211,49 +212,50 @@ class BsnPem(ModelBase):
'l2_weight_decay') 'l2_weight_decay')
self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter') self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
feat_shape = [None, self.top_K, self.feat_dim] feat_shape = [self.top_K, self.feat_dim]
gt_iou_shape = [None. self.top_K, 1] gt_iou_shape = [self.top_K, 1]
props_info_shape = [None, self.top_K, 4] props_info_shape = [self.top_K, 4]
fileid_shape = [None, 1] fileid_shape = [1]
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
# set init data to None # set init data to None
py_reader = None
feat = None feat = None
gt_iou = None gt_iou = None
props_info = None props_info = None
fileid = None fileid = None
feat = fluid.data(name='feat', shape=feat_shape, dtype='float32') feat = fluid.layers.data(name='feat', shape=feat_shape, dtype='float32')
feed_list = [] feed_list = []
feed_list.append(feat) feed_list.append(feat)
if (self.mode == 'train') or (self.mode == 'valid'): if (self.mode == 'train') or (self.mode == 'valid'):
gt_iou = fluid.data( gt_iou = fluid.layers.data(
name='gt_iou', shape=gt_iou_shape, dtype='float32') name='gt_iou', shape=gt_iou_shape, dtype='float32')
feed_list.append(gt_iou) feed_list.append(gt_iou)
elif self.mode == 'test': elif self.mode == 'test':
gt_iou = fluid.data( gt_iou = fluid.layers.data(
name='gt_iou', shape=gt_iou_shape, dtype='float32') name='gt_iou', shape=gt_iou_shape, dtype='float32')
props_info = fluid.data( props_info = fluid.layers.data(
name='props_info', shape=props_info_shape, dtype='float32') name='props_info', shape=props_info_shape, dtype='float32')
feed_list.append(gt_iou) feed_list.append(gt_iou)
feed_list.append(props_info) feed_list.append(props_info)
fileid = fluid.data( fileid = fluid.layers.data(
name='fileid', shape=fileid_shape, dtype='int64') name='fileid', shape=fileid_shape, dtype='int64')
feed_list.append(fileid) feed_list.append(fileid)
elif self.mode == 'infer': elif self.mode == 'infer':
props_info = fluid.data( props_info = fluid.layers.data(
name='props_info', shape=props_info_shape, dtype='float32') name='props_info', shape=props_info_shape, dtype='float32')
feed_list.append(props_info) feed_list.append(props_info)
else: else:
raise NotImplementedError('mode {} not implemented'.format( raise NotImplementedError('mode {} not implemented'.format(
self.mode)) self.mode))
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=feed_list, capacity=4, iterable=True) feed_list=feed_list, capacity=4, iterable=True)
self.feat_input = [feat] self.feat_input = [feat]
......
...@@ -51,36 +51,37 @@ class CTCN(ModelBase): ...@@ -51,36 +51,37 @@ class CTCN(ModelBase):
self.momentum = self.get_config_from_sec('train', 'momentum') self.momentum = self.get_config_from_sec('train', 'momentum')
self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter') self.lr_decay_iter = self.get_config_from_sec('train', 'lr_decay_iter')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
image_shape = [None, 1, self.img_size, self.concept_size] image_shape = [1, self.img_size, self.concept_size]
loc_shape = [None, self.total_num_anchors, 2] loc_shape = [self.total_num_anchors, 2]
cls_shape = [None, self.total_num_anchors] cls_shape = [self.total_num_anchors]
fileid_shape = [None, 1] fileid_shape = [1]
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
# set init data to None # set init data to None
py_reader = None
image = None image = None
loc_targets = None loc_targets = None
cls_targets = None cls_targets = None
fileid = None fileid = None
image = fluid.data( image = fluid.layers.data(
name='image', shape=image_shape, dtype='float32') name='image', shape=image_shape, dtype='float32')
feed_list = [] feed_list = []
feed_list.append(image) feed_list.append(image)
if (self.mode == 'train') or (self.mode == 'valid'): if (self.mode == 'train') or (self.mode == 'valid'):
loc_targets = fluid.data( loc_targets = fluid.layers.data(
name='loc_targets', shape=loc_shape, dtype='float32') name='loc_targets', shape=loc_shape, dtype='float32')
cls_targets = fluid.data( cls_targets = fluid.layers.data(
name='cls_targets', shape=cls_shape, dtype='int64') name='cls_targets', shape=cls_shape, dtype='int64')
feed_list.append(loc_targets) feed_list.append(loc_targets)
feed_list.append(cls_targets) feed_list.append(cls_targets)
elif self.mode == 'test': elif self.mode == 'test':
loc_targets = fluid.data( loc_targets = fluid.layers.data(
name='loc_targets', shape=loc_shape, dtype='float32') name='loc_targets', shape=loc_shape, dtype='float32')
cls_targets = fluid.data( cls_targets = fluid.layers.data(
name='cls_targets', shape=cls_shape, dtype='int64') name='cls_targets', shape=cls_shape, dtype='int64')
fileid = fluid.data( fileid = fluid.layers.data(
name='fileid', shape=fileid_shape, dtype='int64') name='fileid', shape=fileid_shape, dtype='int64')
feed_list.append(loc_targets) feed_list.append(loc_targets)
feed_list.append(cls_targets) feed_list.append(cls_targets)
...@@ -92,10 +93,10 @@ class CTCN(ModelBase): ...@@ -92,10 +93,10 @@ class CTCN(ModelBase):
raise NotImplementedError('mode {} not implemented'.format( raise NotImplementedError('mode {} not implemented'.format(
self.mode)) self.mode))
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=feed_list, capacity=4, iterable=True) feed_list=feed_list, capacity=4, iterable=True)
self.feature_input = [image] self.feature_input = [image]
......
...@@ -65,13 +65,13 @@ class ModelBase(object): ...@@ -65,13 +65,13 @@ class ModelBase(object):
self.is_training = (mode == 'train') self.is_training = (mode == 'train')
self.mode = mode self.mode = mode
self.cfg = cfg self.cfg = cfg
self.dataloader = None self.py_reader = None
def build_model(self): def build_model(self):
"build model struct" "build model struct"
raise NotImplementError(self, self.build_model) raise NotImplementError(self, self.build_model)
def build_input(self, use_dataloader): def build_input(self, use_pyreader):
"build input Variable" "build input Variable"
raise NotImplementError(self, self.build_input) raise NotImplementError(self, self.build_input)
...@@ -114,8 +114,8 @@ class ModelBase(object): ...@@ -114,8 +114,8 @@ class ModelBase(object):
wget.download(url, path) wget.download(url, path)
return path return path
def dataloader(self): def pyreader(self):
return self.dataloader return self.py_reader
def epoch_num(self): def epoch_num(self):
"get train epoch num" "get train epoch num"
......
...@@ -61,17 +61,17 @@ class NEXTVLAD(ModelBase): ...@@ -61,17 +61,17 @@ class NEXTVLAD(ModelBase):
# other params # other params
self.batch_size = self.get_config_from_sec(self.mode, 'batch_size') self.batch_size = self.get_config_from_sec(self.mode, 'batch_size')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
rgb_shape = [None, self.video_feature_size] rgb_shape = [self.video_feature_size]
audio_shape = [None, self.audio_feature_size] audio_shape = [self.audio_feature_size]
label_shape = [None, self.num_classes] label_shape = [self.num_classes]
rgb = fluid.data( rgb = fluid.layers.data(
name='train_rgb' if self.is_training else 'test_rgb', name='train_rgb' if self.is_training else 'test_rgb',
shape=rgb_shape, shape=rgb_shape,
dtype='uint8', dtype='uint8',
lod_level=1) lod_level=1)
audio = fluid.data( audio = fluid.layers.data(
name='train_audio' if self.is_training else 'test_audio', name='train_audio' if self.is_training else 'test_audio',
shape=audio_shape, shape=audio_shape,
dtype='uint8', dtype='uint8',
...@@ -79,15 +79,15 @@ class NEXTVLAD(ModelBase): ...@@ -79,15 +79,15 @@ class NEXTVLAD(ModelBase):
if self.mode == 'infer': if self.mode == 'infer':
label = None label = None
else: else:
label = fluid.data( label = fluid.layers.data(
name='train_label' if self.is_training else 'test_label', name='train_label' if self.is_training else 'test_label',
shape=label_shape, shape=label_shape,
dtype='float32') dtype='float32')
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=[rgb, audio, label], capacity=8, iterable=True) feed_list=[rgb, audio, label], capacity=8, iterable=True)
self.feature_input = [rgb, audio] self.feature_input = [rgb, audio]
self.label_input = label self.label_input = label
......
...@@ -39,26 +39,26 @@ class NonLocal(ModelBase): ...@@ -39,26 +39,26 @@ class NonLocal(ModelBase):
# crop size # crop size
self.crop_size = self.get_config_from_sec(self.mode, 'crop_size') self.crop_size = self.get_config_from_sec(self.mode, 'crop_size')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
input_shape = [None, 3, self.video_length, self.crop_size, self.crop_size] input_shape = [3, self.video_length, self.crop_size, self.crop_size]
label_shape = [None, 1] label_shape = [1]
data = fluid.data( data = fluid.layers.data(
name='train_data' if self.is_training else 'test_data', name='train_data' if self.is_training else 'test_data',
shape=input_shape, shape=input_shape,
dtype='float32') dtype='float32')
if self.mode != 'infer': if self.mode != 'infer':
label = fluid.data( label = fluid.layers.data(
name='train_label' if self.is_training else 'test_label', name='train_label' if self.is_training else 'test_label',
shape=label_shape, shape=label_shape,
dtype='int64') dtype='int64')
else: else:
label = None label = None
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( self.py_reader = fluid.io.PyReader(
feed_list=[data, label], capacity=4, iterable=True) feed_list=[data, label], capacity=4, iterable=True)
self.feature_input = [data] self.feature_input = [data]
......
...@@ -51,24 +51,25 @@ class STNET(ModelBase): ...@@ -51,24 +51,25 @@ class STNET(ModelBase):
self.target_size = self.get_config_from_sec(self.mode, 'target_size') self.target_size = self.get_config_from_sec(self.mode, 'target_size')
self.batch_size = self.get_config_from_sec(self.mode, 'batch_size') self.batch_size = self.get_config_from_sec(self.mode, 'batch_size')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
image_shape = [3, self.target_size, self.target_size] image_shape = [3, self.target_size, self.target_size]
image_shape[0] = image_shape[0] * self.seglen image_shape[0] = image_shape[0] * self.seglen
image_shape = [None, self.seg_num] + image_shape image_shape = [self.seg_num] + image_shape
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
image = fluid.data( image = fluid.layers.data(
name='image', shape=image_shape, dtype='float32') name='image', shape=image_shape, dtype='float32')
if self.mode != 'infer': if self.mode != 'infer':
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
else: else:
label = None label = None
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( py_reader = fluid.io.PyReader(
feed_list=[image, label], capacity=4, iterable=True) feed_list=[image, label], capacity=4, iterable=True)
self.py_reader = py_reader
self.feature_input = [image] self.feature_input = [image]
self.label_input = label self.label_input = label
...@@ -166,4 +167,3 @@ class STNET(ModelBase): ...@@ -166,4 +167,3 @@ class STNET(ModelBase):
param_numpy = np.mean(param_numpy, axis=1, keepdims=True) / self.seglen param_numpy = np.mean(param_numpy, axis=1, keepdims=True) / self.seglen
param_numpy = np.repeat(param_numpy, 3 * self.seglen, axis=1) param_numpy = np.repeat(param_numpy, 3 * self.seglen, axis=1)
param_tensor.set(param_numpy.astype(np.float32), place) param_tensor.set(param_numpy.astype(np.float32), place)
...@@ -51,24 +51,25 @@ class TSM(ModelBase): ...@@ -51,24 +51,25 @@ class TSM(ModelBase):
self.target_size = self.get_config_from_sec(self.mode, 'target_size') self.target_size = self.get_config_from_sec(self.mode, 'target_size')
self.batch_size = self.get_config_from_sec(self.mode, 'batch_size') self.batch_size = self.get_config_from_sec(self.mode, 'batch_size')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
image_shape = [3, self.target_size, self.target_size] image_shape = [3, self.target_size, self.target_size]
image_shape[0] = image_shape[0] * self.seglen image_shape[0] = image_shape[0] * self.seglen
image_shape = [None, self.seg_num] + image_shape image_shape = [self.seg_num] + image_shape
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
image = fluid.data( image = fluid.layers.data(
name='image', shape=image_shape, dtype='float32') name='image', shape=image_shape, dtype='float32')
if self.mode != 'infer': if self.mode != 'infer':
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
else: else:
label = None label = None
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( py_reader = fluid.io.PyReader(
feed_list=[image, label], capacity=4, iterable=True) feed_list=[image, label], capacity=4, iterable=True)
self.py_reader = py_reader
self.feature_input = [image] self.feature_input = [image]
self.label_input = label self.label_input = label
......
...@@ -52,24 +52,25 @@ class TSN(ModelBase): ...@@ -52,24 +52,25 @@ class TSN(ModelBase):
self.target_size = self.get_config_from_sec(self.mode, 'target_size') self.target_size = self.get_config_from_sec(self.mode, 'target_size')
self.batch_size = self.get_config_from_sec(self.mode, 'batch_size') self.batch_size = self.get_config_from_sec(self.mode, 'batch_size')
def build_input(self, use_dataloader=True): def build_input(self, use_pyreader=True):
image_shape = [3, self.target_size, self.target_size] image_shape = [3, self.target_size, self.target_size]
image_shape[0] = image_shape[0] * self.seglen image_shape[0] = image_shape[0] * self.seglen
image_shape = [None, self.seg_num] + image_shape image_shape = [self.seg_num] + image_shape
self.use_dataloader = use_dataloader self.use_pyreader = use_pyreader
image = fluid.data( image = fluid.layers.data(
name='image', shape=image_shape, dtype='float32') name='image', shape=image_shape, dtype='float32')
if self.mode != 'infer': if self.mode != 'infer':
label = fluid.data(name='label', shape=[None, 1], dtype='int64') label = fluid.layers.data(name='label', shape=[1], dtype='int64')
else: else:
label = None label = None
if use_dataloader: if use_pyreader:
assert self.mode != 'infer', \ assert self.mode != 'infer', \
'dataloader is not recommendated when infer, please set use_dataloader to be false.' 'pyreader is not recommendated when infer, please set use_pyreader to be false.'
self.dataloader = fluid.io.DataLoader.from_generator( py_reader = fluid.io.PyReader(
feed_list=[image, label], capacity=4, iterable=True) feed_list=[image, label], capacity=4, iterable=True)
self.py_reader = py_reader
self.feature_input = [image] self.feature_input = [image]
self.label_input = label self.label_input = label
......
...@@ -30,7 +30,6 @@ import models ...@@ -30,7 +30,6 @@ import models
from reader import get_reader from reader import get_reader
from metrics import get_metrics from metrics import get_metrics
from utils.utility import check_cuda from utils.utility import check_cuda
from utils.utility import check_version
logging.root.handlers = [] logging.root.handlers = []
FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s' FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s'
...@@ -101,7 +100,7 @@ def infer(args): ...@@ -101,7 +100,7 @@ def infer(args):
infer_config = merge_configs(config, 'infer', vars(args)) infer_config = merge_configs(config, 'infer', vars(args))
print_configs(infer_config, "Infer") print_configs(infer_config, "Infer")
infer_model = models.get_model(args.model_name, infer_config, mode='infer') infer_model = models.get_model(args.model_name, infer_config, mode='infer')
infer_model.build_input(use_dataloader=False) infer_model.build_input(use_pyreader=False)
infer_model.build_model() infer_model.build_model()
infer_feeds = infer_model.feeds() infer_feeds = infer_model.feeds()
infer_outputs = infer_model.outputs() infer_outputs = infer_model.outputs()
...@@ -166,7 +165,6 @@ if __name__ == "__main__": ...@@ -166,7 +165,6 @@ if __name__ == "__main__":
args = parse_args() args = parse_args()
# check whether the installed paddle is compiled with GPU # check whether the installed paddle is compiled with GPU
check_cuda(args.use_gpu) check_cuda(args.use_gpu)
check_version()
logger.info(args) logger.info(args)
infer(args) infer(args)
...@@ -21,13 +21,12 @@ import logging ...@@ -21,13 +21,12 @@ import logging
import numpy as np import numpy as np
import paddle.fluid as fluid import paddle.fluid as fluid
from utils.train_utils import train_with_dataloader from utils.train_utils import train_with_pyreader
import models import models
from utils.config_utils import * from utils.config_utils import *
from reader import get_reader from reader import get_reader
from metrics import get_metrics from metrics import get_metrics
from utils.utility import check_cuda from utils.utility import check_cuda
from utils.utility import check_version
logging.root.handlers = [] logging.root.handlers = []
FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s' FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s'
...@@ -125,7 +124,7 @@ def train(args): ...@@ -125,7 +124,7 @@ def train(args):
train_prog.random_seed = 1000 train_prog.random_seed = 1000
with fluid.program_guard(train_prog, startup): with fluid.program_guard(train_prog, startup):
with fluid.unique_name.guard(): with fluid.unique_name.guard():
train_model.build_input(use_dataloader=True) train_model.build_input(use_pyreader=True)
train_model.build_model() train_model.build_model()
# for the input, has the form [data1, data2,..., label], so train_feeds[-1] is label # for the input, has the form [data1, data2,..., label], so train_feeds[-1] is label
train_feeds = train_model.feeds() train_feeds = train_model.feeds()
...@@ -135,16 +134,16 @@ def train(args): ...@@ -135,16 +134,16 @@ def train(args):
item.persistable = True item.persistable = True
optimizer = train_model.optimizer() optimizer = train_model.optimizer()
optimizer.minimize(train_loss) optimizer.minimize(train_loss)
train_dataloader = train_model.dataloader() train_pyreader = train_model.pyreader()
valid_prog = fluid.Program() valid_prog = fluid.Program()
with fluid.program_guard(valid_prog, startup): with fluid.program_guard(valid_prog, startup):
with fluid.unique_name.guard(): with fluid.unique_name.guard():
valid_model.build_input(use_dataloader=True) valid_model.build_input(use_pyreader=True)
valid_model.build_model() valid_model.build_model()
valid_feeds = valid_model.feeds() valid_feeds = valid_model.feeds()
valid_fetch_list = valid_model.fetches() valid_fetch_list = valid_model.fetches()
valid_dataloader = valid_model.dataloader() valid_pyreader = valid_model.pyreader()
for item in valid_fetch_list: for item in valid_fetch_list:
item.persistable = True item.persistable = True
...@@ -191,8 +190,8 @@ def train(args): ...@@ -191,8 +190,8 @@ def train(args):
gpus = gpus.split(",") gpus = gpus.split(",")
num_gpus = len(gpus) num_gpus = len(gpus)
assert num_gpus == train_config.TRAIN.num_gpus, \ assert num_gpus == train_config.TRAIN.num_gpus, \
"num_gpus({}) set by CUDA_VISIBLE_DEVICES " \ "num_gpus({}) set by CUDA_VISIBLE_DEVICES" \
"shoud be the same as that " \ "shoud be the same as that" \
"set in {}({})".format( "set in {}({})".format(
num_gpus, args.config, train_config.TRAIN.num_gpus) num_gpus, args.config, train_config.TRAIN.num_gpus)
bs_denominator = train_config.TRAIN.num_gpus bs_denominator = train_config.TRAIN.num_gpus
...@@ -211,16 +210,16 @@ def train(args): ...@@ -211,16 +210,16 @@ def train(args):
epochs = args.epoch or train_model.epoch_num() epochs = args.epoch or train_model.epoch_num()
exe_places = fluid.cuda_places() if args.use_gpu else fluid.cpu_places() exe_places = fluid.cuda_places() if args.use_gpu else fluid.cpu_places()
train_dataloader.set_sample_list_generator( train_pyreader.decorate_sample_list_generator(
train_reader, places=exe_places) train_reader, places=exe_places)
valid_dataloader.set_sample_list_generator( valid_pyreader.decorate_sample_list_generator(
valid_reader, places=exe_places) valid_reader, places=exe_places)
train_with_dataloader( train_with_pyreader(
exe, exe,
train_prog, train_prog,
compiled_train_prog, #train_exe, compiled_train_prog, #train_exe,
train_dataloader, train_pyreader,
train_fetch_list, train_fetch_list,
train_metrics, train_metrics,
epochs=epochs, epochs=epochs,
...@@ -230,7 +229,7 @@ def train(args): ...@@ -230,7 +229,7 @@ def train(args):
save_model_name=args.model_name, save_model_name=args.model_name,
fix_random_seed=args.fix_random_seed, fix_random_seed=args.fix_random_seed,
compiled_test_prog=compiled_valid_prog, #test_exe=valid_exe, compiled_test_prog=compiled_valid_prog, #test_exe=valid_exe,
test_dataloader=valid_dataloader, test_pyreader=valid_pyreader,
test_fetch_list=valid_fetch_list, test_fetch_list=valid_fetch_list,
test_metrics=valid_metrics) test_metrics=valid_metrics)
...@@ -239,7 +238,6 @@ if __name__ == "__main__": ...@@ -239,7 +238,6 @@ if __name__ == "__main__":
args = parse_args() args = parse_args()
# check whether the installed paddle is compiled with GPU # check whether the installed paddle is compiled with GPU
check_cuda(args.use_gpu) check_cuda(args.use_gpu)
check_version()
logger.info(args) logger.info(args)
if not os.path.exists(args.save_dir): if not os.path.exists(args.save_dir):
......
...@@ -47,19 +47,19 @@ def log_lr_and_step(): ...@@ -47,19 +47,19 @@ def log_lr_and_step():
logger.warn("Unable to get learning_rate and LR_DECAY_COUNTER.") logger.warn("Unable to get learning_rate and LR_DECAY_COUNTER.")
def test_with_dataloader(exe, def test_with_pyreader(exe,
compiled_test_prog, compiled_test_prog,
test_dataloader, test_pyreader,
test_fetch_list, test_fetch_list,
test_metrics, test_metrics,
log_interval=0, log_interval=0,
save_model_name=''): save_model_name=''):
if not test_dataloader: if not test_pyreader:
logger.error("[TEST] get dataloader failed.") logger.error("[TEST] get pyreader failed.")
test_metrics.reset() test_metrics.reset()
test_iter = 0 test_iter = 0
for data in test_dataloader(): for data in test_pyreader():
test_outs = exe.run(compiled_test_prog, test_outs = exe.run(compiled_test_prog,
fetch_list=test_fetch_list, fetch_list=test_fetch_list,
feed=data) feed=data)
...@@ -71,14 +71,14 @@ def test_with_dataloader(exe, ...@@ -71,14 +71,14 @@ def test_with_dataloader(exe,
test_metrics.finalize_and_log_out("[TEST] Finish") test_metrics.finalize_and_log_out("[TEST] Finish")
def train_with_dataloader(exe, train_prog, compiled_train_prog, train_dataloader, \ def train_with_pyreader(exe, train_prog, compiled_train_prog, train_pyreader, \
train_fetch_list, train_metrics, epochs = 10, \ train_fetch_list, train_metrics, epochs = 10, \
log_interval = 0, valid_interval = 0, save_dir = './', \ log_interval = 0, valid_interval = 0, save_dir = './', \
save_model_name = 'model', fix_random_seed = False, \ save_model_name = 'model', fix_random_seed = False, \
compiled_test_prog = None, test_dataloader = None, \ compiled_test_prog = None, test_pyreader = None, \
test_fetch_list = None, test_metrics = None): test_fetch_list = None, test_metrics = None):
if not train_dataloader: if not train_pyreader:
logger.error("[TRAIN] get dataloader failed.") logger.error("[TRAIN] get pyreader failed.")
epoch_periods = [] epoch_periods = []
train_loss = 0 train_loss = 0
for epoch in range(epochs): for epoch in range(epochs):
...@@ -87,7 +87,7 @@ def train_with_dataloader(exe, train_prog, compiled_train_prog, train_dataloader ...@@ -87,7 +87,7 @@ def train_with_dataloader(exe, train_prog, compiled_train_prog, train_dataloader
train_iter = 0 train_iter = 0
epoch_periods = [] epoch_periods = []
for data in train_dataloader(): for data in train_pyreader():
cur_time = time.time() cur_time = time.time()
train_outs = exe.run(compiled_train_prog, train_outs = exe.run(compiled_train_prog,
fetch_list=train_fetch_list, fetch_list=train_fetch_list,
...@@ -122,7 +122,7 @@ def train_with_dataloader(exe, train_prog, compiled_train_prog, train_dataloader ...@@ -122,7 +122,7 @@ def train_with_dataloader(exe, train_prog, compiled_train_prog, train_dataloader
save_type='.pdparams') save_type='.pdparams')
if compiled_test_prog and valid_interval > 0 and ( if compiled_test_prog and valid_interval > 0 and (
epoch + 1) % valid_interval == 0: epoch + 1) % valid_interval == 0:
test_with_dataloader(exe, compiled_test_prog, test_dataloader, test_with_pyreader(exe, compiled_test_prog, test_pyreader,
test_fetch_list, test_metrics, log_interval, test_fetch_list, test_metrics, log_interval,
save_model_name) save_model_name)
......
...@@ -14,13 +14,11 @@ ...@@ -14,13 +14,11 @@
import os import os
import signal import signal
import logging
import paddle import paddle
import paddle.fluid as fluid import paddle.fluid as fluid
__all__ = ['AttrDict'] __all__ = ['AttrDict']
logger = logging.getLogger(__name__)
def _term(sig_num, addition): def _term(sig_num, addition):
print('current pid is %s, group id is %s' % (os.getpid(), os.getpgrp())) print('current pid is %s, group id is %s' % (os.getpid(), os.getpgrp()))
...@@ -51,18 +49,3 @@ def check_cuda(use_cuda, err = \ ...@@ -51,18 +49,3 @@ def check_cuda(use_cuda, err = \
sys.exit(1) sys.exit(1)
except Exception as e: except Exception as e:
pass pass
def check_version():
"""
Log error and exit when the installed version of paddlepaddle is
not satisfied.
"""
err = "PaddlePaddle version 1.6 or higher is required, " \
"or a suitable develop version is satisfied as well. \n" \
"Please make sure the version is good with your code." \
try:
fluid.require_version('1.6.0')
except Exception as e:
logger.error(err)
sys.exit(1)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册