Skip to content

Commit

Permalink
py3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
yysijie committed Jul 6, 2018
1 parent 75df9df commit 5ec006f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions processor/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class Demo(IO):
"""
def start(self):

openpose = f'{self.arg.openpose}/examples/openpose/openpose.bin'
openpose = '{}/examples/openpose/openpose.bin'.format(self.arg.openpose)
video_name = self.arg.video.split('/')[-1].split('.')[0]
output_snippets_dir = f'./data/openpose_estimation/snippets/{video_name}'
output_snippets_dir = './data/openpose_estimation/snippets/{}'.format(video_name)
output_sequence_dir = './data/openpose_estimation/data'
output_sequence_path = f'{output_sequence_dir}/{video_name}.json'
output_sequence_path = '{}/{}.json'.format(output_sequence_dir, video_name)
output_result_dir = self.arg.output_dir
output_result_path = f'{output_result_dir}/{video_name}.mp4'
output_result_path = '{}/{}.mp4'.format(output_result_dir, video_name)
label_name_path = './resource/kinetics_skeleton/label_name.txt'
with open(label_name_path) as f:
label_name = f.readlines()
Expand All @@ -38,7 +38,7 @@ def start(self):
render_pose=0,
model_pose='COCO')
command_line = openpose + ' '
command_line += ' '.join([f'--{k} {v}' for k, v in openpose_args.items()])
command_line += ' '.join(['--{} {}'.format(k, v) for k, v in openpose_args.items()])
shutil.rmtree(output_snippets_dir, ignore_errors=True)
os.makedirs(output_snippets_dir)
os.system(command_line)
Expand Down Expand Up @@ -73,7 +73,7 @@ def start(self):
intensity = (feature*feature).sum(dim=0)**0.5
intensity = intensity.cpu().detach().numpy()
label = output.sum(dim=3).sum(dim=2).sum(dim=1).argmax(dim=0)
print(f'Prediction result: {label_name[label]}')
print('Prediction result: {}'.format(label_name[label]))
print('Done.')

# visualization
Expand All @@ -94,7 +94,7 @@ def start(self):
for img in images:
writer.writeFrame(img)
writer.close()
print(f'The Demo result has been saved in {output_result_path}.')
print('The Demo result has been saved in {}.'.format(output_result_path))

@staticmethod
def get_parser(add_help=False):
Expand Down
4 changes: 2 additions & 2 deletions processor/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def load_arg(self, argv=None):
key = vars(p).keys()
for k in default_arg.keys():
if k not in key:
print(f'Unknown Arguments: {k}')
print('Unknown Arguments: {}'.format(k))
assert k in key

parser.set_defaults(**default_arg)
Expand Down Expand Up @@ -87,7 +87,7 @@ def gpu(self):
self.model = nn.DataParallel(self.model, device_ids=self.gpus)

def start(self):
self.io.print_log(f'Parameters:\n{str(vars(self.arg))}\n')
self.io.print_log('Parameters:\n{}\n'.format(str(vars(self.arg))))

@staticmethod
def get_parser(add_help=False):
Expand Down
24 changes: 12 additions & 12 deletions processor/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ def load_data(self):

def show_epoch_info(self):
for k, v in self.epoch_info.items():
self.io.print_log(f"\t{k}: {v}")
self.io.print_log('\t{}: {}'.format(k, v))
if self.arg.pavi_log:
self.io.log('train', self.meta_info['iter'], self.epoch_info)

def show_iter_info(self):
if self.meta_info['iter'] % self.arg.log_interval == 0:
info = f"\tIter {self.meta_info['iter']} Done."
info ='\tIter {} Done.'.format(self.meta_info['iter'])
for k, v in self.iter_info.items():
if isinstance(v, float):
info = info + f' | {k}: {v:.4f}'
info = info + ' | {}: {:.4f}'.format(k, v)
else:
info = info + f' | {k}: {v}'
info = info + ' | {}: {}'.format(k, v)

self.io.print_log(info)

Expand All @@ -101,38 +101,38 @@ def test(self):
self.show_epoch_info()

def start(self):
self.io.print_log(f'Parameters:\n{str(vars(self.arg))}\n')
self.io.print_log('Parameters:\n{}\n'.format(str(vars(self.arg))))

# training phase
if self.arg.phase == 'train':
for epoch in range(self.arg.start_epoch, self.arg.num_epoch):
self.meta_info['epoch'] = epoch

# training
self.io.print_log(f"Training epoch: {epoch}")
self.io.print_log('Training epoch: {}'.format(epoch))
self.train()
self.io.print_log(f'Done.')
self.io.print_log('Done.')

# save model
if ((epoch + 1) % self.arg.save_interval == 0) or (
epoch + 1 == self.arg.num_epoch):
filename = f'epoch{epoch + 1}_model.pt'
filename = 'epoch{}_model.pt'.format(epoch + 1)
self.io.save_model(self.model, filename)

# evaluation
if ((epoch + 1) % self.arg.eval_interval == 0) or (
epoch + 1 == self.arg.num_epoch):
self.io.print_log(f'Eval epoch: {epoch}')
self.io.print_log('Eval epoch: {}'.format(epoch))
self.test()
self.io.print_log(f'Done.')
self.io.print_log('Done.')
# test phase
elif self.arg.phase == 'test':

# the path of weights must be appointed
if self.arg.weights is None:
raise ValueError('Please appoint --weights.')
self.io.print_log(f'Model: {self.arg.model}.')
self.io.print_log(f'Weights: {self.arg.weights}.')
self.io.print_log('Model: {}.'.format(self.arg.model))
self.io.print_log('Weights: {}.'.format(self.arg.weights))

# evaluation
self.io.print_log('Evaluation Start:')
Expand Down
4 changes: 2 additions & 2 deletions processor/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def show_topk(self, k):
rank = self.result.argsort()
hit_top_k = [l in rank[i, -k:] for i, l in enumerate(self.label)]
accuracy = sum(hit_top_k) * 1.0 / len(hit_top_k)
self.io.print_log(f'\tTop{k}: {100 * accuracy:.2f}%')
self.io.print_log('\tTop{}: {:.2f}%'.format(k, 100 * accuracy))

def train(self):
self.model.train()
Expand All @@ -98,7 +98,7 @@ def train(self):

# statistics
self.iter_info['loss'] = loss.data.item()
self.iter_info['lr'] = f'{self.lr:.6f}'
self.iter_info['lr'] = '{:.6f}'.format(self.lr)
loss_value.append(self.iter_info['loss'])
self.show_iter_info()
self.meta_info['iter'] += 1
Expand Down

0 comments on commit 5ec006f

Please sign in to comment.