def __init__(self, sess): self.sess = sess self.dataset_root = 'F:\\Learning\\tensorflow\\detect\\Dataset\\' if Detection_or_Classifier=='classifier': self.train_data = DataLoader(root=self.dataset_root+'SmallNORB\\trainImages',batch=batch_size) self.test_data = DataLoader(root=self.dataset_root+'SmallNORB\\testImages',batch=batch_size) self.labels = [str(i) for i in range(1,1001)] print("Building the model...") self.model = IGCV3FPN(num_classes=len(self.labels), num_anchors=5, batch_size = batch_size, max_box_per_image = max_box_per_image, max_grid=[max_input_size,max_input_size], ) print("Model is built successfully\n\n") elif Detection_or_Classifier=='detection': train_ints, valid_ints, self.labels = create_training_instances( self.dataset_root+'VOC2012\\Annotations\\', self.dataset_root+'VOC2012\\JPEGImages\\', 'data.pkl', '','','', ['person','head','hand','foot','aeroplane','tvmonitor','train','boat','dog','chair', 'bird','bicycle','bottle','sheep','diningtable','horse','motorbike','sofa','cow', 'car','cat','bus','pottedplant'] ) self.train_data = BatchGenerator( instances = train_ints, anchors = anchors, labels = self.labels, downsample = 32, # ratio between network input's size and network output's size, 32 for YOLOv3 max_box_per_image = max_box_per_image, batch_size = batch_size, min_net_size = min_input_size, max_net_size = max_input_size, shuffle = True, jitter = 0.3, norm = normalize ) self.test_data = BatchGenerator( instances = valid_ints, anchors = anchors, labels = self.labels, downsample = 32, # ratio between network input's size and network output's size, 32 for YOLOv3 max_box_per_image = max_box_per_image, batch_size = batch_size, min_net_size = min_input_size, max_net_size = max_input_size, shuffle = True, jitter = 0.0, norm = normalize ) print("Building the model...") self.model = IGCV3FPN(num_classes=len(self.labels), num_anchors=5, batch_size = batch_size, max_box_per_image = max_box_per_image, max_grid=[max_input_size,max_input_size], ) print("Model is built successfully\n\n") #tf.profiler.profile(tf.get_default_graph(),options=tf.profiler.ProfileOptionBuilder.trainable_variables_parameter(), cmd='scope') num_params = get_num_params() print('all params:{}'.format(num_params)) var = tf.global_variables() var_list = [val for val in var] if Detection_or_Classifier=='detection' and False: #var_list = [val for val in var if (('zsc_preprocessing' in val.name) or ('zsc_feature' in val.name) or ('zsc_attention' in val.name) or ('zsc_detection' in val.name)) and ('SE' not in val.name)] var_list = [val for val in var if ('SE' not in val.name)] self.saver = tf.train.Saver(var_list=var_list,max_to_keep=max_to_keep, keep_checkpoint_every_n_hours=10) self.save_checkpoints_path = os.path.join(os.getcwd(),'checkpoints',Detection_or_Classifier) if not os.path.exists(self.save_checkpoints_path): os.makedirs(self.save_checkpoints_path) # Initializing the model self.init = None self.__init_model() # Loading the model checkpoint if exists self.__load_model() summary_dir = os.path.join(os.getcwd(),'logs',Detection_or_Classifier) if not os.path.exists(summary_dir): os.makedirs(summary_dir) summary_dir_train = os.path.join(summary_dir,'train') if not os.path.exists(summary_dir_train): os.makedirs(summary_dir_train) summary_dir_test = os.path.join(summary_dir,'test') if not os.path.exists(summary_dir_test): os.makedirs(summary_dir_test) self.train_writer = tf.summary.FileWriter(summary_dir_train,sess.graph) self.test_writer = tf.summary.FileWriter(summary_dir_test)
def __init__(self, sess): self.sess = sess self.dataset_root = 'F:\\Learning\\tensorflow\\detect\\Dataset\\' if Detection_or_Classifier == 'classifier': self.labels = list(range(18)) self.train_data = DataLoader(root=os.path.join( self.dataset_root, 'data', 'train'), classes=len(self.labels), batch=batch_size) print("Building the model...") self.model = Model(num_classes=len(self.labels)) print("Model is built successfully\n\n") elif Detection_or_Classifier == 'detection': train_ints, valid_ints, self.labels = create_training_instances( os.path.join(self.dataset_root, 'Fish', 'Annotations'), os.path.join(self.dataset_root, 'Fish', 'JPEGImages'), 'data.pkl', '', '', '', False, [ 'heidiao', 'niyu', 'lvqimamiantun', 'hualu', 'heijun', 'dalongliuxian', 'tiaoshiban' ] #['person','head','hand','foot','aeroplane','tvmonitor','train','boat','dog','chair', # 'bird','bicycle','bottle','sheep','diningtable','horse','motorbike','sofa','cow', # 'car','cat','bus','pottedplant'] ) self.train_data = BatchGenerator(train_ints, self.labels, batch_size) print("Building the model...") self.model = Model(num_classes=23) print("Model is built successfully\n\n") #tf.profiler.profile(tf.get_default_graph(),options=tf.profiler.ProfileOptionBuilder.trainable_variables_parameter(), cmd='scope') num_params = get_num_params() print('all params:{}'.format(num_params)) self.use_classifier_pretrain = True if not self.use_classifier_pretrain: var = tf.global_variables() else: var = tf.trainable_variables() var_list = [val for val in var] if Detection_or_Classifier == 'detection' and self.use_classifier_pretrain: var_list = [val for val in var if 'zsc_detection' not in val.name] if Detection_or_Classifier == 'classifier': var = tf.global_variables() var_list = [val for val in var if 'Logits/bias' not in val.name] self.saver = tf.train.Saver(var_list=var_list, max_to_keep=max_to_keep) self.save_checkpoints_path = os.path.join(os.getcwd(), 'checkpoints', Detection_or_Classifier) if not os.path.exists(self.save_checkpoints_path): os.makedirs(self.save_checkpoints_path) # Initializing the model self.init = None self.__init_model() # Loading the model checkpoint if exists self.__load_model()
def __init__(self, sess): self.sess = sess self.dataset_root = '/home/b101/anaconda2/ZSCWork/Dataset/' if Detection_or_Classifier == 'classifier': self.train_data = DataLoader(root=self.dataset_root + 'SmallNORB/trainImages', batch=batch_size) self.test_data = DataLoader(root=self.dataset_root + 'SmallNORB/testImages', batch=batch_size) self.labels = ['1', '2', '3', '4', '5'] print("Building the model...") self.model = CliqueFPN( num_classes=len(self.labels), num_anchors=3, batch_size=batch_size, max_box_per_image=max_box_per_image, max_grid=[max_input_size, max_input_size], ) print("Model is built successfully\n\n") elif Detection_or_Classifier == 'detection': train_ints, valid_ints, self.labels = create_training_instances( self.dataset_root + 'Fish/Annotations/', self.dataset_root + 'Fish/JPEGImages/', 'data.pkl', '', '', '', [ 'heidiao', 'niyu', 'lvqimamiantun', 'hualu', 'heijun', 'dalongliuxian', 'tiaoshiban' ] #['person','head','hand','foot','aeroplane','tvmonitor','train','boat','dog','chair', # 'bird','bicycle','bottle','sheep','diningtable','horse','motorbike','sofa','cow', # 'car','cat','bus','pottedplant'] ) self.train_data = BatchGenerator( instances=train_ints, anchors=anchors, labels=self.labels, downsample= 32, # ratio between network input's size and network output's size, 32 for YOLOv3 max_box_per_image=max_box_per_image, batch_size=batch_size, min_net_size=min_input_size, max_net_size=max_input_size, shuffle=True, jitter=0.3, norm=normalize) self.test_data = BatchGenerator( instances=valid_ints, anchors=anchors, labels=self.labels, downsample= 32, # ratio between network input's size and network output's size, 32 for YOLOv3 max_box_per_image=max_box_per_image, batch_size=batch_size, min_net_size=min_input_size, max_net_size=max_input_size, shuffle=True, jitter=0.0, norm=normalize) print("Building the model...") self.model = CliqueFPN( num_classes=len(self.labels), num_anchors=3, batch_size=batch_size, max_box_per_image=max_box_per_image, max_grid=[max_input_size, max_input_size], ) print("Model is built successfully\n\n") #tf.profiler.profile(tf.get_default_graph(),options=tf.profiler.ProfileOptionBuilder.trainable_variables_parameter(), cmd='scope') num_params = get_num_params() print('all params:{}'.format(num_params)) var = tf.global_variables() var_list = [val for val in var] if Detection_or_Classifier == 'detection' and False: var_list = [ val for val in var if 'PrimaryConv/conv_0/batchnorm' not in val.name and 'PrimaryConv/conv_1/batchnorm' not in val.name and 'PrimaryConv/conv_2/batchnorm' not in val.name and 'PrimaryConv/conv_0/DecoupledOperator' not in val.name and 'PrimaryConv/conv_1/DecoupledOperator' not in val.name and 'PrimaryConv/conv_2/DecoupledOperator' not in val.name and 'PrimaryConv/conv_0/prelu' not in val.name and 'PrimaryConv/conv_1/prelu' not in val.name and 'PrimaryConv/conv_2/prelu' not in val.name and 'SelfAttention/g/batch_norm' not in val.name and 'SelfAttention/f/batch_norm' not in val.name and 'SelfAttention/h/batch_norm' not in val.name and 'SelfAttention/g/prelu' not in val.name and 'SelfAttention/f/prelu' not in val.name and 'SelfAttention/h/prelu' not in val.name and 'SelfAttention/DecoupledOperator' not in val.name and 'zsc_pred' not in val.name ] self.saver = tf.train.Saver(var_list=var_list, max_to_keep=max_to_keep) self.save_checkpoints_path = os.path.join(os.getcwd(), 'checkpoints', Detection_or_Classifier) if not os.path.exists(self.save_checkpoints_path): os.makedirs(self.save_checkpoints_path) # Initializing the model self.init = None self.__init_model() # Loading the model checkpoint if exists self.__load_model()
def __init__(self, sess): self.sess = sess self.dataset_root = '/home/b101/anaconda2/ZSCWork/Dataset/' if Detection_or_Classifier=='classifier': self.train_data = DataLoader(root=self.dataset_root+'SmallNORB/trainImages',batch=batch_size) self.test_data = DataLoader(root=self.dataset_root+'SmallNORB/testImages',batch=batch_size) self.labels = ['1','2','3','4','5'] print("Building the model...") self.model = CliqueFPN(num_classes=len(self.labels), num_anchors=5, batch_size = batch_size, max_box_per_image = max_box_per_image, max_grid=[max_input_size,max_input_size], ) print("Model is built successfully\n\n") elif Detection_or_Classifier=='detection': train_ints, valid_ints, self.labels = create_training_instances( self.dataset_root+'VOC2012/Annotations/', self.dataset_root+'VOC2012/JPEGImages/', 'data.pkl', '','','', ['person','head','hand','foot','aeroplane','tvmonitor','train','boat','dog','chair', 'bird','bicycle','bottle','sheep','diningtable','horse','motorbike','sofa','cow', 'car','cat','bus','pottedplant'] ) self.train_data = BatchGenerator( instances = train_ints, anchors = anchors, labels = self.labels, downsample = 32, # ratio between network input's size and network output's size, 32 for YOLOv3 max_box_per_image = max_box_per_image, batch_size = batch_size, min_net_size = min_input_size, max_net_size = max_input_size, shuffle = True, jitter = 0.3, norm = normalize ) self.test_data = BatchGenerator( instances = valid_ints, anchors = anchors, labels = self.labels, downsample = 32, # ratio between network input's size and network output's size, 32 for YOLOv3 max_box_per_image = max_box_per_image, batch_size = batch_size, min_net_size = min_input_size, max_net_size = max_input_size, shuffle = True, jitter = 0.0, norm = normalize ) print("Building the model...") self.model = CliqueFPN(num_classes=len(self.labels), num_anchors=5, batch_size = batch_size, max_box_per_image = max_box_per_image, max_grid=[max_input_size,max_input_size], ) print("Model is built successfully\n\n") #tf.profiler.profile(tf.get_default_graph(),options=tf.profiler.ProfileOptionBuilder.trainable_variables_parameter(), cmd='scope') num_params = get_num_params() print('all params:{}'.format(num_params)) var = tf.global_variables() var_list = [val for val in var] if Detection_or_Classifier=='detection' and False: var_list = [val for val in var if 'CliqueBlock_2/loop/deform_conv' not in val.name ] self.saver = tf.train.Saver(var_list=var_list,max_to_keep=max_to_keep) self.save_checkpoints_path = os.path.join(os.getcwd(),'checkpoints',Detection_or_Classifier) if not os.path.exists(self.save_checkpoints_path): os.makedirs(self.save_checkpoints_path) # Initializing the model self.init = None self.__init_model() # Loading the model checkpoint if exists self.__load_model() summary_dir = os.path.join(os.getcwd(),'logs',Detection_or_Classifier) if not os.path.exists(summary_dir): os.makedirs(summary_dir) summary_dir_train = os.path.join(summary_dir,'train') if not os.path.exists(summary_dir_train): os.makedirs(summary_dir_train) summary_dir_test = os.path.join(summary_dir,'test') if not os.path.exists(summary_dir_test): os.makedirs(summary_dir_test) self.train_writer = tf.summary.FileWriter(summary_dir_train,sess.graph) self.test_writer = tf.summary.FileWriter(summary_dir_test)