(model, epoch_num, train_prog, train_vars, exe, data_list)
return np.array(acc_v).mean(), epoch_id
train
train
train
def train(model, epoch_num, train_prog, train_vars, exe, data_list):
    """
        train
    """
    train_py_reader, loss_train, acc_train = train_vars
    exec_strategy = fluid.ExecutionStrategy()
    exec_strategy.num_threads = 1
    build_strategy = fluid.BuildStrategy()
    build_strategy.memory_optimize = False
    build_strategy.enable_inplace = True
    train_exe = fluid.ParallelExecutor(
        main_program=train_prog,
        use_cuda=True,
        loss_name=loss_train.name,
        exec_strategy=exec_strategy,
        build_strategy=build_strategy)

    train_reader = reader.train10(FLAGS.data_path, FLAGS.batch_size, data_list)
    train_py_reader.decorate_paddle_reader(train_reader)

    train_fetch_list = [loss_train, acc_train]
    epoch_start_time = time.time()
    for epoch_id in range(epoch_num):
        train_py_reader.start()
        epoch_end_time = time.time()
        if epoch_id > 0:
            print("Epoch {}, total time {}".format(epoch_id - 1, epoch_end_time
                                                   - epoch_start_time))
        epoch_start_time = epoch_end_time
        epoch_end_time
        start_time = time.time()
        step_id = 0
        try:
            while True:
                prev_start_time = start_time
                start_time = time.time()
                loss_v, acc_v = train_exe.run(
                    fetch_list=[v.name for v in train_fetch_list])
                if np.isnan(np.array(loss_v).mean()):
                    format_str = "[%s] jobs done, step = %d, loss = nan"
                    print(format_str % (utils.stime(), step_id))
                    return np.array(acc_v).mean(), epoch_id
                print("Epoch {}, Step {}, loss {}, acc {}, time {}".format(
                        epoch_id, step_id, np.array(loss_v).mean(),
                        np.array(acc_v).mean(), start_time - prev_start_time))
                step_id += 1
                sys.stdout.flush()
        except fluid.core.EOFException:
            train_py_reader.reset()
    return np.array(acc_v).mean(), epoch_id
def train ( model , epoch_num , train_prog , train_vars , exe , data_list ) : train_py_reader , loss_train , acc_train = train_vars exec_strategy = fluid . ExecutionStrategy ( ) exec_strategy . num_threads = 1 build_strategy = fluid . BuildStrategy ( ) build_strategy . memory_optimize = False build_strategy . enable_inplace = True train_exe = fluid . ParallelExecutor ( main_program = train_prog , use_cuda = True , loss_name = loss_train . name , exec_strategy = exec_strategy , build_strategy = build_strategy ) train_reader = reader . train10 ( FLAGS . data_path , FLAGS . batch_size , data_list ) train_py_reader . decorate_paddle_reader ( train_reader ) train_fetch_list = [ loss_train , acc_train ] epoch_start_time = time . time ( ) for epoch_id in range ( epoch_num ) : train_py_reader . start ( ) epoch_end_time = time . time ( ) if epoch_id > 0 : print ( "Epoch {}, total time {}" . format ( epoch_id - 1 , epoch_end_time - epoch_start_time ) ) epoch_start_time = epoch_end_time epoch_end_time start_time = time . time ( ) step_id = 0 try : while True : prev_start_time = start_time start_time = time . time ( ) loss_v , acc_v = train_exe . run ( fetch_list = [ v . name for v in train_fetch_list ] ) if np . isnan ( np . array ( loss_v ) . mean ( ) ) : format_str = "[%s] jobs done, step = %d, loss = nan" print ( format_str % ( utils . stime ( ) , step_id ) ) return np . array ( acc_v ) . mean ( ) , epoch_id print ( "Epoch {}, Step {}, loss {}, acc {}, time {}" . format ( epoch_id , step_id , np . array ( loss_v ) . mean ( ) , np . array ( acc_v ) . mean ( ) , start_time - prev_start_time ) ) step_id += 1 sys . stdout . flush ( ) except fluid . core . EOFException : train_py_reader . reset ( ) return np . array ( acc_v ) . mean ( ) , epoch_id