第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

如何在 CNN Keras 中修復(fù)密集層的輸入大???

我嘗試使用 keras 構(gòu)建人臉識別模型。我有帶有主題名稱和特征的圖像(深度學(xué)習(xí)用的不多,我知道,但我很快就會得到更多)但是當(dāng)我嘗試擬合我的數(shù)據(jù)時(shí),我收到了這個(gè)錯(cuò)誤:ValueError:檢查目標(biāo)時(shí)出錯(cuò):預(yù)期dense_2有2維,但得到的數(shù)組形狀為(3, 243, 320, 3)我試圖將損失函數(shù)從 更改sparse_categorical_crossentropy為categorical_crossentropy。使用 keras 的“to_categorical”功能進(jìn)行單熱編碼標(biāo)簽但它不會工作這是我如何用圖像和標(biāo)簽填充我的列表###### fill with imagesfor i in range(0,num_classes):k=0for j in range(len(features)):    k+=1    if(i < 10):        sub = "subject0"+str(i)+"."+features[j]+".png"    else:        sub = "subject"+str(i)+"."+features[j]+".png"    imgfile = Image.open(sub)    img = np.array(imgfile)    #print(img.shape)    #print(type(img))    if(k != 3):        train.append(img)        train_labels.append(i)    else :        test.append(img)        test_labels.append(i)########## train train = np.asarray(train)train_labels = np.asarray(train_labels)########## test test = np.asarray(test)test_labels = np.asarray(test_labels)我的班級現(xiàn)在是3個(gè)?。?個(gè)班是一個(gè)科目)以下是如何重塑和規(guī)范化圖像。# Reshape  243x320 pixels, 1 channel (B/W)train = train.reshape(train.shape[0], img_rows, img_cols, 1)# Reshape  243x320 pixels, 1 channel (B/W)test = test.reshape(test.shape[0], img_rows, img_cols, 1)# Normalize pixel values: [0-255] --> [0.0-1.0]train, test = train / 255.0, test / 255.0# One-hot encode labelstest = to_categorical(test, num_classes)test_labels = to_categorical(test_labels, num_classes)我建立了一個(gè)簡單的 CNN 模型######### build cnn modelsmodel = Sequential()model.add(Conv2D(32, kernel_size=(5, 5), padding='same', activation='relu', input_shape=(img_rows,img_cols,1)))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Conv2D(32, (3, 3), padding='same', activation='relu'))model.add(MaxPooling2D(pool_size=(2, 2)))model.add(Flatten())model.add(Dense(128, activation='relu'))model.add(Dense(num_classes, activation='softmax'))model.compile(    optimizer='adam',    loss='categorical_crossentropy',    metrics=['accuracy'])我認(rèn)為問題是我的模型中的一個(gè)層的輸出。我試圖移動flatten,但沒有奏效。謝謝你的幫助 !
查看完整描述

1 回答

?
慕森王

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊

test = to_categorical(test, num_classes)應(yīng)該是,train_labels = ...而您的model.fit(...)電話應(yīng)該是model.fit(train, train_labels)。

這些是我能找到的最顯著的錯(cuò)誤。


查看完整回答
反對 回復(fù) 2021-12-26
  • 1 回答
  • 0 關(guān)注
  • 138 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號