Created
June 28, 2017 07:22
-
-
Save cemolcay/689775abee533a203edcfb73df95c60f to your computer and use it in GitHub Desktop.
NOT logical problem with Tensorflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import absolute_import, division, print_function | |
| import tensorflow as tf | |
| import tflearn | |
| import os | |
| os.environ['TF_CPP_MIN_LOG_LEVEL']='2' | |
| # Logical NOT operator | |
| X = [[0.], [1.]] | |
| Y = [[1.], [0.]] | |
| # Graph definition | |
| with tf.Graph().as_default(): | |
| g = tflearn.input_data(shape=[None, 1]) | |
| g = tflearn.fully_connected(g, 128, activation='linear') | |
| g = tflearn.fully_connected(g, 128, activation='linear') | |
| g = tflearn.fully_connected(g, 1, activation='sigmoid') | |
| g = tflearn.regression(g, optimizer='sgd', learning_rate=2., | |
| loss='mean_square') | |
| # Model training | |
| m = tflearn.DNN(g) | |
| m.fit(X, Y, n_epoch=100, snapshot_epoch=False) | |
| # Test model | |
| print("Testing NOT operator") | |
| print("NOT 0:", round(m.predict([[0.]]))) | |
| print("NOT 1:", round(m.predict([[1.]]))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment