Я новый питон, и сейчас у меня есть эта проблема.Я пытаюсь сделать модель CNN для 27 классификаций.Но я получаю эту ошибку ValueError: Невозможно передать значение shape (64,) для Tensor 'target / Y: 0', имеющего форму '(?, 27)' [вот изображение моей ошибки 1
вот мой код, я буду очень признателен за любые предложения и комментарии PS Я новичок в этом, поэтому заранее извиняюсь за ошибку noob
import numpy as np, cv2, os
import tflearn
import parser
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.estimator import regression
img_size = 50
LR = 1e-3
MODEL_N = 'wood-{}-{}.model'.format(LR, '2conv-basic')
folders = ['alan batu', 'alan bunga', 'bindang', 'bintangor',
'dark red meranti',
'durian','geronggang','jelutong','jongkong','kapur','keruing',
'light red meranti',
'menggris','merbau','mersawa','nyatoh','perupok','pulai','ramin',
'rengas','resak','selangan batu','sepetir','terentang',
'white meranti','yellow meranti']
labels = []
images = []
for folder in folders:
for path in os.listdir('C:/Users/mwasi/Desktop/AI/pictures/sorted/'+folder):
img =
cv2.imread('C:/Users/mwasi/Desktop/AI/pictures/sorted/'+folder+'/'+path,0)
images.append(cv2.resize(img, (img_size, img_size)))
labels.append(folders.index(folder))
to_train= 0
training_data =[]
testing_data =[]
train_images, test_images, train_labels, test_labels = [],[],[],[]
for image, label in zip(images, labels):
if to_train<5:
train_images.append(image)
train_labels.append(label)
to_train+=1
training_data.append ([np.array(image), np.array(label)])
else:
test_images.append(image)
test_labels.append(label)
to_train = 0
testing_data.append ([np.array(image), np.array(label)])
print('# of training images: ', len(train_images))
print('# of testimg images: ', len(test_images))
np.save('train_data.npy',training_data)
np.save('testing_data.npy',testing_data)
convnet = input_data(shape=[None, img_size,img_size, 1], name='input')
convnet = conv_2d(convnet, 32, 5,padding='valid', activation='relu')
convnet = max_pool_2d(convnet, 5)
convnet = conv_2d(convnet, 64, 5, activation='relu')
convnet = max_pool_2d(convnet, 5)
convnet = fully_connected(convnet, 1024, activation='relu')
convnet = dropout(convnet, 0.4)
convnet = fully_connected(convnet,27, activation='softmax')
convnet = regression(convnet, optimizer='adam', learning_rate=LR,
loss='categorical_crossentropy', name='targets')
model = tflearn.DNN(convnet, tensorboard_dir='log')
train_data = np.load('train_data.npy')
test_data=np.load('train_data.npy')
if os.path.exists('{}.meta'.format(MODEL_N)):
model.load(MODEL_NAME)
print('model loaded')
train = train_data[:-50]
test = train_data[-50:]
X = np.array([i[0] for i in train]).reshape(-1,img_size,img_size,1)
Y = [i[1] for i in train]
test_x = np.array([i[0] for i in test]).reshape(-1, img_size, img_size, 1)
test_y = [i[1] for i in test]
model.fit({'input': X}, {'targets': Y}, n_epoch=3, validation_set=({'input':
test_x}, {'targets': test_y}),
snapshot_step=10, show_metric=True, run_id=MODEL_N)