张量板步骤限制为40?

时间:2018-12-28 07:33:32

标签: tensorflow keras tensorboard

我正在使用keras 2.24 + tensorflow(1.12.0)评估我的学习实验。我有一个自keras.callbacks.TensorBoard继承的自定义Tensorboard类,可将摘要图像添加到tensorboard。但是,当我已经训练到90个纪元时,看来最多只能看到40个纪元?这是Tensorboard本身的限制吗(我是否必须更改某些设置才能查看后面的历元数据?)还是我的Tensorboard代码有问题?

enter image description here enter image description here

class MaskImageTensorBoard(TensorBoard):
    def __init__(self, target_size, image_every_x_epochs, output_name, log_dir, data_vis_dir, **kwargs):
        self.save_freq = image_every_x_epochs
        self.output_name = output_name
        self.data_vis_dir = data_vis_dir
        self.target_size = target_size 
        super(MaskImageTensorBoard, self).__init__(log_dir, **kwargs)

    def _load_images(self, image_list):
        image_arr = []
        for f in image_list:
            img = Image.open(f).resize((self.target_size[1], self.target_size[0]), Image.ANTIALIAS)
            image_arr.append(np.array(img))
        return np.array(image_arr)


    def on_epoch_end(self, epoch, logs=None):
        limit = 5
        threshold = 0.5
        color = [0, 255, 0]

        if epoch % self.save_freq == 0:
            image_list = [os.path.join(self.data_vis_dir, f) for f in random.sample(os.listdir(self.data_vis_dir), limit )]
            images = self._load_images(image_list)
            images2 = images / 255.
            predictions = K.get_session().run(self.model.output, feed_dict = {self.model.input : images2})

            predictions[predictions >= threshold] = 1
            predictions[predictions < threshold] = 0 #shape [5, h, w, 1]
            mask = np.apply_along_axis(lambda channel: np.concatenate([channel, channel, channel], axis=-1), 3, predictions)
            mask *= color

            masked_img = 0.5 *  images + 0.5 * mask
            masked_tensor = tf.convert_to_tensor(masked_img)
            summ = tf.summary.image("Validation epoch {}".format(epoch), masked_tensor)
            s = self.sess.run(summ)
            self.writer.add_summary(s)

        super(MaskImageTensorBoard, self).on_epoch_end(epoch, logs)

0 个答案:

没有答案