未验证 提交 eb7eb9cd 编写于 作者: L littletomatodonkey 提交者: GitHub

remove unused code in ml (#4781)

上级 a7fb45f6
...@@ -109,14 +109,13 @@ def build_program(is_train, main_prog, startup_prog, args): ...@@ -109,14 +109,13 @@ def build_program(is_train, main_prog, startup_prog, args):
with fluid.program_guard(main_prog, startup_prog): with fluid.program_guard(main_prog, startup_prog):
queue_capacity = 64 queue_capacity = 64
image = fluid.data( image = fluid.data(
name='image', shape=[None] + image_shape, dtype='float32') name='image', shape=[None] + image_shape, dtype='float32')
label = fluid.data( label = fluid.data(name='label', shape=[None, 1], dtype='int64')
name='label', shape=[None, 1], dtype='int64')
loader = fluid.io.DataLoader.from_generator( loader = fluid.io.DataLoader.from_generator(
feed_list=[image, label], feed_list=[image, label],
capacity=queue_capacity, capacity=queue_capacity,
use_double_buffer=True, use_double_buffer=True,
iterable=True) iterable=True)
with fluid.unique_name.guard(): with fluid.unique_name.guard():
avg_cost, acc_top1, acc_top5, out = net_config(image, label, model, avg_cost, acc_top1, acc_top5, out = net_config(image, label, model,
...@@ -187,17 +186,12 @@ def train_async(args): ...@@ -187,17 +186,12 @@ def train_async(args):
exe.run(startup_prog) exe.run(startup_prog)
logging.debug('after run startup program')
if checkpoint is not None: if checkpoint is not None:
fluid.load(program=train_prog, model_path=checkpoint, executor=exe) fluid.load(program=train_prog, model_path=checkpoint, executor=exe)
if pretrained_model: if pretrained_model:
fluid.load(
def if_exist(var): program=train_prog, model_path=pretrained_model, executor=exe)
return os.path.exists(os.path.join(pretrained_model, var.name))
fluid.load(program=train_prog, model_path=pretrained_model, executor=exe)
if args.use_gpu: if args.use_gpu:
devicenum = get_gpu_num() devicenum = get_gpu_num()
...@@ -208,7 +202,7 @@ def train_async(args): ...@@ -208,7 +202,7 @@ def train_async(args):
test_batch_size = args.test_batch_size test_batch_size = args.test_batch_size
train_loader.set_sample_generator( train_loader.set_sample_generator(
reader.train(args), reader.train(args),
batch_size=train_batch_size, batch_size=train_batch_size,
drop_last=True, drop_last=True,
places=places) places=places)
...@@ -230,9 +224,8 @@ def train_async(args): ...@@ -230,9 +224,8 @@ def train_async(args):
while iter_no <= args.total_iter_num: while iter_no <= args.total_iter_num:
for train_batch in train_loader(): for train_batch in train_loader():
t1 = time.time() t1 = time.time()
lr, loss, acc1, acc5 = train_exe.run( lr, loss, acc1, acc5 = train_exe.run(feed=train_batch,
feed=train_batch, fetch_list=train_fetch_list)
fetch_list=train_fetch_list)
t2 = time.time() t2 = time.time()
period = t2 - t1 period = t2 - t1
lr = np.mean(np.array(lr)) lr = np.mean(np.array(lr))
...@@ -260,8 +253,8 @@ def train_async(args): ...@@ -260,8 +253,8 @@ def train_async(args):
for batch_id, test_batch in enumerate(test_loader()): for batch_id, test_batch in enumerate(test_loader()):
t1 = time.time() t1 = time.time()
[feas] = exe.run(test_prog, [feas] = exe.run(test_prog,
feed=test_batch, feed=test_batch,
fetch_list=test_fetch_list) fetch_list=test_fetch_list)
label = np.asarray(test_batch[0]['label']) label = np.asarray(test_batch[0]['label'])
label = np.squeeze(label) label = np.squeeze(label)
......
...@@ -116,14 +116,13 @@ def build_program(is_train, main_prog, startup_prog, args): ...@@ -116,14 +116,13 @@ def build_program(is_train, main_prog, startup_prog, args):
with fluid.program_guard(main_prog, startup_prog): with fluid.program_guard(main_prog, startup_prog):
queue_capacity = 64 queue_capacity = 64
image = fluid.data( image = fluid.data(
name='image', shape=[None] + image_shape, dtype='float32') name='image', shape=[None] + image_shape, dtype='float32')
label = fluid.data( label = fluid.data(name='label', shape=[None, 1], dtype='int64')
name='label', shape=[None, 1], dtype='int64')
loader = fluid.io.DataLoader.from_generator( loader = fluid.io.DataLoader.from_generator(
feed_list=[image, label], feed_list=[image, label],
capacity=queue_capacity, capacity=queue_capacity,
use_double_buffer=True, use_double_buffer=True,
iterable=True) iterable=True)
with fluid.unique_name.guard(): with fluid.unique_name.guard():
avg_cost, out = net_config(image, label, model, args, is_train) avg_cost, out = net_config(image, label, model, args, is_train)
...@@ -185,18 +184,12 @@ def train_async(args): ...@@ -185,18 +184,12 @@ def train_async(args):
exe.run(startup_prog) exe.run(startup_prog)
logging.debug('after run startup program')
if checkpoint is not None: if checkpoint is not None:
fluid.load(program=train_prog, model_path=checkpoint, executor=exe) fluid.load(program=train_prog, model_path=checkpoint, executor=exe)
if pretrained_model: if pretrained_model:
fluid.load(
def if_exist(var): program=train_prog, model_path=pretrained_model, executor=exe)
return os.path.exists(os.path.join(pretrained_model, var.name))
fluid.load(program=train_prog, model_path=pretrained_model, executor=exe)
if args.use_gpu: if args.use_gpu:
devicenum = get_gpu_num() devicenum = get_gpu_num()
...@@ -207,7 +200,7 @@ def train_async(args): ...@@ -207,7 +200,7 @@ def train_async(args):
test_batch_size = args.test_batch_size test_batch_size = args.test_batch_size
train_loader.set_sample_generator( train_loader.set_sample_generator(
reader.train(args), reader.train(args),
batch_size=train_batch_size, batch_size=train_batch_size,
drop_last=True, drop_last=True,
places=places) places=places)
...@@ -229,9 +222,8 @@ def train_async(args): ...@@ -229,9 +222,8 @@ def train_async(args):
while iter_no <= args.total_iter_num: while iter_no <= args.total_iter_num:
for train_batch in train_loader(): for train_batch in train_loader():
t1 = time.time() t1 = time.time()
lr, loss, feas, label = train_exe.run( lr, loss, feas, label = train_exe.run(feed=train_batch,
feed=train_batch, fetch_list=train_fetch_list)
fetch_list=train_fetch_list)
t2 = time.time() t2 = time.time()
period = t2 - t1 period = t2 - t1
lr = np.mean(np.array(lr)) lr = np.mean(np.array(lr))
...@@ -257,8 +249,8 @@ def train_async(args): ...@@ -257,8 +249,8 @@ def train_async(args):
for batch_id, test_batch in enumerate(test_loader()): for batch_id, test_batch in enumerate(test_loader()):
t1 = time.time() t1 = time.time()
[feas] = exe.run(test_prog, [feas] = exe.run(test_prog,
feed=test_batch, feed=test_batch,
fetch_list=test_fetch_list) fetch_list=test_fetch_list)
label = np.asarray(test_batch[0]['label']) label = np.asarray(test_batch[0]['label'])
label = np.squeeze(label) label = np.squeeze(label)
...@@ -280,7 +272,7 @@ def train_async(args): ...@@ -280,7 +272,7 @@ def train_async(args):
if iter_no % args.save_iter_step == 0 and iter_no != 0: if iter_no % args.save_iter_step == 0 and iter_no != 0:
model_path = os.path.join(model_save_dir + '/' + model_name, model_path = os.path.join(model_save_dir + '/' + model_name,
str(iter_no)) str(iter_no))
if not os.path.isdir(model_path): if not os.path.isdir(model_path):
os.makedirs(model_path) os.makedirs(model_path)
fluid.save(program=train_prog, model_path=model_path) fluid.save(program=train_prog, model_path=model_path)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册