fork download
  1. import tensorflow as tf
  2. import numpy as np
  3. x= np.array([[0,0],[0,1],[1,0],[1,1]],dtype=np.float32)
  4. y= np.array([[0],[1],[1],[0]],dtype=np.float32)
  5. model=tf.keras.Sequential([tf.keras.layers.Dense(8,input_dim=2,activation='relu'),tf.keras.layers.Dense(8,activation='relu'),tf.keras.layers.Dense(1,activation='sigmoid')])
  6. model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
  7. model.fit(x,y,epochs=1000,verbose=0)
  8. pred=model.predict(x)
  9. rounded_pred=np.round(pred)
  10. print("Predictions:",rounded_pred)
Success #stdin #stdout #stderr 3.18s 232120KB
stdin
Standard input is empty
stdout
('Predictions:', array([[0.],
       [1.],
       [1.],
       [0.]], dtype=float32))
stderr
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version.
Instructions for updating:
Colocations handled automatically by placer.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/math_ops.py:3066: to_int32 (from tensorflow.python.ops.math_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.cast instead.