Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
551 views
in Technique[技术] by (71.8m points)

google colaboratory - Error in trying to Save a tensorflow model

I am testing a simple model with the main to serving it . I am in colab environment. executing the code

import numpy as np
from tensorflow import keras
model=tf.keras.Sequential([keras.layers.Dense(units=1,input_shape=[1])])
model.compile(optimizer='sgd', loss='mean_squared_error')
xs=np.array([-1.0,0.0,1.0,2.0,3.0,4.0],dtype=float)
ys=np.array([-3.0,-1.0,1.0,3.0,5.0,7.0],dtype=float)
model.fit(xs,ys,epochs=500,verbose=2)

tf.saved_model.simple_save(
    keras.backend.get_session(),
    export_path,
    inputs={'input_image': model.input},
    outputs={t.name:t for t in model.outputs})

I obtain the following error that I don't know how to fix:

<ipython-input-19-634675006b49> in <module>()
----> 1 tf.saved_model.simple_save(
      2     keras.backend.get_session(),
      3     export_path,
      4     inputs={'input_image': model.input},
      5     outputs={t.name:t for t in model.outputs})

AttributeError: module 'tensorflow._api.v2.saved_model' has no attribute 'simple_save'```



question from:https://stackoverflow.com/questions/65952161/error-in-trying-to-save-a-tensorflow-model

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

simple_save is deprecated in tensorflow v2 (LINK).

Try to use model.save(saving/path) instead

full documentation on model.save : https://www.tensorflow.org/tutorials/keras/save_and_load#save_the_entire_model


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...