Я не могу сохранить модель после того, как натренировал свои данные с помощью модели концентратора Universal Lite 2 (https://tfhub.dev/google/universal-sentence-encoder-lite/2).
tensorflow== 1.15 tensorflow_hub=0.7.0 python =3.7.6 OS = Window 10 64 bit
I сохраненная модель локальная
path ="C:/Users/771556/Downloads/ModelLiteUSE" #url ="https://tfhub.dev/google/universal-sentence-encoder-lite/2" liteModule = hub.Module(path)
input_placeholder = tf.sparse_placeholder(tf.int64, shape=[None, None]) encodings = liteModule( inputs=dict( values=input_placeholder.values, indices=input_placeholder.indices, dense_shape=input_placeholder.dense_shape))
with tf.Session() as sess: spm_path = sess.run(liteModule(signature="spm_path"))
sp = spm.SentencePieceProcessor() sp.Load(spm_path) print("SentencePiece model loaded at {}.".format(spm_path))
def process_to_IDs_in_sparse_format(sp, sentences): ids = [sp.EncodeAsIds(x) for x in sentences] max_len = max(len(x) for x in ids) dense_shape=(len(ids), max_len) values=[item for sublist in ids for item in sublist] indices=[[row,col] for row in range(len(ids)) for col in range(len(ids[row]))] return (values, indices, dense_shape)
def embed(input): values, indices, dense_shape = process_to_IDs_in_sparse_format(sp, input) # Reduce logging output. logging.set_verbosity(logging.ERROR) with tf.Session() as session: session.run([tf.global_variables_initializer(), tf.tables_initializer()]) message_embeddings = session.run( encodings, feed_dict={input_placeholder.values: values, input_placeholder.indices: indices, input_placeholder.dense_shape: dense_shape}) return message_embeddings
Обучение данных
TrainModel= embed(file_data.text)
Сохранение модели
tf.saved_model.save(TrainModel,'D:/liteTrainmodel')
Ошибка