0

尝试转换张量流 python 保存的模型时出现以下错误

tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model ./saved_1 ./exported_model

回溯(最近一次通话最后):

文件“/Users/a/workspace/pen3/myenv/bin/tensorflowjs_converter”,第 10 行,在 sys.exit(main())

文件“/Users/a/workspace/pen3/myenv/lib/python3.5/site-packages/tensorflowjs/converters/converter.py”,第 358 行,在主要 strip_debug_ops=FLAGS.strip_debug_ops)

文件“/Users/a/workspace/pen3//myenv/lib/python3.5/site-packages/tensorflowjs/converters/tf_saved_model_conversion_v2.py”,第 268 行,convert_tf_saved_model model = load(saved_model_dir, saved_model_tags)

TypeError: load() 接受 1 个位置参数,但给出了 2 个

这些是 saved_1 目录的内容

  • 保存模型.pb
  • 变量
    • variables.data-00000-of-00001
    • 变量.index

TensorFlow.js 版本:1.13.1

tensorflowjs 转换器版本:1.0.1

带有 python 版本的虚拟环境:3.5.5

python中的代码来保存模型数据。张量流中的简单线性回归

import tensorflow as tf
import numpy as np 
import os
import shutil
from sklearn.datasets import fetch_california_housing
from sklearn.preprocessing import StandardScaler

n_epochs = 11
learning_rate = 0.01

saved_models = 'saved_models'
if os.path.exists(saved_models):
    shutil.rmtree(saved_models)

os.makedirs(saved_models)



housing = fetch_california_housing()
(m,n) = housing.data.shape
scaler = StandardScaler()

scaled_housing_data = scaler.fit_transform(housing.data)
scaled_housing_data_plus_bias = np.c_[np.ones((m, 1)), scaled_housing_data]

X = tf.constant( scaled_housing_data_plus_bias, dtype=tf.float32 , name='X')
Y = tf.constant( housing.target.reshape(-1, 1) , dtype=tf.float32, name='Y')
theta = tf.Variable(tf.random_uniform( [n+1, 1] , -1.0, 1.0))

y_pred = tf.matmul( X, theta, name='predictions')
error = y_pred - Y
mse = tf.reduce_mean(tf.square(error), name="mse")
gradients = 2/m * tf.matmul(tf.transpose(X), error)
training_op = tf.assign(theta, theta - learning_rate * gradients)

init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)

    for epoch in range(n_epochs):
        if epoch % 5 == 0:
            print("Epoch", epoch, "MSE =", mse.eval())
            tf.saved_model.simple_save(sess, saved_models + '/model_' + str(epoch) , inputs={'myInput' :X },  outputs={'myOutput' : y_pred })
        sess.run(training_op)


    best_theta = theta.eval()

print(best_theta)
4

0 回答 0