Я хочу реализовать многослойную нейронную сеть, но я получаю ошибку во входном слое кера, что массивы размера 1 могут быть преобразованы в python только скаляры. Вот код:
from keras.models import Sequential
from keras.layers import Activation
from keras import backend as K
from keras.layers.core import Dense
from keras.optimizers import SGD
from keras.metrics import categorical_crossentropy
import numpy as np
import cv2
import os
from random import randint
import matplotlib.pyplot as plt
#Loading the images
DataDir= r"E:\FYP\images_datasets\Training Data"
Categories=["Badshahi-Mosque"]
for category in Categories:
path=os.path.join(DataDir,category)
for img in os.listdir(path):
img_arr=cv2.imread(os.path.join(path,img),cv2.IMREAD_GRAYSCALE)
plt.imshow(img_arr,cmap="gray")
break
break
#Resizing the image
IMG_SIZE=(124,124)
new_array=cv2.resize(img_arr,(IMG_SIZE))
plt.imshow(new_array,cmap="gray")
plt.show()
print(new_array.shape)
training_data=[]
class_num1=[]
#Training the data
def create_training_data():
for category in Categories:
path=os.path.join(DataDir,category)
class_num=Categories.index(category)
for img in os.listdir(path):
try:
img_arr=cv2.imread(os.path.join(path,img))
new_array=cv2.resize(img_arr,(IMG_SIZE))
training_data.append([new_array,class_num])
class_num1.append([class_num])
except Exception as e:
pass
create_training_data()
print("Length of the training data is:",len(training_data))
classes = np.unique(class_num1)
nClasses = len(classes)
print('Total number of outputs : ', nClasses)
print('Output classes being able to be classified: ', classes)
import random
random.shuffle(training_data)
for i in training_data[:5]:
print("Labeling values before on hot enc are:",i[1])
import numpy as np
X=[]
train_labels=[]#One hot encoding values
train_data=[]#Floating values
trained_data=[]#Scalar and floating values
for features,lab in training_data:
X.append(features)
train_labels.append(lab)
for i in X:
train_data = i.astype('float32')
# print("Train data",train_data)
training_data1=[]
for i in train_data:
trained_data= (i - np.min(i)) / (np.max(i) - np.min(i))
training_data1=np.array(trained_data).ravel()
# print("Trained data",training_data1)
from tensorflow.keras import utils as np_utils
train_labels = np_utils.to_categorical(train_labels)
# print(train_labels)enter code here
model = Sequential()
model.add(Dense(units=15376,input_shape=(training_data1,),activation='relu'))
Ошибка происходит над последним слоем на входной фигуре, почему эта ошибка происходит, у меня есть форма изображения после изменения размера 124 * 124,