Вот код для отслеживания потерь для одного образца:
import tensorflow as tf
import numpy as np
import keras
x = tf.Variable(initial_value=np.ndarray(shape=(10, 10), dtype=np.float32)) # your sample input
y =np.random.randint(0, 9, size=(10, )) # your sample label
y_labels = keras.utils.to_categorical(y, 10)
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(labels=x, logits=y_labels)) # loss operation for that particular sample
tf.summary.scalar('loss', loss) #logging loss op in summary
print('loss op', loss)
merge = tf.summary.merge_all()
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
loss_val, merge_val = sess.run([loss, merge]) # no need to pass any feed_dict, loss value calculated is specific to that sample
print('loss val', loss_val)
# merge val could be put in to tf summary writer