fork download
  1. # Import python libraries required in this example:
  2. from keras.models import Sequential
  3. from keras.layers import Dense, Activation
  4. import numpy as np
  5. # Use numpy arrays to store inputs (x) and outputs (y):
  6. x = np.array([[0,0], [0,1], [1,0], [1,1]])
  7. y = np.array([[0], [1], [1], [0]])
  8. # Define the network model and its arguments.
  9. # Set the number of neurons/nodes for each layer:
  10. model = Sequential()
  11. model.add(Dense(2, input_shape=(2,)))
  12. model.add(Activation('sigmoid'))
  13. model.add(Dense(1))
  14. model.add(Activation('sigmoid'))
  15. # Compile the model and calculate its accuracy:
  16. model.compile(loss='mean_squared_error', optimizer='sgd', metrics=['accuracy'])
  17. # Print a summary of the Keras model:
  18. model.summary()
Success #stdin #stdout 2.8s 315892KB
stdin
Standard input is empty
stdout
Model: "sequential"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 dense (Dense)               (None, 2)                 6         
                                                                 
 activation (Activation)     (None, 2)                 0         
                                                                 
 dense_1 (Dense)             (None, 1)                 3         
                                                                 
 activation_1 (Activation)   (None, 1)                 0         
                                                                 
=================================================================
Total params: 9
Trainable params: 9
Non-trainable params: 0
_________________________________________________________________