通过 Colab 上的回调节省准确性和损失
因此,我尝试在 Colab 上训练模型,这将花费我大约 70-72 小时的持续运行时间。我有一个免费帐户,所以我经常因为过度使用或不活动而被踢,这意味着我不能将历史记录转储到 pickle 文件中。
history = model.fit_generator(custom_generator(train_csv_list,batch_size), steps_per_epoch=len(train_csv_list[:13400])//(batch_size), epochs=1000, verbose=1, callbacks=[stop_training], validation_data=(x_valid,y_valid))
我在回调方法中找到了 CSVLogger 并将其添加到我的回调中,如下所示。但由于某种原因,它不会创建 model_history_log.csv。我没有收到任何错误或警告。我做错了什么部分? 我的目标是在整个训练过程中仅保存准确性和损失。
class stop_(Callback):
def on_epoch_end(self, epoch, logs={}):
model.save(Path("/content/drive/MyDrive/.../model" +str(int(epoch))))
CSVLogger("/content/drive/MyDrive/.../model_history_log.csv", append=True)
if(logs.get('accuracy') > ACCURACY_THRESHOLD):
print("\nReached %2.2f%% accuracy, so stopping training!!" %(ACCURACY_THRESHOLD*100))
self.model.stop_training = True
stop_training = stop_()
另外,由于我在每个时期都保存模型,因此模型是否保存此信息?到目前为止我还没有发现任何东西,我怀疑它是否能保存准确性、损失、验证准确性等
So im trying to train a model on colab, and it is going to take me roughly 70-72 hr of continues running. I have a free account, so i get kicked due to over-use or inactivity pretty frequently, which means I cant just dump history in a pickle file.
history = model.fit_generator(custom_generator(train_csv_list,batch_size), steps_per_epoch=len(train_csv_list[:13400])//(batch_size), epochs=1000, verbose=1, callbacks=[stop_training], validation_data=(x_valid,y_valid))
I found the CSVLogger in callback method and added it to my callback as below. But it wont create model_history_log.csv for some reason. I don't get any error or warning. What part am i doing wrong ?
My goal is to only save accuracy and loss, throughout the training process
class stop_(Callback):
def on_epoch_end(self, epoch, logs={}):
model.save(Path("/content/drive/MyDrive/.../model" +str(int(epoch))))
CSVLogger("/content/drive/MyDrive/.../model_history_log.csv", append=True)
if(logs.get('accuracy') > ACCURACY_THRESHOLD):
print("\nReached %2.2f%% accuracy, so stopping training!!" %(ACCURACY_THRESHOLD*100))
self.model.stop_training = True
stop_training = stop_()
Also since im saving the model at every epoch, does the model save this information ? so far i havent found anything, and i doubt it saves accuracy, loss, val accuracy,etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
认为您想按如下方式编写回调,
然后在运行 model.fit 使用代码之前
记住在 model.fit 中设置回调 = 回调。我在一个简单的数据集上测试了这一点。它只运行了 3 个 epoch,准确率就超过了 0.98 的阈值。因此,由于它运行了 3 个纪元,因此它在 sdir 中创建了 3 个保存模型文件,标记为 ,
它还创建了标记为 traindata.csv 的 csv 文件。 csv 文件内容是
Think you want to write your callback as follows
then before you run model.fit use code
Remember in model.fit set callbacks = callbacks. I tested this on a simple dataset. It ran for only 3 epochs before the accuracy exceeded the threshold of .98. So since it ran for 3 epoch it created 3 save model files in the sdir labeled as
It also created the csv file labelled as traindata.csv. The csv file content was