diff --git a/demo/mnist/api_train_v2.py b/demo/mnist/api_train_v2.py index d5eeb05318830050b27da9931d367880eb1c607e..4d95780f06cd79c7a8999507ac0276edb3c8dd03 100644 --- a/demo/mnist/api_train_v2.py +++ b/demo/mnist/api_train_v2.py @@ -37,7 +37,7 @@ def main(): trainer = paddle.trainer.SGD(update_equation=adam_optimizer) trainer.train( - train_reader=paddle.reader.batched( + reader=paddle.reader.batched( paddle.reader.shuffle(paddle.dataset.mnist.train_creator(), buf_size=8192), batch_size=32), topology=cost, diff --git a/python/paddle/v2/trainer.py b/python/paddle/v2/trainer.py index 9b45ee69f39f3fc1e75683f31cb336d82554698c..cbeef0306b739c0b6b3b6d98f494e61270e9f8f2 100644 --- a/python/paddle/v2/trainer.py +++ b/python/paddle/v2/trainer.py @@ -28,19 +28,13 @@ class ITrainer(object): The interface of Trainer. The only exposed method is `train`. """ - def train(self, - train_reader_creator, - topology, - parameters, - test_data_reader=None, - event_handler=None): + def train(self, reader, topology, parameters, event_handler=None): """ train method. - :param train_reader_creator: + :param reader: :param topology: :param parameters: - :param test_data_reader: :param event_handler: :return: """ @@ -62,7 +56,7 @@ class SGD(ITrainer): self.__optimizer__ = update_equation def train(self, - train_reader, + reader, topology, parameters, num_passes=1, @@ -72,7 +66,7 @@ class SGD(ITrainer): """ Training method. Will train num_passes of input data. - :param train_reader: + :param reader: :param topology: Network Topology, use one or more Layers to represent it. :param parameters: The parameter pools. :param num_passes: The total train passes. @@ -104,7 +98,7 @@ class SGD(ITrainer): for pass_id in xrange(num_passes): updater.startPass() - for batch_id, data_batch in enumerate(train_reader()): + for batch_id, data_batch in enumerate(reader()): pass_type = updater.startBatch(len(data_batch)) gm.forwardBackward(feeder(data_batch), out_args, pass_type) for each_param in gm.getParameters(): @@ -122,13 +116,11 @@ class SGD(ITrainer): gm.finish() -def __check_train_args__(train_reader, topology, parameters, event_handler, - **kwargs): +def __check_train_args__(reader, topology, parameters, event_handler, **kwargs): """ Check train function's argument types """ - if not callable(train_reader) or not isinstance(train_reader(), - collections.Iterator): + if not callable(reader) or not isinstance(reader(), collections.Iterator): raise TypeError('train_data_reader should be a function, ' 'which can return a iterator')