如何更新训练模型中使用的python库的版本



我在Google colab上训练了一个模型,然后丢弃了它,然后我在我的系统上用VS Code完成了这个项目。我得到了一个错误,说版本不匹配,因为我使用的是最新版本的库,而协作实验室使用的是旧版本。我在我的系统上重新训练了模型,这花了很多时间,因为我的系统有一个基本配置。我对协作的唯一使用是将训练的重点放在协作上,而不是放在我的系统上

我不知道会有版本冲突,因为我以为Colab会有最新版本的库

我有colab (Google) tensorflow版本2.9.2和我的Raspberry 4 tensorflow版本2.4.1。所以不同的版本。我用input_shape(220,220,3)制作了一个预训练模型VGG19。我将图像分为两类

一旦我在Colab中训练了模型。谷歌环境,然后从Colab除了模型和它的权重。

# serialize model to JSON
model_json =  loaded_model2.to_json()
with open('/content/drive/MyDrive/dataset/extract/model_5.json', "w") as json_file:
json_file.write(model_json)
# serialize weights to HDF5
loaded_model2.save_weights('/content/drive/MyDrive/model_5.h5')
print("Saved model to disk")

正如我所指出的,然后我打算在我的Raspberry4上使用该训练模型。所以我在Raspberry上创建了一个模型,就像我在Colab上做的那样,但我不做"适合"。接下来我要做的是加载。h5文件,其中包含在Colab.Google中生成的"权重"。原则上这对我来说是有效的

model_new = tf.keras.Sequential()
model_new.add(tf.keras.applications.VGG19(include_top=false, weights='imagenet',pooling='avg',input_shape=(220,220,3)))
model_new.add(tf.keras.layers.Dense(2,activation="softmax"))
opt = tf.keras.optimizers.SGC(0,004)
model_new.compile(loss='categorical_crossentropy',optimizer=opt,metrics=['accuracy'])
model_new.load_weights('/home/pi/projects/models/model_5.h5)

最新更新