Skip to content

Instantly share code, notes, and snippets.

@spnova12
Last active July 12, 2018 04:46
Show Gist options
  • Save spnova12/4959b6ab6034ca2191a028c5000022b6 to your computer and use it in GitHub Desktop.
Save spnova12/4959b6ab6034ca2191a028c5000022b6 to your computer and use it in GitHub Desktop.
이미지읽는 시간과 training 시간의 비교
def train_base():
start_time = 0
time_read = 0
time_read_training = 0
# training 시키지 않고 이미지 읽기만 run
for i, batch in tqdm.tqdm(enumerate(training_data_loader, 1)):
if i==1: start_time = time.time()
if i == 2000:
end_time = time.time()
time_read = end_time - start_time
break
img_input, img_target = batch[0].to(device), batch[1].to(device)
noise = torch.randn(batch_size, 1, training_crop_size / 2, training_crop_size / 2).to(device)
# training 과 이미지 읽기 모두 run
for i, batch in tqdm.tqdm(enumerate(training_data_loader, 1)):
if i==1: start_time = time.time()
if i == 2000:
end_time = time.time()
time_read_training = end_time - start_time
break
netG.train()
img_input, img_target = batch[0].to(device), batch[1].to(device)
noise = torch.randn(batch_size, 1, training_crop_size/2, training_crop_size/2).to(device)
output = netG(img_input, noise)
loss = MSE(output, img_target)
G_optimizer.zero_grad()
loss.backward()
G_optimizer.step()
print('time_read :',time_read, 'time_read_training :', time_read_training,
'time_read/time_read_training :', time_read/time_read_training)
"""
> 결과
(rsndomcrop)
time_read : 71.56252527236938 # 읽기만 하는 경우
time_read_training : 112.93482851982117 # 읽고 학습까지 하는 경우
time_read/time_read_training : 0.633662141345612
(img centercrop)
time_read : 61.6091570854187 # 읽기만 하는 경우
time_read_training : 107.02364420890808 # 읽고 학습까지 하는 경우
time_read/time_read_training : 0.5756593091257369
아무튼 이미지을 읽는 시간과 training 시키는 시간과 비슷하다는 것을 알 수 있다.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment