Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.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
autokeras模型到tensorflowjs模型的转换_Tensorflow_Tensorflow.js - Fatal编程技术网

autokeras模型到tensorflowjs模型的转换

autokeras模型到tensorflowjs模型的转换,tensorflow,tensorflow.js,Tensorflow,Tensorflow.js,我正在尝试通过autokeras制作模型,并希望将其部署到移动设备上。 为此,我需要使用tensorflowjs_转换器将生成的模型转换为移动格式。 在尝试我的模型之前,我使用autokeras回归器进行了测试,但转换失败,并显示以下错误消息 ValueError: The same saveable will be restored with two names: layer_with_weights-0/encoding_layers/6/_table/.ATTRIBUTES/table

我正在尝试通过autokeras制作模型,并希望将其部署到移动设备上。 为此,我需要使用tensorflowjs_转换器将生成的模型转换为移动格式。 在尝试我的模型之前,我使用autokeras回归器进行了测试,但转换失败,并显示以下错误消息

ValueError: The same saveable will be restored with two names: layer_with_weights-0/encoding_layers/6/_table/.ATTRIBUTES/table
我只测试了保存的tf格式,因为我在tensorflowjs文档中看到,保存的keras格式可能无法完全转换(冻结的模型不能很好地从tf保存的模型中生成,因此跳过)

这是创建模型文件的代码(与示例相同,但保存模型的最后一行除外)

模型转换步骤。 我还使用了转换后的序列模型(tf.keras.sequential(model.layers)),但会产生相同的错误

<< tf_saved_model -> tfjs_graph_model >>
(tfjsv) D:\0.Projects\autokeras_test\tfjs\tfjsv>tensorflowjs_converter --input_format tf_saved_model --output_format tfjs_graph_model D:\0.Projects\autokeras_test\model_test\pb_california D:\0.Projects\autokeras_test\model_test\res\

tfjs\u图形\u模型>>
(tfjsv)D:\0.Projects\autokeras\u test\tfjs\tfjsv>tensorflowjs\u转换器--输入格式tf\u保存的\u模型--输出格式tfjs\u图形\u模型D:\0.Projects\autokeras\u test\model\u test\pb\u加州D:\0.Projects\autokeras\u test\model\test\res\

我不太确定是否可以将autokeras模型转换为tfjs层模型。我不是这方面的专家。但是,在我看来,autokeras基于keras,autokeras模型在keras环境下运行。但是,在我看来,autokeras基于keras,autokeras模型在keras环境下运行。所以我认为autokeras模型将与keras模型兼容,keras模型可以通过tensorflowjs(搁置操作员问题)转换为web模型。我错了吗?是的,在阅读文档之后,这是可能的。您可以尝试使用
model.save(“model\u autokeras.h5”)
将其转换为keras模型,然后使用
tensorflowjs\u转换器--输入格式keras--重量\u碎片大小\u字节60000000
将其转换为keras模型吗。包括输入和输出路径。我不太确定是否可以将autokeras模型转换为tfjs层模型。我不是这方面的专家。但是,在我看来,autokeras基于keras,autokeras模型在keras环境中运行。但是,在我看来,autokeras基于keras,autokeras模型在keras环境中运行。所以我认为autokeras模型将与keras模型兼容,keras模型可以通过tensorflowjs(搁置操作员问题)转换为web模型。我错了吗?是的,在阅读文档之后,这是可能的。您可以尝试使用
model.save(“model\u autokeras.h5”)
将其转换为keras模型,然后使用
tensorflowjs\u转换器--输入格式keras--重量\u碎片大小\u字节60000000
将其转换为keras模型吗。包括输入和输出路径。
from sklearn.datasets import fetch_california_housing
import numpy as np
import pandas as pd
import tensorflow as tf
import autokeras as ak

house_dataset = fetch_california_housing()
df = pd.DataFrame(
    np.concatenate((
        house_dataset.data, 
        house_dataset.target.reshape(-1,1)),
        axis=1),
    columns=house_dataset.feature_names + ['Price'])
train_size = int(df.shape[0] * 0.9)
df[:train_size].to_csv('train.csv', index=False)
df[train_size:].to_csv('eval.csv', index=False)
train_file_path = 'train.csv'
test_file_path = 'eval.csv'
import pandas as pd
import numpy as np
# x_train as pandas.DataFrame, y_train as pandas.Series
x_train = pd.read_csv('train.csv')
print(type(x_train)) # pandas.DataFrame
y_train = x_train.pop('Price')
print(type(y_train)) # pandas.Series

# Preparing testing data.
x_test = pd.read_csv('eval.csv')
y_test = x_test.pop('Price')
# You can also use numpy.ndarray for x_train and y_train.
x_train = x_train.to_numpy().astype(np.unicode)
y_train = y_train.to_numpy()
x_test = x_test.to_numpy().astype(np.unicode)
y_test = y_test.to_numpy()
# It tries 10 different models.
reg = ak.StructuredDataRegressor(max_trials=3, overwrite=True)
reg.fit(x_train, y_train, epochs=10)
model = reg.export_model()
type(model)
tf.keras.models.save_model(model, "model_test/pb_california", save_format="tf")

<< tf_saved_model -> tfjs_graph_model >>
(tfjsv) D:\0.Projects\autokeras_test\tfjs\tfjsv>tensorflowjs_converter --input_format tf_saved_model --output_format tfjs_graph_model D:\0.Projects\autokeras_test\model_test\pb_california D:\0.Projects\autokeras_test\model_test\res\