Operating environment
GeForce GTX 1070 (8GB)
ASRock Z170M Pro4S [Intel Z170chipset]
Ubuntu 14.04 LTS desktop amd64
TensorFlow v0.11
cuDNN v5.1 for Linux
CUDA v8.0
Python 2.7.6
IPython 5.1.0 -- An enhanced Interactive Python.
I wanted to stop the python code in the middle. It was okay to execute it sequentially using Jupyter, but I investigated how to stop it with script.
Reference http://stackoverflow.com/questions/179369/how-do-i-abort-the-execution-of-a-python-script
The following is a script for Deep Learning called TensorFlow.
I wanted to finish after print (input_ph.get_shape ())
.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import tensorflow as tf
import tensorflow.contrib.slim as slim
#Create a Queue with filename
filename_queue = tf.train.string_input_producer(["input.csv"])
#CSV parse
reader = tf.TextLineReader()
key, value = reader.read(filename_queue)
input1, output = tf.decode_csv(value, record_defaults=[[0.], [0.]])
inputs = tf.pack([input1])
output = tf.pack([output])
batch_size=4 # [4]
inputs_batch, output_batch = tf.train.shuffle_batch([inputs, output], batch_size, capacity=40, min_after_dequeue=batch_size)
input_ph = tf.placeholder("float", [None,1])
output_ph = tf.placeholder("float",[None,1])
#if 1 // debug
print(input_ph.get_shape())
sys.exit()
#endif
##Graph generation of NN
hiddens = slim.stack(input_ph, slim.fully_connected, [1,7,7,7],
activation_fn=tf.nn.sigmoid, scope="hidden")
prediction = slim.fully_connected(hiddens, 1, activation_fn=tf.nn.sigmoid, scope="output")
loss = tf.contrib.losses.mean_squared_error(prediction, output_ph)
#train_op = slim.learning.create_train_op(loss, tf.train.AdamOptimizer(0.01))
train_op = slim.learning.create_train_op(loss, tf.train.AdamOptimizer(0.001))
def feed_dict(inputs, output):
return {input_ph: inputs.eval(), output_ph: output.eval()}
init_op = tf.initialize_all_variables()
with tf.Session() as sess:
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(sess=sess, coord=coord)
try:
sess.run(init_op)
for i in range(30000): #[10000]
_, t_loss = sess.run([train_op, loss], feed_dict=feed_dict(inputs_batch, output_batch))
if (i+1) % 100 == 0:
print("%d,%f" % (i+1, t_loss))
# print("%d,%f,#step, loss" % (i+1, t_loss))
finally:
coord.request_stop()
coord.join(threads)
result
$ python linreg2_feeddict.py
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally
(?, 1)
Recommended Posts