1. Tensorboard
How to use Tensorboard
tbCallback = keras.callbacks.TensorBoard(log_dir='./logs', histogram_freq=0, write_graph=True,
write_images=True)
tensorboard --logdir=/home/dong/PycharmProjects/CIFAR10-vgg/logs
exist in the current folder "./test_data/tiger.jpeg"
How to use tf.summary to view the training progress
Link: https://www.tensorflow.org/programmers_guide/summaries_and_tensorboard
and https://blog.csdn.net/u012436149/article/details/53184847
Firstly, adding code
e.g. tf.summary.scalar('total_loss', total_loss)
or tf.summary.scalar('Stream_acc', acc_op)
and then meger all the summaries:
merged_summary = tf.summary.merge_all()
train_writer = tf.summary.FileWriter(summaries_dir + '/train',
sess.graph)
test_writer = tf.summary.FileWriter(summaries_dir + '/test')
Where summaries_dir is a folder to store training and testing logs.
After that, you should write the training and testing summaries
e.g.
_,summary = sess.run([train_op,merged_summary], feed_dict)
train_writer.add_summary(summary, i)
2.Tensorflow
pip install tensorflow-gpu --upgrade
3. tf.squeeze()
Given a tensor input
, this operation returns a tensor of the same type with all dimensions of size 1 removed. If you don't want to remove all size 1 dimensions, you can remove specific size 1 dimensions by specifying
axis
.
For example:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t)) # [2, 3]
Or, to remove specific size 1 dimensions:
# 't' is a tensor of shape [1, 2, 1, 3, 1, 1]
tf.shape(tf.squeeze(t, [2, 4])) # [1, 2, 3, 1]
4. tf.train.Saver and Restore
- Restoring:
loading graphtf.train.import_meta_graph('ckpt/inception-200.meta')
loading weights:
saver = tf.train.Saver()
saver.restore(sess, "ckpt/inception-200")
5. Use placeholder with default in the following way:
If we have the value of intermediate result (z in the following example), we can avoid to start from the beginning(give the value of x to computer intermediate result z);
x = tf.placeholder(tf.float32, (), name='x')
# z is a placeholder with default value
z = tf.placeholder_with_default(x+tf.constant(5.0), (), name='z')
y = tf.mul(z, tf.constant(0.5))
with tf.Session() as sess:
# and feed the z in
print(sess.run(y, feed_dict={z: 5})