def __init__(self, flags): gpu_options = tf.GPUOptions( per_process_gpu_memory_fraction=flags.gpu_memory_fraction) run_config = tf.ConfigProto(allow_soft_placement=True, gpu_options=gpu_options) run_config.gpu_options.allow_growth = True self.sess = tf.Session(config=run_config) self.flags = flags self.iter_time = 0 self._make_folders() self._init_logger() self.dataset = Dataset(self.flags.dataset, self.flags, log_path=self.log_out_dir) self.model = MRGAN(self.sess, self.flags, self.dataset.image_size, self.dataset(self.flags.is_train), log_path=self.log_out_dir) # self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) tf_utils.show_all_variables()
def __init__(self, input_shape, output_shape, lr=0.001, weight_decay=1e-4, total_iters=2e4, is_train=True, log_dir=None, name='U-Net'): self.input_shape = input_shape self.output_shape = output_shape self.conv_dims = [ 64, 64, 128, 128, 256, 256, 512, 512, 1024, 1024, 512, 512, 512, 256, 256, 256, 128, 128, 128, 64, 64, 64, 2 ] self.lr = lr self.weight_decay = weight_decay self.total_steps = total_iters self.start_decay_step = int(self.total_steps * 0.5) self.decay_steps = self.total_steps - self.start_decay_step self.is_train = is_train self.log_dir = log_dir self.name = name self.tb_lr, self.pred = None, None self.logger, self.file_handler, self.stream_handler = utils.init_logger( log_dir=self.log_dir, name=self.name, is_train=self.is_train) with tf.variable_scope(self.name): self._build_net() self._tensorboard() tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, input_img_shape=(320, 200, 1), gen_mode=1, iden_model_dir=None, session=None, lr=2e-4, total_iters=2e5, is_train=True, log_dir=None, lambda_1=100., num_class=4, num_identities=122, batch_size=1, name='pix2pix'): self.input_img_shape = input_img_shape self.output_img_shape = (*self.input_img_shape[0:2], 1) self.iris_shape = (200, 200, 1) self.gen_mode = gen_mode self.iden_model_dir = iden_model_dir self.sess = session self.is_train = is_train self.labmda_1 = lambda_1 self.num_class = num_class self.num_identities = num_identities self.gen_c = [ 64, 128, 256, 512, 512, 512, 512, 512, 512, 512, 512, 512, 256, 128, 64, self.output_img_shape[2] ] self.dis_c = [64, 128, 256, 512, 1] self.lr = lr self.total_steps = total_iters self.start_decay_step = int(self.total_steps * 0.5) self.decay_steps = self.total_steps - self.start_decay_step self.log_dir = log_dir self.batch_size = batch_size self.name = name self.tb_lr = None self.crop_pred_iris = None self.iris_value = tf.reshape(tf.constant([204.], dtype=tf.float32), shape=(1, 1, 1, 1)) self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, log_dir=self.log_dir, is_train=self.is_train, name=self.name) # Initialize the identification network if self.gen_mode == 4: self._init_iden_model() self._build_graph() # main graph # self._best_metrics_record() self._init_tensorboard() # tensorboard tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, input_shape, min_values, max_values, domain='xy', num_attribute=6, use_batchnorm=False, lr=1e-3, weight_decay=1e-4, total_iters=2e5, small_value=1e-7, is_train=True, log_dir=None, name='ResNet18'): self.input_shape = input_shape self.min_values = min_values self.max_values = max_values self.domain = domain self.small_value = small_value self.num_attribute = num_attribute self.use_batchnorm = use_batchnorm self.lr = lr self.weight_decay = weight_decay self.total_steps = total_iters self.is_train = is_train self.log_dir = log_dir self.name = name self.layers = [2, 2, 2, 2] self._ops = list() self.tb_lr = None if self.domain.lower() == 'xy': # X, Y, Ra, Rb, F, D self.weights_constant = np.array([10.0, 10.0, 1.0, 1.0, 1.0, 1.0], dtype=np.float32) elif self.domain.lower() == 'rarb': # X, Y, Ra, Rb, F, D self.weights_constant = np.array([1.0, 1.0, 10.0, 10.0, 1.0, 1.0], dtype=np.float32) else: raise NotImplementedError self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, log_dir=self.log_dir, is_train=self.is_train, name=self.name) self._build_graph() # TODO: self._best_metrics_record() self._eval_graph() self._init_tensorboard() tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, flags): run_config = tf.ConfigProto() run_config.gpu_options.allow_growth = True self.sess = tf.Session(config=run_config) self.flags = flags self.dataset = Dataset(self.flags.dataset) self.model = VanillaGAN(self.sess, self.flags, self.dataset.image_size) self._make_folders() self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) tf_utils.show_all_variables()
def __init__(self, decode_img_shape=(320, 400, 1), output_shape=(320, 200, 1), num_classes=4, data_path=(None, None), batch_size=1, lr=2e-4, total_iters=2e5, is_train=True, log_dir=None, resize_factor=0.5, lambda_1=100., name='pix2pix'): self.decode_img_shape = decode_img_shape self.input_shape = output_shape self.output_shape = output_shape self.num_classes = num_classes self.is_train = is_train self.resize_factor = resize_factor self.labmda_1 = lambda_1 self.gen_c = [ 64, 128, 256, 512, 512, 512, 512, 512, 512, 512, 512, 512, 256, 128, 64, self.output_shape[2] ] self.dis_c = [64, 128, 256, 512, 1] # self.conv_dims = [64, 128, 256, 512, 512, 512, 512, 512, 512, 512, 512, 512, 256, 128, 64, 1] self.data_path = data_path self.batch_size = batch_size self.lr = lr self.total_steps = total_iters self.start_decay_step = int(self.total_steps * 0.5) self.decay_steps = self.total_steps - self.start_decay_step self.log_dir = log_dir self.name = name self.tb_lr = None self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, logDir=self.log_dir, isTrain=self.is_train, name=self.name) self._build_graph() # main graph self._init_tensorboard() # tensorboard tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, flags): run_config = tf.ConfigProto() run_config.gpu_options.allow_growth = True self.sess = tf.Session(config=run_config) self.current_time = datetime.now().strftime("%Y%m%d-%H%M") self.flags = flags self.dataset = Dataset(self.sess, flags, self.flags.dataset) self.model = WGAN(self.sess, self.flags, self.dataset) self._make_folders() self.iter_time = 0 self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) tf_utils.show_all_variables()
def __init__(self, decodeImgShape=(320, 400, 1), outputShape=(320, 200, 1), numClasses=4, dataPath=(None, None), batchSize=1, lr=1e-3, weightDecay=1e-4, totalIters=2e5, isTrain=True, logDir=None, method=None, multi_test=True, advanced_multi_test=False, resize_factor=0.5, use_dice_loss=False, lambda_one=1.0, name='UNet'): self.decodeImgShape = decodeImgShape self.inputShape = outputShape self.outputShape = outputShape self.numClasses = numClasses self.method = method self.use_batch_norm = False self.isTrain = isTrain self.resize_factor = resize_factor self.use_dice_loss = use_dice_loss self.lambda_one = lambda_one self.multi_test = False if self.isTrain else multi_test self.advanced_multi_test = advanced_multi_test self.degree = 10 self.num_try = len(range(-self.degree, self.degree+1, 1)) # multi_tes: from -10 degree to 11 degrees self.conv_dims = self.set_conv_dims(self.method) self.dataPath = dataPath self.batchSize = batchSize self.lr = lr self.weightDecay = weightDecay self.totalSteps = totalIters self.startDecayStep = int(self.totalSteps * 0.25) self.decaySteps = int(self.totalSteps * 0.5) self.logDir = logDir self.name=name self.mIoUMetric, self.mIoUMetricUpdate = None, None self.tb_lr = None self._ops = list() self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, logDir=self.logDir, isTrain=self.isTrain, name=self.name) self._build_graph() # main graph # self._init_eval_graph() # evaluation for validation data self._init_test_graph() # for test data self._best_metrics_record() # metrics # self._init_tensorboard() # tensorboard tf_utils.show_all_variables(logger=self.logger if self.isTrain else None)
def __init__(self, flags): run_config = tf.ConfigProto() run_config.gpu_options.allow_growth = True self.sess = tf.Session(config=run_config) self.flags = flags self.iter_time = 0 self._make_folders() self._init_logger() self.dataset = Dataset(self.flags.dataset, self.flags, log_path=self.log_out_dir) self.model = MRGANPLUS(self.sess, self.flags, self.dataset.image_size, self.dataset(self.flags.is_train), log_path=self.log_out_dir) self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) tf_utils.show_all_variables()
def __init__(self, flags): run_config = tf.ConfigProto() run_config.gpu_options.allow_growth = True self.sess = tf.Session(config=run_config) self.flags = flags #ucsd self.dataset = Dataset(self.sess, flags, self.flags.dataset) self.model = AEDAE(self.sess, self.flags, self.dataset) self._make_folders() self.iter_time = 0 self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) tf_utils.show_all_variables()
def __init__(self, flags): run_config = tf.ConfigProto() run_config.gpu_options.allow_growth = True self.sess = tf.Session(config=run_config) self.flags = flags self.dataset = Dataset(self.flags.dataset, is_train=self.flags.is_train) self.model = Siamese(self.sess, self.flags, self.dataset.image_size, self.dataset) self.accuracy = self.model.accuracy self.train_accuracy = self.model.train_accuracy ############################################################### self._make_folders() self.saver = tf.train.Saver() self.sess.run(tf.global_variables_initializer()) tf_utils.show_all_variables()
def __init__(self, input_dim, output_dim=1, optimizer=None, use_dropout=True, lr=0.001, random_seed=123, is_train=True, log_dir=None, name=None): self.name = name self.is_train = is_train self.log_dir = log_dir self.cur_lr = None self.logger, self.file_handler, self.stream_handler = utils.init_logger(log_dir=self.log_dir, name=self.name, is_train=self.is_train) with tf.variable_scope(self.name): # Placeholders for inputs self.X = tf.placeholder(dtype=tf.float32, shape=[None, input_dim], name='X') self.y = tf.placeholder(dtype=tf.float32, shape=[None, output_dim], name='y') self.keep_prob = tf.placeholder(tf.float32, name='keep_prob') tf_utils.print_activations(self.X, logger=self.logger if self.is_train else None) # Placeholders for TensorBoard self.train_acc = tf.placeholder(tf.float32, name='train_acc') self.val_acc = tf.placeholder(tf.float32, name='val_acc') net = self.X if use_dropout: net = tf_utils.dropout(x=net, keep_prob=self.keep_prob, seed=random_seed, name='dropout', logger=self.logger if self.is_train else None) # Network, loss, and optimizer self.y_pred = tf_utils.linear(net, output_size=output_dim) tf_utils.print_activations(self.y_pred, logger=self.logger if self.is_train else None) self.loss = tf.math.reduce_mean(tf.nn.l2_loss(self.y_pred - self.y)) self.train_op, self.cur_lr = optimizer_fn(optimizer, lr=lr, loss=self.loss, name=self.name) # Accuracy etc self.y_pred_round = tf.math.round(x=self.y_pred, name='rounded_pred') accuracy = tf.equal(tf.cast(x=self.y_pred_round, dtype=tf.int32), tf.cast(x=self.y, dtype=tf.int32)) self.accuracy = tf.reduce_mean(tf.cast(x=accuracy, dtype=tf.float32)) * 100. self._tensorboard() tf_utils.show_all_variables(logger=self.logger if self.is_train else None)
def __init__(self, image_shape, data_path, batch_size=64, z_dim=100, lr=2e-4, beta1=0.999, total_iters=2e5, is_train=True, log_dir=None, name='dcgan'): self.image_shape = image_shape self.data_path = data_path self.batch_size = batch_size self.z_dim = z_dim self.gen_dims = [1024, 512, 256, 128, 64, 1] self.dis_dims = [64, 128, 256, 512, 1024, 1] self.lr = lr self.beta1 = beta1 self.total_steps = total_iters self.start_decay_step = int(self.total_steps * 0.5) self.decay_steps = self.total_steps - self.start_decay_step self.is_train = is_train self.log_dir = log_dir self.name = name self.g_lr_tb, self.d_lr_tb = None, None self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, log_dir=self.log_dir, is_train=self.is_train, name=self.name) self.gen_ops, self.dis_ops = [], [] self._build_net() self._initTensorBoard() tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, decode_img_shape=(320, 200, 1), num_classes=152, data_path=(None, None), batch_size=1, lr=1e-3, weight_decay=1e-4, total_iters=2e5, is_train=True, log_dir=None, resize_factor=0.5, name='ResNet18'): self.decode_img_shape = decode_img_shape self.num_classes = num_classes self.data_path = data_path self.batch_size = batch_size self.lr = lr self.weight_decay = weight_decay self.total_steps = total_iters self.is_train = is_train self.log_dir = log_dir self.resize_factor = resize_factor self.name = name self.layers = [2, 2, 2, 2] self._ops = list() self.tb_lr = None self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, logDir=self.log_dir, isTrain=self.is_train, name=self.name) self._build_graph() # self.init_tensorboard() tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, input_img_shape=(320, 200, 1), num_classes=122, lr=1e-3, weight_decay=1e-4, total_iters=2e5, is_train=True, log_dir=None, name='ResNet18'): self.input_img_shape = input_img_shape self.num_classes = num_classes self.lr = lr self.weight_decay = weight_decay self.total_steps = total_iters self.is_train = is_train self.log_dir = log_dir self.name = name self.layers = [2, 2, 2, 2] self._ops = list() self.tb_lr = None self.logger = logging.getLogger(__name__) # logger self.logger.setLevel(logging.INFO) utils.init_logger(logger=self.logger, log_dir=self.log_dir, is_train=self.is_train, name=self.name) if self.is_train: self._build_graph() self._best_metrices_record() self._init_tensorboard() else: self._build_test_graph() self._eval_graph() tf_utils.show_all_variables( logger=self.logger if self.is_train else None)
def __init__(self, input_dim, output_dim=[1000, 1000, 10], optimizer=None, use_dropout=True, lr=0.001, weight_decay=1e-4, random_seed=123, is_train=True, log_dir=None, name=None): self.name = name self.is_train = is_train self.log_dir = log_dir self.cur_lr = None self.logger, self.file_handler, self.stream_handler = utils.init_logger(log_dir=self.log_dir, name=self.name, is_train=self.is_train) with tf.variable_scope(self.name): # Placeholders for inputs self.X = tf.placeholder(dtype=tf.float32, shape=[None, input_dim], name='X') tf_utils.print_activations(self.X, logger=self.logger if self.is_train else None) self.y = tf.placeholder(dtype=tf.float32, shape=[None, output_dim[-1]], name='y') self.y_cls = tf.math.argmax(input=self.y, axis=1) self.keep_prob = tf.placeholder(tf.float32, name='keep_prob') # Placeholders for TensorBoard self.train_acc = tf.placeholder(tf.float32, name='train_acc') self.val_acc = tf.placeholder(tf.float32, name='val_acc') net = self.X for idx in range(len(output_dim) - 1): net = tf_utils.linear(x=net, output_size=output_dim[idx], name='fc'+str(idx), logger=self.logger if self.is_train else None) if use_dropout: net = tf_utils.dropout(x=net, keep_prob=self.keep_prob, seed=random_seed, name='dropout'+str(idx), logger=self.logger if self.is_train else None) net = tf_utils.relu(x=net, name='relu'+str(idx), logger=self.logger if self.is_train else None) # Last predict layer self.y_pred = tf_utils.linear(net, output_size=output_dim[-1], name='last_fc') tf_utils.print_activations(self.y_pred, logger=self.logger if self.is_train else None) # Loss = data loss + regularization term self.data_loss = tf.math.reduce_mean( tf.nn.sigmoid_cross_entropy_with_logits(logits=self.y_pred, labels=self.y)) self.reg_term = weight_decay * tf.reduce_sum( [tf.nn.l2_loss(weight) for weight in tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)]) self.loss = self.data_loss + self.reg_term # Optimizer self.train_op, self.cur_lr = optimizer_fn(optimizer, lr=lr, loss=self.loss, name=self.name) # Accuracy etc self.y_pred_cls = tf.math.argmax(input=self.y_pred, axis=1) correct_prediction = tf.math.equal(self.y_pred_cls, self.y_cls) self.accuracy = tf.reduce_mean(tf.cast(correct_prediction, dtype=tf.float32)) * 100. self._tensorboard() tf_utils.show_all_variables(logger=self.logger if self.is_train else None)