def main(_): """ The main function for training steps """ pp.pprint(flags.FLAGS.__flags) n_per_itr_print_results = 100 kb_work_on_patch = True # --------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------- # Manual Switchs ------------------------------------------------------------------------------ # --------------------------------------------------------------------------------------------- # DATASET PARAMETER : UCSD # FLAGS.dataset = 'UCSD' # FLAGS.dataset_address = './dataset/UCSD_Anomaly_Dataset.v1p2/UCSDped2/Train' nd_input_frame_size = (240, 360) nd_slice_size = (45, 45) n_stride = 25 n_fetch_data = 600 # --------------------------------------------------------------------------------------------- # # DATASET PARAMETER : MNIST # FLAGS.dataset = 'mnist' # FLAGS.dataset_address = './dataset/mnist' # nd_input_frame_size = (28, 28) # nd_slice_size = (28, 28) FLAGS.train = True FLAGS.input_width = nd_slice_size[0] FLAGS.input_height = nd_slice_size[1] FLAGS.output_width = nd_slice_size[0] FLAGS.output_height = nd_slice_size[1] FLAGS.sample_dir = 'export/' + FLAGS.dataset + '_%d.%d' % ( nd_slice_size[0], nd_slice_size[1]) FLAGS.input_fname_pattern = '*' check_some_assertions() # manual handling of GPU gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.4) run_config = tf.ConfigProto(gpu_options=gpu_options) run_config.gpu_options.allow_growth = True with tf.Session(config=run_config) as sess: tmp_model = ALOCC_Model( sess, input_width=FLAGS.input_width, input_height=FLAGS.input_height, output_width=FLAGS.output_width, output_height=FLAGS.output_height, batch_size=FLAGS.batch_size, sample_num=FLAGS.batch_size, attention_label=FLAGS.attention_label, r_alpha=FLAGS.r_alpha, dataset_name=FLAGS.dataset, dataset_address=FLAGS.dataset_address, input_fname_pattern=FLAGS.input_fname_pattern, checkpoint_dir=FLAGS.checkpoint_dir, is_training=FLAGS.train, log_dir=FLAGS.log_dir, sample_dir=FLAGS.sample_dir, nd_patch_size=nd_slice_size, n_stride=n_stride, n_per_itr_print_results=n_per_itr_print_results, kb_work_on_patch=kb_work_on_patch, nd_input_frame_size=nd_input_frame_size, n_fetch_data=n_fetch_data) # show_all_variables() if FLAGS.train: print('Program is on Train Mode') tmp_model.train(FLAGS) else: if not tmp_model.load(FLAGS.checkpoint_dir)[0]: print('Program is on Test Mode') raise Exception( "[!] Train a model first, then run test mode from file test.py" )
def main(_): """ The main function for training steps """ n_per_itr_print_results = 100 kb_work_on_patch = True # --------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------- # Manual Switchs ------------------------------------------------------------------------------ # --------------------------------------------------------------------------------------------- # DATASET PARAMETER : data-alocc FLAGS.dataset = "data-alocc" FLAGS.dataset_address = "./dataset/data-alocc/train" kb_work_on_patch = False nd_input_frame_size = (180, 270) nd_slice_size = (180, 270) n_stride = 1 FLAGS.train = True FLAGS.input_width = nd_slice_size[0] FLAGS.input_height = nd_slice_size[1] FLAGS.output_width = nd_slice_size[0] FLAGS.output_height = nd_slice_size[1] FLAGS.sample_dir = ("export/" + FLAGS.dataset + "_%d.%d.%f_" % (nd_slice_size[0], nd_slice_size[1], FLAGS.r_alpha)) FLAGS.input_fname_pattern = "*" pp.pprint(flags.FLAGS.__flags) check_some_assertions() # manual handling of GPU gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5) run_config = tf.ConfigProto(gpu_options=gpu_options) run_config.gpu_options.allow_growth = True with tf.Session(config=run_config) as sess: tmp_model = ALOCC_Model( sess, input_width=FLAGS.input_width, input_height=FLAGS.input_height, output_width=FLAGS.output_width, output_height=FLAGS.output_height, batch_size=FLAGS.batch_size, sample_num=FLAGS.batch_size, attention_label=FLAGS.attention_label, r_alpha=FLAGS.r_alpha, dataset_name=FLAGS.dataset, dataset_address=FLAGS.dataset_address, input_fname_pattern=FLAGS.input_fname_pattern, checkpoint_dir=FLAGS.checkpoint_dir, is_training=FLAGS.train, log_dir=FLAGS.log_dir, sample_dir=FLAGS.sample_dir, nd_patch_size=nd_slice_size, n_stride=n_stride, n_per_itr_print_results=n_per_itr_print_results, kb_work_on_patch=kb_work_on_patch, nd_input_frame_size=nd_input_frame_size, ) # show_all_variables() if FLAGS.train: print("Program is on Train Mode") tmp_model.train(FLAGS) else: if not tmp_model.load(FLAGS.checkpoint_dir)[0]: print("Program is on Test Mode") raise Exception( "[!] Train a model first, then run test mode from file test.py" )