aboutsummaryrefslogtreecommitdiffstats
path: root/dlstuff/one.py
diff options
context:
space:
mode:
authorbloodstalker <thabogre@gmail.com>2018-10-17 17:45:51 +0000
committerbloodstalker <thabogre@gmail.com>2018-10-17 17:45:51 +0000
commita7f7a083fc3e6eb7fc1c689c3dbf0e758670f6a4 (patch)
tree13879399c3ddec4743f8f6a884b0b67c4b4f0304 /dlstuff/one.py
parentupdate (diff)
downloadseer-a7f7a083fc3e6eb7fc1c689c3dbf0e758670f6a4.tar.gz
seer-a7f7a083fc3e6eb7fc1c689c3dbf0e758670f6a4.zip
update
Diffstat (limited to 'dlstuff/one.py')
-rwxr-xr-xdlstuff/one.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/dlstuff/one.py b/dlstuff/one.py
new file mode 100755
index 0000000..4012b89
--- /dev/null
+++ b/dlstuff/one.py
@@ -0,0 +1,78 @@
+#!/usr/bin/python3
+# _*_ coding=utf-8 _*_
+
+import argparse
+import code
+import readline
+import signal
+import sys
+from keras.datasets import mnist
+from keras import models
+from keras import layers
+from keras.utils import to_categorical
+import matplotlib.pyplot as plt
+
+def SigHandler_SIGINT(signum, frame):
+ print()
+ sys.exit(0)
+
+class Argparser(object):
+ def __init__(self):
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--string", type=str, help="string")
+ parser.add_argument("--bool", action="store_true", help="bool", default=False)
+ parser.add_argument("--dbg", action="store_true", help="debug", default=False)
+ self.args = parser.parse_args()
+
+# write code here
+def premain(argparser):
+ signal.signal(signal.SIGINT, SigHandler_SIGINT)
+ #here
+ (train_images, train_labels), (test_images, test_labels) = mnist.load_data()
+ '''
+ print(train_images.shape)
+ print(len(train_labels))
+ print(train_labels)
+ print(test_images.shape)
+ print(len(test_labels))
+ print(test_labels)
+ digit = train_images[4]
+ plt.imshow(digit, cmap=plt.cm.binary)
+ plt.show()
+ '''
+
+ network = models.Sequential()
+ network.add(layers.Dense(512, activation="relu", input_shape=(28*28,)))
+ network.add(layers.Dense(10, activation="softmax"))
+ #network.compile(optimizer="rmsprop", loss="categorical_crossentropy", metrics=["accuracy"])
+ network.compile(optimizer="rmsprop", loss="mse", metrics=["accuracy"])
+
+ train_images = train_images.reshape((60000, 28 * 28))
+ train_images = train_images.astype("float32") / 255
+ test_images = test_images.reshape((10000, 28 * 28))
+ test_images = test_images.astype("float32") / 255
+ train_labels = to_categorical(train_labels)
+ test_labels = to_categorical(test_labels)
+
+ network.fit(train_images, train_labels, epochs=5, batch_size=128)
+
+ test_loss, test_acc = network.evaluate(test_images, test_labels)
+ print("test_acc:", test_acc)
+
+def main():
+ argparser = Argparser()
+ if argparser.args.dbg:
+ try:
+ premain(argparser)
+ except Exception as e:
+ print(e.__doc__)
+ if e.message: print(e.message)
+ variables = globals().copy()
+ variables.update(locals())
+ shell = code.InteractiveConsole(variables)
+ shell.interact(banner="DEBUG REPL")
+ else:
+ premain(argparser)
+
+if __name__ == "__main__":
+ main()