logo
Loading...

使用Xception和Resnet 50出現“ValueError: Error when checking target: expected dense_2 to have 4 dimensions, but got array with shape (50000, 10)” - Cupoy

我用Xception和Resnet 50各試跑了一遍,最後model都會出現“ValueError:...

cvdl-1,cvdl-1-d21

使用Xception和Resnet 50出現“ValueError: Error when checking target: expected dense_2 to have 4 dimensions, but got array with shape (50000, 10)”

2019/12/24 上午 06:28
電腦視覺深度學習討論版
張凱維
觀看數:7
回答數:2
收藏數:1
cvdl-1
cvdl-1-d21

我用Xception和Resnet 50各試跑了一遍,最後model都會出現

“ValueError: Error when checking target: expected dense_2 to have 4 dimensions, but got array with shape (50000, 10)”

我知道y_train出來的是(50000,10), x_train是(50000, 32, 32, 3), 這兩個出來的形狀不一樣,請問要如何調整呢?

回答列表

  • 2019/12/24 上午 08:55
    楊哲寧
    贊同數:0
    不贊同數:0
    留言數:4

    您好,請確認一下fit的時候是不是放入正確資訊:

    model.fit(x_train,y_train,batch_size=32,epochs=100)

    再來從報錯訊息來看,dense_2 layer好像有點問題:

    理論上dense_2 layers dimention 應該是二維沒錯:dense_2 (Dense)                 (None, 10)  

    但你的模型期望他是4維,可以確認一下有沒有搭錯的地方。

    這是解答的dense_2 layer:

    predictions = Dense(output_dim=10,activation='softmax')(x)          

  • 2019/12/24 上午 09:53
    Jeffrey
    贊同數:1
    不贊同數:0
    留言數:0