簡體   English   中英

如何設置Keras模型正確?

[英]How setup Keras model correctly?

我正在努力在Keras建造模型。 我想傳遞我的所有功能, input=10output=3 但是,一旦我運行下面的代碼

def build_model(input_dim, output_classes):
    print 'Creating model ...', time.time() - start, mprof.memory_usage()
    model = Sequential()
    model.add(Dense(input_dim=input_dim, output_dim=8, activation=relu))
    model.add(Dropout(0.5))
    model.add(Dense(input_dim=8, output_dim=6, activation=relu))
    model.add(Dropout(0.5))
    model.add(Dense(output_dim=output_classes, activation='softmax'))
    model.compile(loss='categorical_crossentropy', optimizer='adadelta')

我收到一個錯誤:

ValueError: ('shapes (35,9) and (10,8) not aligned: 9 (dim 1) != 10 (dim 0)', (35L, 9L), (10L, 8L))
Apply node that caused the error: Dot22(<TensorType(float32, matrix)>, <TensorType(float32, matrix)>)
Inputs types: [TensorType(float32, matrix), TensorType(float32, matrix)]
Inputs shapes: [(35L, 9L), (10L, 8L)]
Inputs strides: [(36L, 4L), (32L, 4L)]
Inputs values: ['not shown', 'not shown']

在我的情況下,模型初始化的正確參數是什么?

我復制了你的代碼並執行它沒有錯誤。(只是評論了打印,因為我正在使用Python 3)

我設置input_dim = 10和output_classes = 3,沒有問題。

可能是您正在為output_classes傳遞非整數值,如果是這種情況,則可能會出現一系列錯誤,具體取決於傳遞的對象類型。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM