我需要在CNN编码器模型中为不同的任务存储来自特定层的中间结果。但是,如果我等待整个模型完成运行,GPU内存就会溢出。所有要写入的值都是火炬张量。 目前,我的重点是将其写入文本文件,如下所示:
def train(loop):
for i, batch in enumerate(train_loader, 0):
store_dictionary['images'] = images
store_dictionary['recon'] = recon
#after the train loop is complete
try:
output_file = open('stored_dictionary_values.txt', 'wt')
output_file.write(str(store_dict))
output_file.close()
except:
print("Unable to write to file")
如何在每次循环后写入值,但需要将值附加到txt文件的现有键中
目前没有回答
相关问题 更多 >
编程相关推荐