我在用Keras编写网络时遇到了问题。这个网络必须,给定一组属于一个圆的点作为输入,确定这个圆。基本上,该网络具有维度阵列(num circles,num points,2)作为输入,其在2维中表示多个“num circles”的圆的多个“num points”的坐标。网络必须有一个向量(num circles,3)作为输出,其中包含圆心的2个坐标和相应的半径。该网络是:
import numpy as np
import keras
from keras import layers
x_train = array_of_circles
# Input vector of shape (100, 1000, 2) i.e., 100 circles of 1000 points each
y_train = np.concatenate((array_of_centers, array_of_radius.reshape(-1,1)), axis=1)
# Output: [x_center, y_center, radius]
# Define the neural network model
model = keras.Sequential([
layers.InputLayer(input_shape=(num_points, 2)),
layers.Dense(64, activation='relu'),
layers.Dense(64, activation='relu'),
layers.Dense(32, activation='relu'),
layers.Dense(3) # Output layer with 3 units for x_center, y_center, and radius
])
# Compile the model
model.compile(optimizer='adam', loss='mean_squared_error')
# Train the model
model.fit(x_train, y_train, epochs=10, batch_size=32)
我试着编译代码,得到了这样的消息:
Incompatible shapes: [32,1000,3] vs. [32,3]
[[{{node gradient_tape/mean_squared_error/BroadcastGradientArgs}}]] [Op:__inference_train_function_6137]
如何匹配输入和输出形状?
1条答案
按热度按时间k2fxgqgv1#
不知道这是不是你要找的,但下面的工作对我来说没有错误:
输出: