import tensorflow as tf import numpy as np # logging import logging from segmentpy.tf114 import log logger = log.setup_custom_logger(__name__) logger.setLevel(logging.DEBUG) def init_weights(shape, name='weights', reuse=False, uniform=True): """ input: ------- shape: (list) shape of the weight matrix e.g. [5, 5, 1, 32] name: (string) name of the node return: ------- tensorflow variable initialized by xavier method """ with tf.variable_scope(name, reuse=reuse): return tf.get_variable('w', shape=shape, initializer=tf.initializers.glorot_uniform() if uniform else tf.initializers.glorot_normal()) def init_bias(shape, name='bias', reuse=False, uniform=True): """ input: -------
from tensorboard.backend.event_processing import event_accumulator import pandas as pd import matplotlib.pyplot as plt import numpy as np from PIL import Image import re import os from segmentpy.tf114.util import check_N_mkdir import logging from segmentpy.tf114 import log logger = log.setup_custom_logger('root') logger.setLevel(logging.DEBUG) def gradient_extractor(event_dir: str, write_rlt=True): if not event_dir.endswith('train/'): _dir = os.path.join(event_dir, 'train/') else: _dir = event_dir accumulator = event_accumulator.EventAccumulator(_dir, size_guidance={ event_accumulator.SCALARS: 0, event_accumulator.HISTOGRAMS: 0, }) accumulator.Reload() tags = accumulator.Tags() l_grad_tag = [] for param_name in tags['histograms']: