Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google Colab不保存模型或模型检查点?_Python_Tensorflow_Keras_Google Drive Api_Google Colaboratory - Fatal编程技术网

Python Google Colab不保存模型或模型检查点?

Python Google Colab不保存模型或模型检查点?,python,tensorflow,keras,google-drive-api,google-colaboratory,Python,Tensorflow,Keras,Google Drive Api,Google Colaboratory,我一直在使用Colab来训练我的模型,但到目前为止,我只能将权重保存到我的Google Drive中,而不能保存整个模型,甚至模型检查点,这让我非常恼火 我安装Google Drive时使用了: 从google.colab导入驱动器 安装(“/content/gdrive”) 我知道我可以从驱动器中读取文件,因为这段代码可以工作: 将numpy导入为np 将np.load(“/content/gdrive/MyDrive/trainingData.npz”)作为f: dataX=f[“data

我一直在使用Colab来训练我的模型,但到目前为止,我只能将权重保存到我的Google Drive中,而不能保存整个模型,甚至模型检查点,这让我非常恼火

我安装Google Drive时使用了:

从google.colab导入驱动器
安装(“/content/gdrive”)
我知道我可以从驱动器中读取文件,因为这段代码可以工作:

将numpy导入为np
将np.load(“/content/gdrive/MyDrive/trainingData.npz”)作为f:
dataX=f[“dataX”]
dataY=f[“dataY”]
我使用以下方法设置TPU:

%tensorflow\u版本2.x
导入tensorflow作为tf
打印(“Tensorflow版本”+tf.\uuuuuu版本)
尝试:
tpu=tf.distribute.cluster_resolver.TPUClusterResolver()#tpu检测
打印('在TPU上运行',TPU.cluster_spec().as_dict()['worker']))
除值错误外:
raise BaseException('错误:未连接到TPU运行时;有关说明,请参阅此笔记本中的上一个单元格!')
tf.config.experimental\u连接到集群(tpu)
tf.tpu.experimental.initialize\u\tpu\u系统(tpu)
tpu_策略=tf.distribute.experimental.TPUStrategy(tpu)
但当我运行以下代码时,不会保存任何模型检查点:

使用tpu_策略。范围()
模型=顺序()
model.add(LSTM(256,input_shape=(dataX.shape[1],dataX.shape[2]))
模型。添加(辍学(0.2))
model.add(密集型(dataY.shape[1],activation=“softmax”))
compile(loss='classifical\u crossentropy',optimizer='adam')
filepath=“/content/gdrive/MyDrive/weights-improvement-{epoch:02d}-{loss:.4f}.hdf5”
checkpoint=ModelCheckpoint(文件路径,monitor='loss',verbose=1,save\u best\u only=True,mode='min')
回调\u列表=[检查点]
model.fit(dataX,dataY,epochs=50,batch\u size=128)
我甚至不能正常保存模型:
model.save(“/content/gdrive/MyDrive/model”)
给出:

UnimplementedError:未实现文件系统方案“[local]”(文件:“model/variables/variables\u temp/part-00000-of-00001”)
使用执行器执行操作时遇到。此错误将取消所有未来的操作并毒害它们的输出张量。
有趣的是,我仍然可以通过
model.save_weights(“/content/gdrive/MyDrive/model.h5”)

然而,由于我希望能够保存整个模型以备将来训练,因此仅保存权重并不令人满意


我犯了哪些错误?如何保存我的模型?

TPU仅以h5格式保存。如果需要保存整个模型,请使用gcs存储桶。请看这里@Andrey,您能否澄清TPU被限制为.h5格式的含义?你附加的链接不是很清楚。另外,由于
model.save()
允许另存为.h5,这是否意味着我可以简单地通过这样做来解决问题?我在一年前处理过这个问题,有一个更好的链接,但我现在找不到。我不确定是否将模型保存为h5,但我认为它不会起作用。我总是使用
保存权重()