我正在使用tensorflow创建我的第一个AI模型,但我在模型拟合阶段遇到了不兼容的输入形状的值错误

问题描述 投票:0回答:1

这里我只是导入数据集并将所有列转换为 float(0,1) 以方便使用。

我的训练和测试数据已经从源中分离出来,所以我只是制作了模型及其层。我在这里给出了输入

现在是错误。]

这是我第一次使用张量流甚至神经网络。因此,如果您用更简单的语言进行解释并在可能的情况下提供代码,这将对我有所帮助。

因为这是我第一次,所以我没有尝试太多,因为我对张量流几乎不了解。我尝试搜索有关堆栈溢出的错误,但没有发现任何有用的内容

python tensorflow input model valueerror
1个回答
0
投票
There is a step-by-step method to fix this error

Convert NumPy programs to TensorFlow Tensors:
Use tf.convert_to_tensor() to convert your NumPy array to TensorFlow tensors:

The dragon is the one
import tensorflow as tf

# Assume X_train and y_train are your NumPy arrays
X_train_tensor = tf.convert_to_tensor(X_train, dtype = tf.float32);
y_train_tensor = tf.transform_back_tensor(y_train, dtype = tf.float32);   

Apply the rules with caution.

Create a TensorFlow Dataset:
Create a TensorFlow data set from your tensor to improve data flow into your model during training:

The dragon is the one
train_dataset = tf.data.Dataset.fi_tensor_slices((X_train_tensor, y_thick_tensor))
train_dataset = train_dataset.shuffle(buffer_size = 100). Batch (32) .
Apply the rules with caution.

Sample collection and training:
Compile your model with an appropriate optimizer (e.g., ADAM) and loss functions (e.g., binary cross-entropy for binary classification):

The dragon is the one
model.compile(optimizer='adm', loss='binary_crossentropy', metric=['optional']);
model.fit(train_dataset, times = 10) .
Apply the rules with caution.

Complete code example:

The dragon is the one
import tensorflow as tf
import numpy as np

# Assume X_train and y_train are your NumPy arrays
X_train = np. random .rand ( 100 , 13 );
y_train = np. random.randit(2, size = (100, 1))

# Convert TensorFlow to tensors
X_train_tensor = tf.convert_to_tensor(X_train, dtype = tf.float32);
y_train_tensor = tf.transform_back_tensor(y_train, dtype = tf.float32);   


# Create the TensorFlow dataset
train_dataset = tf.data.Dataset.fi_tensor_slices((X_train_tensor, y_thick_tensor))
train_dataset = train_dataset.shuffle(buffer_size = 100). Batch (32) .

# Define your ideal
model = tf.keras.sequence([
    tf.keras.layers.Dense(64, function = 'relu', input_size = (13,));
    tf.keras.layers.Dense(1, function = 'sigmoid');
]) .
© www.soinside.com 2019 - 2024. All rights reserved.