如何创建自定义并查看训练模型的自定义输入的输出?



我想在自定义输入上评估tensorflow模型,如何这样做?我有以下工作tensorflow代码

import tensorflow as tf
from tensorflow import keras
from tensorflow.keras.layers import Flatten, Dense
import numpy as np
import pandas as pd
all_data, all_labels = np.resize(np.linspace(0,50,100),[1000,3]), np.random.randint(0,2,[1000])
def build_model():
model = keras.Sequential([
Dense(20, activation=tf.nn.relu, input_shape=[len(all_data[0])]),
Dense(20, activation=tf.nn.relu, input_shape=[20]),
Dense(1, activation=tf.nn.sigmoid)
])
model.compile(
optimizer=tf.keras.optimizers.Adam(),
loss=tf.keras.losses.binary_crossentropy,
metrics=[
tf.keras.metrics.BinaryAccuracy(name='accuracy')

]
)
return model
model = build_model()
history = model.fit(all_data, all_labels, epochs=200)

我想给自定义输入模型,如何这样做,例如输入像[100,2,4]?

您可以使用model。返回损失值&测试模式下模型的度量值。">

它以批处理模式运行,所以如果你传递一批输入,它将计算度量,损失等。

如果你想让模型预测,等效函数是model.predict(myinput),它返回你的模型在myinput上的预测标签。

最新更新