python - 如何解决构建中性网络的形状问题?
问题描述
我有一个目录,其中有两个文件夹,第一个是冬天的图像,第二个是夏天的图像。但我有这种类型的问题。我该如何解决?(如何解决构建中性网络的形状问题?)
import numpy as np
from PIL import Image
from matplotlib import pyplot as plt
import os
import keras
import joblib
from keras.preprocessing.image import ImageDataGenerator
train_images = 'C:\\Users\\Администратор\\AppData\\Local\\Programs\\Python\\Python36-32\\train_images'
model = keras.Sequential([
keras.layers.Flatten(input_shape=(48, 48, 3)),
keras.layers.Dense(128, activation='relu'),
keras.layers.Dropout(0.5),
keras.layers.Dense(1, activation='sigmoid')
])
model.compile(optimizer='adam',
loss='binary_crossentropy',
metrics=['accuracy'])
datagen = ImageDataGenerator(rescale = 1. /255)
train_generator = datagen.flow_from_directory(
train_images,
target_size = (48,48),
batch_size = 37,
class_mode = 'binary')
model.fit(np.array(train_images), epochs=10, validation_split = 0.1)
看起来您的帖子主要是代码;请添加更多细节。错误 (cmd)。
C:\Users\Администратор>C:\Users\Администратор\AppData\Local\Programs\Python\Pyth
on36-32\image_guess.py
Using Theano backend.
WARNING (theano.configdefaults): g++ not available, if using conda: `conda insta
ll m2w64-toolchain`
C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\site-packag
es\theano\configdefaults.py:560: UserWarning: DeprecationWarning: there is no c+
+ compiler.This is deprecated and with Theano 0.11 a c++ compiler will be mandat
ory
warnings.warn("DeprecationWarning: there is no c++ compiler."
WARNING (theano.configdefaults): g++ not detected ! Theano will be unable to exe
cute optimized C-implementations (for both CPU and GPU) and will default to Pyth
on implementations. Performance will be severely degraded. To remove this warnin
g, set Theano flags cxx to an empty string.
WARNING (theano.tensor.blas): Using NumPy C-API based implementation for BLAS fu
nctions.
Found 370 images belonging to 2 classes.
Traceback (most recent call last):
File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\image_g
uess.py", line 31, in <module>
model.fit(np.array(train_images), epochs=10, validation_split = 0.1)
File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\keras\engine\training.py", line 1154, in fit
batch_size=batch_size)
File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\keras\engine\training.py", line 579, in _standardize_user_data
exception_prefix='input')
File "C:\Users\Администратор\AppData\Local\Programs\Python\Python36-32\lib\sit
e-packages\keras\engine\training_utils.py", line 135, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected flatten_1_input to have 4 dimensions, but got array with shape ()
解决方案
推荐阅读
- java - 来自日期的 Cassandra UUID
- java - 如何解析这个带有内层的 json 文件?
- javascript - 根据下拉选择mysqli自动填充文本输入字段
- react-native - 无法将模块 tensorflow_inception_graph.pb 解析为文件或文件夹
- javascript - Safari 浏览器使用 javascript 中的类报告错误
- kerberos - 如何将 SnappyData 与 Kerberos 集成
- ruby-on-rails - Ruby 调试器:奇怪的缓存
- elasticsearch - elasticsearch 为什么我需要指定路由查询参数
- c - 你怎么知道结构中的某些字段是数组?
- xslt-1.0 - IE - XSL 文件没有从浏览器缓存中加载(总是点击服务器加载)