python - 转化率 神经网络、输出和 y 数据维度
问题描述
我是神经网络的新手(使用 Keras,tf 后端),我正在尝试训练一个网络来发现 200x200 图像中的特定像素。输入数据具有格式为(数量,200,200,1)的 np 数组,因为它们是黑白图像,数组值范围从 -0.5 到 0.5。标记的 y 数据具有相同的格式,每个像素的值为 0 和 1 个像素的值为 1。
导入数据后,如下所示:
我的网络如下所示:
train_images = np.expand_dims(train_images, axis=3)
train_labels = np.expand_dims(train_labels, axis=3)
test_images = np.expand_dims(test_images, axis=3)
test_labels = np.expand_dims(test_labels, axis=3)
print(train_images.shape) # (example, 200, 200, 1)
print(train_labels.shape) # (example, 200, 200, 1)
print(test_images.shape)
print(test_labels.shape)
num_filters = 16
filter_size = 5
filter_size2 =3
pool_size = 2
input_shape=(200,200,1)
output_shape = input_shape
inputs = tf.keras.Input(shape=input_shape)
x= tf.keras.layers.Conv2D(num_filters, filter_size, activation=tf.nn.relu)input_shape=input_shape, padding='same')(inputs)
x= tf.keras.layers.Conv2D(num_filters, filter_size2, padding='same')(x)
x= tf.keras.layers.MaxPooling2D(pool_size=pool_size)(x)
x= tf.keras.layers.Dropout(0.25)(x)
x= tf.keras.layers.Flatten()(x)
x= tf.keras.layers.Dense(64, activation=tf.nn.relu)(x)
x= tf.keras.layers.Dropout(0.5)(x)
x= tf.keras.layers.Dense(1024, activation=tf.nn.relu)(x)
outputs = tf.keras.layers.Dense(output_shape, activation=tf.nn.softmax)(x)
model = tf.keras.Model(inputs=inputs, outputs=outputs)
model.summary()
model.compile('Adam', loss='categorical_crossentropy',metrics=['accuracy'],)
history = model.fit(train_images, to_categorical(train_labels), epochs=3,
validation_data=(test_images, to_categorical(test_labels)))
当我将图层展平以使用 Dense 图层时,我希望 softmax 计算每个像素的概率,但 Dense 似乎只采用一维数字而没有数组格式的元组。我还考虑将网络更改为 2 个节点(x 和 y 坐标)的输出,但是当我上传具有 2 个坐标的数据时,它会再次具有格式(数量,1,1)。所以输出维度不适合 y 数据维度。
对于如何尝试训练网络以找到搜索的像素的最佳方式,我会很高兴提供任何帮助。
解决方案
推荐阅读
- css - 稍微滚动后,粘性导航栏不再固定
- python - 关于如何使用 html2json 的简单示例
- android - 在分页库 3 中恢复滚动位置
- javascript - React 组件不会随着状态变化而更新
- csv - 与 neo4j 和 csv 文件相关
- javascript - 如何检测 Safari 浏览器中的活动选项卡已更改?
- c# - 使用 C# SDK 定期刷新 Azure 存储帐户密钥
- sonarqube - 如何使用 Sonarqube 插件接口在登录时获取用户的用户名和密码
- django-rest-framework - python manage.py makemigrations在Windows系统上没有响应
- html - 从 html 表加载后,制表符表为空