【发布时间】:2021-08-29 10:39:23
【问题描述】:
我正在为 Deepfake 训练两个自动编码器,它需要经过一轮 150,000 轮。我在 10,000 时停止了它,但我希望它能够从它停止的时代恢复训练。有没有办法做到这一点?
train_setA = video.loading_images(setA_path)/255.0
train_setB = video.loading_images(setB_path)/255.0
train_setA += train_setB.mean( axis=(0,1,2) ) - train_setA.mean( axis=(0,1,2) )
batch_size = int(len(os.listdir(setA_path))/20)
print( "press 'q' to stop training and save model" )
for epoch in range(1000000):
batch_size = 64
warped_A, target_A = train_util.training_data( train_setA, batch_size )
warped_B, target_B = train_util.training_data( train_setB, batch_size )
loss_A = aeA.train_on_batch( warped_A, target_A )
loss_B = aeB.train_on_batch( warped_B, target_B )
print( loss_A, loss_B )
print('Current epoch no... ' + str(epoch))
if epoch % 100 == 0:
save_model_weights()
print('Model weights saved')
test_A = target_A[0:14]
test_B = target_B[0:14]
figure_A = np.stack([
test_A,
aeA.predict( test_A ),
aeB.predict( test_A ),
], axis=1 )
figure_B = np.stack([
test_B,
aeB.predict( test_B ),
aeA.predict( test_B ),
], axis=1 )
figure = np.concatenate( [ figure_A, figure_B ], axis=0 )
figure = figure.reshape( (4,7) + figure.shape[1:] )
figure = train_util.stack_images( figure )
figure = np.clip( figure * 255, 0, 255 ).astype('uint8')
cv2.imshow( "", figure )
key = cv2.waitKey(1)
if key == ord('q'):
save_model_weights()
exit()
【问题讨论】:
标签: python tensorflow machine-learning keras