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

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

ValueError:檢查輸入時(shí)出錯(cuò):預(yù)期 conv2d_1_input 有 4 個(gè)維度

ValueError:檢查輸入時(shí)出錯(cuò):預(yù)期 conv2d_1_input 有 4 個(gè)維度

蝴蝶刀刀 2023-05-09 14:46:47
我正在我的數(shù)據(jù)集上構(gòu)建一個(gè) 2d 卷積網(wǎng)絡(luò)。我在測(cè)試集上運(yùn)行它,代碼如下:#reproducible codefrom keras.models import Sequentialfrom keras.layers import Dense, Dropout, Flattenfrom keras.utils import np_utilsfrom keras import optimizersfrom sklearn.metrics import confusion_matriximport numpy as npimport timefrom keras.layers.convolutional import Conv2Ddata = np.random.rand(1000,22)data.shapetrain_X = data[0:data.shape[0],0:12]train_X.shapetrain_y = data[0:data.shape[0],12:data.shape[1]]train_y.shapetrain_X = train_X.reshape((train_X.shape[0], train_X.shape[1], 1))train_X.shapeneurons = 10model = Sequential()model.add(Conv2D(filters=64,input_shape=train_X.shape, activation='relu',kernel_size = 3))model.add(Flatten())model.add(Dense(neurons,activation='relu')) # first hidden layermodel.add(Dense(neurons, activation='relu')) # second hidden layermodel.add(Dense(neurons, activation='relu')) # third hidden layermodel.add(Dense(10, activation='softmax'))sgd = optimizers.SGD(lr=0.05, decay=1e-6, momentum=0.95, nesterov=True)model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])model.summary()model.fit(train_X,train_y, validation_split=0.2, epochs=10, batch_size=100, verbose=0)model.summary()
查看完整描述

2 回答

?
心有法竹

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

你沒(méi)有理由使用 2D 卷積層,因?yàn)槟愕臄?shù)據(jù)是 3D 的。您正在尋找的是 Conv1D。另外,不要n_samples在input_shape.


from tensorflow.keras.models import Sequential

from tensorflow.keras.layers import Dense, Conv1D, Flatten

from tensorflow.keras import optimizers

import numpy as np


data = np.random.rand(1000,22)


train_X = data[0:data.shape[0],0:12]

train_X = train_X.reshape((train_X.shape[0], train_X.shape[1], 1))


train_y = data[0:data.shape[0],12:data.shape[1]]


neurons = 10

model = Sequential()

model.add(Conv1D(filters=64,input_shape=train_X.shape[1:], 

    activation='relu',kernel_size = 3))

model.add(Flatten())

model.add(Dense(neurons,activation='relu')) # first hidden layer

model.add(Dense(10, activation='softmax'))

sgd = optimizers.SGD(lr=0.05, decay=1e-6, momentum=0.95, nesterov=True)

model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])

history = model.fit(train_X, train_y, validation_split=0.2, epochs=1, batch_size=100)

Train on 800 samples, validate on 200 samples

100/800 [==>...........................] - ETA: 2s - loss: 11.4786 - acc: 0.0800

800/800 [==============================] - 0s 547us/sample - loss: 55.3883 - acc: 0.1000 



查看完整回答
反對(duì) 回復(fù) 2023-05-09
?
HUX布斯

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

你需要train_X有第四維度。就像錯(cuò)誤信息所說(shuō)的那樣。

train_X = train_X.reshape(train_X.shape[0], train_X.shape[1], 1, 1)


查看完整回答
反對(duì) 回復(fù) 2023-05-09
  • 2 回答
  • 0 關(guān)注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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