Я использую Fashion Mnist Dataset, но я новичок в CNN. Скорее всего, я застрял в проблеме формы входной матрицы.
import numpy as np
import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
from keras.layers import Dense,Conv2D,Flatten,Dense,Dropout,MaxPool2D
from keras.models import Sequential
from keras.layers import BatchNormalization
from keras.layers import Activation
dataset = pd.read_csv('fashion-mnist_train.csv')
X=dataset.iloc[:,1:].values
y=dataset.iloc[:,0].values
X=X/255.
X=np.reshape(X,(-1,28,28,1))
#input_shape_problem_i_think
model=Sequential()
model.add(Conv2D(input_shape=(28,28,1),filters=16,kernel_size=(3,3)))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPool2D())
model.add(Conv2D(filters=16,kernel_size=(3,3)))
model.add(BatchNormalization())
model.add(Activation('relu'))
model.add(MaxPool2D())
model.add(Flatten())
model.add(Dense(units=400,activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(units=10,activation='softmax'))
model.summary()
#optimaztion
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.fit(X,y,batch_size=100,epochs=1,validation_split=0.33,verbose=1,)
ValueError: Ошибка при проверке цели: ожидалось, что плотность_платформы_34 равна (10,), но получен массив с формой (1,)
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_46 (Conv2D) (None, 26, 26, 16) 160
_________________________________________________________________
batch_normalization_40 (Batc (None, 26, 26, 16) 64
_________________________________________________________________
activation_39 (Activation) (None, 26, 26, 16) 0
_________________________________________________________________
max_pooling2d_39 (MaxPooling (None, 13, 13, 16) 0
_________________________________________________________________
conv2d_47 (Conv2D) (None, 11, 11, 16) 2320
_________________________________________________________________
batch_normalization_41 (Batc (None, 11, 11, 16) 64
_________________________________________________________________
activation_40 (Activation) (None, 11, 11, 16) 0
_________________________________________________________________
max_pooling2d_40 (MaxPooling (None, 5, 5, 16) 0
_________________________________________________________________
flatten_20 (Flatten) (None, 400) 0
_________________________________________________________________
dense_35 (Dense) (None, 400) 160400
_________________________________________________________________
dropout_18 (Dropout) (None, 400) 0
_________________________________________________________________
dense_36 (Dense) (None, 10) 4010
=================================================================
Total params: 167,018
Trainable params: 166,954
Non-trainable params: 64
_________________________________________________________________