Closed choidam closed 4 years ago
sample model & save checkpoints
# save checkpoint
checkpoint_path = "training_2/cp-{epoch:04d}.ckpt"
checkpoint_dir = os.path.dirname(checkpoint_path)
cp_callback = tf.keras.callbacks.ModelCheckpoint(filepath=checkpoint_path,
save_weights_only=True,
period=5,
verbose=1)
newmodel = create_model()
newmodel.save_weights(checkpoint_path.format(epoch=0))
newmodel.fit(dataset,
epochs=40,
shuffle=True,
validation_data=val_dataset,
callbacks=[LearningRateScheduler(scheduler, verbose=1), callbacks, cp_callback],
workers=4)
check directory
latest = tf.train.latest_checkpoint(checkpoint_dir)
latest
load weights to new model
# Create a new model instance
model2 = create_model()
# Load the previously saved weights
model2.load_weights(latest)
train model2
model2.fit(dataset,
epochs=40,
# shuffle=True,
validation_data=val_dataset,
callbacks=[LearningRateScheduler(scheduler, verbose=1), callbacks]),
workers=4)
확실히 epoch1부터 정확도는 높지만 훈련도가 전혀 증가하지 않는다 ... ㅠㅠ 문제가 뭘까 .. 처음부터 쓰면 안 되는 방법이었나 ...?...
공식문서 참고하기
https://www.tensorflow.org/tutorials/keras/save_and_load?hl=tr