Beispiel #1
0
  def __init__(self, dataset, pth_data, num_classes, num_samples_per_class, log):
    """
    Args:
      num_samples_per_class: num samples to generate per class in one batch
      batch_size: size of meta batch size (e.g. number of functions)
    """
    self.dataset = dataset.lower()
    self.num_samples_per_class = num_samples_per_class
    self.num_classes = num_classes
    self.pth_data = Path(pth_data).resolve()
    assert self.pth_data.exists(), 'The {} does not exists.'.format(self.pth_data)
  
    if self.dataset == 'toronto-coco-qa':
      data = torch.load(self.pth_data)
      self.all_words     = data['all_words']
      self.words_index   = data['words_index']
      self.max_word      = len(self.words_index)
      for key in self.all_words:
        self.words_index[ int(self.words_index[key]) ] = key
      self.all_answers   = data['all_answers']
      #self.answers_index = data['answers_index']
      self.base_training      = data['training']
      self.base_testing       = data['testing']
      
      self.meta_training      = [SimpleQA(self.words_index, x) for x in self.base_training]
      self.meta_testing       = [SimpleQA(self.words_index, x) for x in self.base_testing]
      for x in self.meta_training + self.meta_testing:
        x.check(self.max_word)

    elif self.dataset == 'ms-coco-ic':
      data = torch.load(self.pth_data)
      self.all_words     = data['all_words']
      self.words_index   = data['words2index']
      self.max_word      = len(self.words_index)
      for key in self.all_words:
        self.words_index[ int(self.words_index[key]) ] = key
      self.base_training      = data['training']
      self.base_testing       = data['testing']

      self.meta_training      = [SimpleQA(self.words_index, x, False) for x in self.base_training]
      self.meta_testing       = [SimpleQA(self.words_index, x, False) for x in self.base_testing]
      for x in self.meta_training + self.meta_testing:
        x.check(self.max_word)
    else:
      raise ValueError('Unrecognized dataset : {}'.format(dataset))
    print_log('Meta-Task : [{:}], train={:}, test={:}'.format(dataset, len(self.meta_training), len(self.meta_testing)), log)
Beispiel #2
0
    def train(self):
        for itr in tqdm(np.arange(self.start_itr, self.n_itr)):
            logger.log("----\nIteration {}\n----".format(itr))
            paths = self.obtain_samples(itr)
            data = self.process_samples(itr, paths)

            if self.train_model:
                self.add_paths_to_pool(data)
                if self.pool.size >= self.min_pool_size:

                    train_dynamics.train_model(
                        self.model,
                        self.pool,
                        n_train_batches=self.n_train_batches,
                        train_batch_size=self.train_batch_size)

            self.optimize_policy(itr, data)
            logger.print_log()
            logger.save_values()
		try:
			self.conn = psycopg2.connect("dbname='" + db_name + "' user='******' password='******' host='" + db_host + "'")
			return True
		except:
			print("DataBase Connection Error !!")
			print("dbname='" + db_name + "' user='******' password='******' host='" + db_host + "'")
			return False

	# connectionの取得
	def get_pg_connection(self):
		return self.conn

	# PostgreSQL接続終了
	def set_pg_connection_close(self, cur):
		cur.close()
		self.conn.close()

# テスト用
if __name__ == '__main__':
	file_name = "access_log_" + datetime.datetime.now().strftime("%Y-%m-%d") + ".log"
	logger = logger.Logger(file_name)

	pg_connection = PgConnection()
	if pg_connection.set_pg_connection_open():
		connectin = pg_connection.get_pg_connection()
		cursor = connectin.cursor()
		pg_connection.set_pg_connection_close(cursor)

	logger.print_log()
Beispiel #4
0
                        if e.errno == errno.ENOENT:
                            unlink(self.target.name)
                        else:
                            raise
                else: # no output generated at all; that's ok
                    unlink(self.tmpname_sout)
                    unlink(self.target.name)
                if vars.VERBOSE or vars.XTRACE or vars.DEBUG:
                    log('%s (done)\n\n', self.target.printable_name())
            else:
                unlink(self.tmpname_sout)
                unlink(self.tmpname_arg3)

            if rv != 0:
                if vars.ONLY_LOG:
                    logger.print_log(self.target)
                err('%s: exit code %d\n', self.target.printable_name(), rv)
            self.target.build_done(exitcode=rv)
            self.target.refresh()

            self._move_extra_results(self.outdir, self.target.dirname() or ".", rv)

            self.result[0] += rv
            self.result[1] += 1
            if self.parent:
                self.parent.add_dep(self.target)

        finally:
            self.tmp_sout_f.close()
            self.target.dolock().unlock()
Beispiel #5
0
def get_help():
    '''
    Display indication to navigate in the CLI interface
    '''
    logger.log('Print the help command')
    print(f'Usage: Image filter\n-h or ---help : To get all the commands\n'
          f'-i or --input-dir <directory>\n-o --output-dir <directory>')


argument = ('-h', '---help', '--log-file', '--filter', '--config-file')

if not (args[1] in argument):
    print('Command not found. Type ---help or -h')
if args[1] in ('-h', '---help'):
    text = art.text2art("HELP")
    print(text)
    get_help()
if args[1] == '--log-file':
    text = art.text2art("LOGS")
    print(text)
    logger.print_log(args[2])
if args[1] == '--config-file':
    apply_filter(args[2])
if args[1] == '--filter':
    text = art.text2art("FILTER")
    print(text)
    if len(args) == 2:
        print('Please entrer a filter')
    else:
        apply_filter(args[2])