In [ ]:
In [ ]:
https://www.tensorflow.org/tutorials/using_gpu
Limit memory:
- config.gpu_options.allow_growth = True
- config.gpu_options.per_process_gpu_memory_fraction = 0.01
Uwaga: GPU resources not released when session is closed https://github.com/tensorflow/tensorflow/issues/1727
Trzeba zakończyć proces pythona (w jupyter: kernel restart)
Aby sprawdzić zasoby GPU: nvidia-smi
In [9]:
!nvidia-smi
In [6]:
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
#config.gpu_options.per_process_gpu_memory_fraction = 0.01
In [8]:
sess = tf.InteractiveSession(config=config)
x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])
x.initializer.run()
sub = tf.subtract(x, a)
print(sub.eval())
sess.close()
In [ ]:
In [10]:
sess = tf.Session(config=config)
x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])
sess.run(x.initializer) # różnica 1
sub = tf.subtract(x, a)
print(sess.run(sub)) # różnica 2
sess.close()
In [11]:
with tf.Session(config=config) as sess:
with tf.device("/gpu:0"):
x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])
x.initializer.run()
sub = tf.subtract(x, a)
print(sub.eval())
In [12]:
with tf.Session(config=config) as sess:
with tf.device("/gpu:0"):
x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0])
sess.run(x.initializer) # różnica 1
sub = tf.subtract(x, a)
print(sess.run(sub)) # różnica 2
In [13]:
c = tf.constant(4.0)
c.graph is tf.get_default_graph()
Out[13]:
In [18]:
with tf.Session(config=config) as sess:
with tf.device("/gpu:0"):
x = tf.Variable([1.0, 2.0])
a = tf.constant([3.0, 3.0],name="A")
sub = tf.subtract(x, a)
sess.run(x.initializer)
writer = tf.summary.FileWriter("/DATA/marcin.kostur/tf001",sess.graph)
writer.close()
sub = tf.subtract(x, a)
print(sess.run(sub))
https://www.tensorflow.org/get_started/summaries_and_tensorboard
Uwaga - należy wybrać unikalny port: --port 3456
In [19]:
!ls -l /DATA/marcin.kostur/tf001/*
In [20]:
!tensorboard --logdir=/DATA/marcin.kostur/tf001/ --port 4001
In [ ]:
tf.
In [ ]:
In [ ]:
In [21]:
import tensorflow as tf
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
tf.reset_default_graph()
In [22]:
sess = tf.InteractiveSession(config=config)
In [23]:
a = tf.linspace(0.,11.,23)
b = a*a
print(b.eval())
In [24]:
c = tf.constant([1,2,3.])
In [25]:
type(a)
Out[25]:
In [28]:
x = tf.Variable([1,2,3.])
In [29]:
type(x)
Out[29]:
In [34]:
x.initializer.run()
x.eval()
Out[34]:
In [35]:
(a[:3]*x)
Out[35]:
In [36]:
(a[:3]*x).eval()
Out[36]:
In [37]:
y = tf.placeholder(tf.float32)
In [9]:
d = y*a
In [10]:
d.eval(feed_dict={y:1.23})
Out[10]:
In [38]:
n = tf.random_normal([2,2])
In [41]:
n.eval()
Out[41]:
In [24]:
n = tf.random_uniform([12])
In [25]:
n.eval()
Out[25]:
In [49]:
sess.close()
In [ ]:
In [ ]:
In [ ]: