def tets_fit(): # forget to compile inp1 = Input(1, batch_size=1) d1 = Dense(1) model = Model(inp1, d1) with pytest.raises(KError): model.fit([[1]], [[1]])
def test_fit_evaluate_predict_spec(): x = np.array([[1], [1]]) y = np.array([[1], [1]]) input1 = Input(1, name='input1') input2 = Input(1, name='input2') output1 = Dense(1, name='output1')(input1) output2 = Dense(1, name='output2')(input2) model0 = Model(input1, output1) model1 = Model([input1, input2], [output1, output2]) model2 = Model([input1, input2], [output1, output2]) model0.compile('sgd', 'mse', metrics=['acc']) model1.compile('sgd', loss=['mse', 'mse'], metrics=['acc']) model2.compile('sgd', loss={ 'output1': 'mse', 'output2': 'mse' }, metrics={ 'output1': 'acc', 'output2': 'acc' }) model0.predict([1, 1]) model0.evaluate([1, 1], [1, 1]) model0.fit([1, 1], [1, 1], nb_epoch=1) model1.predict([x, x]) model1.evaluate([x, x], [y, y]) model1.fit([x, x], [y, y], nb_epoch=1) model2.predict({'input1': x, 'input2': x}) model2.evaluate({'input1': x, 'input2': x}, {'output1': y, 'output2': y}) model2.fit({ 'input1': x, 'input2': x }, { 'output1': y, 'output2': y }, nb_epoch=1)
def tets_fit(): # forget to compile with pytest.raises(KError): model = Model(inp1, d1) model.fit([[1]], [[1]])
row, col, pixel = X_train.shape[1:] # 4D input. x = Input(shape=(row, col, pixel)) # Encodes a row of pixels using TimeDistributed Wrapper. encoded_rows = TimeDistributed(LSTM(output_dim=row_hidden))(x) # Encodes columns of encoded rows. encoded_columns = LSTM(col_hidden)(encoded_rows) # Final predictions and model. prediction = Dense(nb_classes, activation='softmax')(encoded_columns) model = Model(inputs=x, outputs=prediction) model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy']) # Training. model.fit(X_train, y_train, batch_size=batch_size, nb_epoch=nb_epochs, verbose=1, validation_data=(X_test, y_test)) # Evaluation. scores = model.evaluate(X_test, y_test) print('Test loss:', scores[0]) print('Test accuracy:', scores[1])