def main(flags): # make network # define place holder X = tf.placeholder( tf.float32, shape=[None, flags.input_size[0], flags.input_size[1], 3], name='X') z = tf.placeholder(tf.float32, shape=[None, flags.z_dim], name='z') mode = tf.placeholder(tf.bool, name='mode') model = uabMakeNetwork_BiGAN.BiGAN({ 'X': X, 'Z': z }, trainable=mode, model_name=flags.model_name, input_size=flags.input_size, batch_size=flags.batch_size, learn_rate=flags.learning_rate, decay_step=flags.decay_step, decay_rate=flags.decay_rate, epochs=flags.epochs, start_filter_num=flags.sfn, z_dim=flags.z_dim, lr_mult=flags.lr_mult, depth=4) model.create_graph('X', class_num=flags.num_classes, reduce_dim=False) # prepare data dataReader_train = ImageLabelReader_celeb( flags.data_dir, flags.batch_size, (flags.input_size[0], flags.input_size[1]), True) dataReader_valid = ImageLabelReader_celeb( flags.data_dir, flags.batch_size, (flags.input_size[0], flags.input_size[1]), False) img_mean = np.zeros(3) # train start_time = time.time() model.train_config('X', 'Z', flags.n_train, flags.n_valid, flags.input_size, uabRepoPaths.modelPath, par_dir='BiGAN_CELEB') model.run( train_reader=dataReader_train, valid_reader=dataReader_valid, pretrained_model_dir=None, isTrain=True, img_mean=img_mean, verb_step=100, # print a message every 100 step(sample) save_epoch=50, # save the model every 5 epochs gpu=GPU, tile_size=flags.tile_size, patch_size=flags.input_size) duration = time.time() - start_time print('duration {:.2f} hours'.format(duration / 60 / 60))
img_dir, task_dir = sis_utils.get_task_img_folder() os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID' os.environ['CUDA_VISIBLE_DEVICES'] = str(gpu) # make the model # define place holder X = tf.placeholder(tf.float32, shape=[None, input_size[0], input_size[1], 3], name='X') z = tf.placeholder(tf.float32, shape=[None, latent_num], name='z') mode = tf.placeholder(tf.bool, name='mode') model = uabMakeNetwork_BiGAN.BiGAN({ 'X': X, 'Z': z }, trainable=mode, input_size=input_size, batch_size=1, start_filter_num=64, z_dim=latent_num, depth=4) # create graph model.create_graph('X', class_num=3) model_dir = r'/hdd6/Models/BiGAN_INRIA_RESIZE/BiGAN_inria_z100_lrm1_resize_PS(128, 128)_BS64_EP50_LR0.0001_DS25_DR0.1_SFN64' blCol = uab_collectionFunctions.uabCollection('inria') opDetObj = bPreproc.uabOperTileDivide( 255) # inria GT has value 0 and 255, we map it back to 0 and 1 # [3] is the channel id of GT rescObj = uabPreprocClasses.uabPreprocMultChanOp([], 'GT_Divide.tif', 'Map GT to (0, 1)', [3], opDetObj)
def main(flags): # make network # define place holder X = tf.placeholder(tf.float32, shape=[None, flags.input_size[0], flags.input_size[1], 3], name='X') z = tf.placeholder(tf.float32, shape=[None, flags.z_dim], name='z') mode = tf.placeholder(tf.bool, name='mode') model = uabMakeNetwork_BiGAN.BiGAN({'X': X, 'Z': z}, trainable=mode, model_name=flags.model_name, input_size=flags.input_size, batch_size=flags.batch_size, learn_rate=flags.learning_rate, decay_step=flags.decay_step, decay_rate=flags.decay_rate, epochs=flags.epochs, start_filter_num=flags.sfn, z_dim=flags.z_dim, lr_mult=flags.lr_mult) model.create_graph('X', class_num=flags.num_classes, reduce_dim=False) # create collection # the original file is in /ei-edl01/data/uab_datasets/inria blCol = uab_collectionFunctions.uabCollection('inria') opDetObj = bPreproc.uabOperTileDivide(255) # inria GT has value 0 and 255, we map it back to 0 and 1 # [3] is the channel id of GT rescObj = uabPreprocClasses.uabPreprocMultChanOp([], 'GT_Divide.tif', 'Map GT to (0, 1)', [3], opDetObj) rescObj.run(blCol) img_mean = np.zeros(3) #blCol.getChannelMeans([0, 1, 2]) # get mean of rgb info # extract patches extrObj = uab_DataHandlerFunctions.uabPatchExtr([0, 1, 2, 4], # extract all 4 channels cSize=flags.input_size, # patch size as 572*572 numPixOverlap=int(model.get_overlap()/2), # overlap as 92 extSave=['jpg', 'jpg', 'jpg', 'png'], # save rgb files as jpg and gt as png isTrain=True, gtInd=3, pad=model.get_overlap()) # pad around the tiles patchDir = extrObj.run(blCol) # make data reader # use uabCrossValMaker to get fileLists for training and validation idx, file_list = uabCrossValMaker.uabUtilGetFolds(patchDir, 'fileList.txt', 'force_tile') # use first 5 tiles for validation file_list_train = uabCrossValMaker.make_file_list_by_key(idx, file_list, [i for i in range(6, 37)]) file_list_valid = uabCrossValMaker.make_file_list_by_key(idx, file_list, [i for i in range(0, 6)]) with tf.name_scope('image_loader'): # GT has no mean to subtract, append a 0 for block mean dataReader_train = uabDataReader.ImageLabelReader([3], [0, 1, 2], patchDir, file_list_train, flags.input_size, flags.tile_size, flags.batch_size, dataAug='flip,rotate', block_mean=np.append([0], img_mean)) # no augmentation needed for validation dataReader_valid = uabDataReader.ImageLabelReader([3], [0, 1, 2], patchDir, file_list_valid, flags.input_size, flags.tile_size, flags.batch_size, dataAug=' ', block_mean=np.append([0], img_mean)) # train start_time = time.time() model.train_config('X', 'Z', flags.n_train, flags.n_valid, flags.input_size, uabRepoPaths.modelPath, par_dir='BiGAN_128') model.run(train_reader=dataReader_train, valid_reader=dataReader_valid, pretrained_model_dir=None, isTrain=True, img_mean=img_mean, verb_step=100, # print a message every 100 step(sample) save_epoch=20, # save the model every 5 epochs gpu=GPU, tile_size=flags.tile_size, patch_size=flags.input_size) duration = time.time() - start_time print('duration {:.2f} hours'.format(duration/60/60))