-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (36 loc) · 1.27 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Entrance file"""
import run_lib
from absl import app
from absl import flags
from ml_collections.config_flags import config_flags
import tensorflow as tf
import os
import numpy as np
import torch
import random
# set_deterministic
def set_deterministic(config):
# Pytorch
torch.manual_seed(config.seed)
# Numpy
np.random.seed(config.seed)
# Random
random.seed(config.seed)
FLAGS = flags.FLAGS
config_flags.DEFINE_config_file("config", None, "Training configuration.", lock_config=True)
flags.DEFINE_string("workdir", "usbm_traj", "Directory for saving visualized results.")
flags.DEFINE_string("type", "usbm", "Flag for switching different modes. (options: usbm / csbm)")
flags.DEFINE_string("resultdir", "results", "Directory for saving workdir.")
flags.DEFINE_bool("deterministic", False, "Set true to make the result deterministic.")
flags.DEFINE_integer("seed", 0, "Set the seed.")
def main(argv):
if FLAGS.deterministic:
FLAGS.config.seed = FLAGS.seed
set_deterministic(FLAGS.config)
resultdir = FLAGS.resultdir
FLAGS.config.sampling.type = FLAGS.type
tf.io.gfile.makedirs(resultdir)
tf.io.gfile.makedirs(os.path.join(resultdir, FLAGS.workdir))
run_lib.run(FLAGS.config, os.path.join(resultdir, FLAGS.workdir))
if __name__ == "__main__":
app.run(main)