Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. here is my custom callback to show some images
  2.  
  3. class DisplaySamples(tf.keras.callbacks.Callback):
  4. def __init__(self, log_dir='./logs/tmp/', get_samples=None):
  5. super(DisplaySamples, self).__init__()
  6. self.step = 0
  7. self.samples = get_samples
  8. self.writer = tf.summary.FileWriter(log_dir)
  9.  
  10. def on_batch_end(self, batch, logs=None):
  11. logs = logs or {}
  12. self.step += 1
  13. if self.step % 2 == 0:
  14. # images using TensorBorad;
  15. summary_str = []
  16. for i in range(len(self.samples)):
  17. image = self.samples[i]
  18. keypoints = np.squeeze(self.model.predict(image)[0], axis=0)
  19.  
  20. summary_str.append(tf.Summary.Value(tag='plot/image/{}'.format(i),
  21. image=tf.summary.image("image", image)))
  22. summary_str.append(tf.Summary.Value(tag='plot/keypts/{}'.format(i),
  23. image=tf.summary.image("keyps", keypoints)))
  24.  
  25. self.writer.add_summary(tf.Summary(value=summary_str), global_step=self.step)
  26.  
  27.  
  28. def read_images():
  29. """
  30.  
  31. Returns
  32. -------
  33.  
  34. """
  35.  
  36. image_list = []
  37. for filename in glob.glob('../samples/*.jpg'):
  38. im = cv2.imread(filename)
  39. im = cv2.resize(im, (512, 512, 3))
  40. im = np.reshape(im, (1, 512, 512, 3))
  41. image_list.append(im)
  42. return image_list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement