Esempio n. 1
0
    def __init__(self, **kwargs):
        self.verbose = 0  # 0(warning) | 1(info) | 2(debug)

        # training signature
        self.machine = "ecegrid"  # "machine_id"
        self.timestamp = "17082300"  # "yymmdd##"
        # training configuration
        self.mode = 2  # 1(train) | 2(test model_file)
        self.config = 1

        self.seed = 1
        self.render = False  # whether render the window from the original envs or not
        self.visualize = True  # whether do online plotting and stuff or not
        self.save_best = False  # save model w/ highest reward if True, otherwise always save the latest model

        if 'gpu' in kwargs and kwargs['gpu']:
            self.use_cuda = torch.cuda.is_available()
            self.dtype = torch.cuda.FloatTensor if torch.cuda.is_available(
            ) else torch.FloatTensor
        else:
            self.use_cuda = False
            self.dtype = torch.FloatTensor

        # prefix for model/log/visdom
        self.refs = self.machine + "_" + self.timestamp  # NOTE: using this as env for visdom

        # Unpack possible arguments
        if 'mode' in kwargs and kwargs['mode']:
            self.mode = kwargs['mode']
        if 'config' in kwargs and kwargs['config']:
            self.config = kwargs['config']
        if 'model' in kwargs and kwargs['model']:
            self.refs = kwargs['model']
        self.visualize = kwargs['visualize']
        self.agent_type, self.env_type, self.game, self.circuit_type = CONFIGS[
            self.config]

        self.root_dir = os.getcwd()
        # model files
        # NOTE: will save the current model to model_name
        self.model_name = self.root_dir + "/models/" + self.refs + ".pth"
        # NOTE: will load pretrained model_file if not None
        self.model_file = None  #self.root_dir + "/models/{TODO:FILL_IN_PRETAINED_MODEL_FILE}.pth"
        if self.mode == 2:
            self.model_file = self.model_name  # NOTE: so only need to change self.mode to 2 to test the current training
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + "_test"  # NOTE: using this as env for visdom for testing, to avoid accidentally redraw on the training plots

        # logging configs
        self.log_name = self.root_dir + "/logs/" + self.refs + ".log"
        self.logger = loggerConfig(self.log_name, self.verbose)
        self.logger.warning("<===================================>")

        if self.visualize:
            self.vis = visdom.Visdom()
            self.logger.warning("bash$: python -m visdom.server"
                                )  # activate visdom server on bash
            self.logger.warning("http://localhost:8097/env/" +
                                self.refs)  # open this address on browser
Esempio n. 2
0
    def __init__(self):
        self.verbose = 0  # 0(warning) | 1(info) | 2(debug)

        # training signature
        self.machine = "hpcgpu2"  # "machine_id"
        self.timestamp = "17112500"  # "yymmdd## "
        # training configuration
        self.mode = 1  # 1(train) | 2(test) | 3(generate image)
        self.config = 0
        self.train_target = "semantic"  # depth|semantic

        self.seed = 1
        self.render = False  # whether render the window from the original envs or not
        self.visualize = True  # whether do online plotting and stuff or not
        self.save_best = False  # save model w/ highest reward if True, otherwise always save the latest model

        self.agent_type, self.model_type = CONFIGS[self.config]

        self.use_cuda = torch.cuda.is_available()
        self.dtype = torch.cuda.FloatTensor if torch.cuda.is_available(
        ) else torch.FloatTensor

        # prefix for model/log/visdom
        self.refs = self.machine + "_" + self.timestamp  # NOTE: using this as env for visdom
        self.root_dir = os.getcwd()

        # model files
        # NOTE: will save the current model to model_name
        self.model_name = self.root_dir + "/models/" + self.refs + ".pth"
        # NOTE: will load pretrained model_file if not None
        self.model_file = self.root_dir + "/models/pretrained.pth"
        #self.model_file  = None
        if self.mode == 2:
            self.model_file = self.model_name
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + "_test"
        if self.mode == 3:
            self.model_file = self.model_name
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + "_generate"

        # logging configs
        self.log_name = self.root_dir + "/logs/" + self.refs + ".log"
        self.logger = loggerConfig(self.log_name, self.verbose)
        self.logger.warning("<===================================>")

        if self.visualize:
            self.vis = visdom.Visdom()
            #self.logger.warning("bash$: python -m visdom.server")           # activate visdom server on bash
            #self.logger.warning("http://localhost:8097/env/" + self.refs)   # open this address on browser
            self.writer = SummaryWriter(self.root_dir + '/runs/' + self.refs)
            self.logger.warning("bash$: tensorboardX --logdir run/"
                                )  # activate visdom server on bash
            self.logger.warning(
                "http://localhost:6006")  # open this address on browser
    def __init__(self):
        self.verbose = 0  # 0(warning) | 1(info) | 2(debug)

        # training signature
        self.machine = "cpu1"  # "machine_id"
        self.timestamp = "17072200"  # "yymmdd##"
        self.visdom_port = 8098
        # training configuration
        self.mode = 1  # 1(train) | 2(test model_file)

        self.continue_training = True  # Continues training if a model already exists, otherwise starts from 0

        self.seed = 123
        self.render = False  # whether render the window from the original envs or not
        self.visualize = True  # whether do online plotting and stuff or not

        self.num_processes = 10
        self.hist_len = 4
        self.hidden_dim = 256

        self.use_cuda = False  # Not used
        self.dtype = torch.FloatTensor

        # prefix for model/log/visdom
        self.refs = self.machine + "_" + self.timestamp  # NOTE: using this as env for visdom
        self.root_dir = os.getcwd()

        # model files
        self.model_name = self.root_dir + "/models/" + self.refs + ".pth"

        if self.continue_training:
            if os.path.exists(self.model_name):
                self.model_file = self.model_name
            else:
                self.model_file = None

        if self.mode == 2:
            self.model_file = self.model_name  # NOTE: so only need to change self.mode to 2 to test the current training
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + "_test"  # NOTE: using this as env for visdom for testing, to avoid accidentally redraw on the training plots

        # logging configs
        self.log_name = self.root_dir + "/logs/" + self.refs + ".log"
        self.logger = loggerConfig(self.log_name, self.verbose)
        self.logger.warning("<===================================>")

        if self.visualize:
            self.vis = visdom.Visdom(port=self.visdom_port)
Esempio n. 4
0
    def __init__(self):
        self.verbose     = 0            # 0(warning) | 1(info) | 2(debug)

        # training signature
        self.machine     = "CopyBenchmark"       # "machine_id"
        self.timestamp   = "171202"   # "yymmdd##"

        # training configuration
        self.mode        = 1            # 1(train) | 2(test model_file)
        self.config      = 3            #1:copy #3: associative recall

        self.seed        = 333         #111 #222 #666
        self.render      = True        # whether render the window from the original envs or not
        self.visualize   = True         #whether save bit error on csv  # whether diaplay output and save bit error on command line or not
        self.save_best   = False        # save model w/ highest reward if True, otherwise always save the latest model

        self.agent_type, self.env_type, self.game, self.circuit_type = CONFIGS[self.config]

        self.use_cuda    = torch.cuda.is_available()
        self.dtype       = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor

        # prefix for model/log/visdom
        self.refs        = self.machine + "_" + self.timestamp  # NOTE: using this as env for visdom
        self.root_dir    = os.getcwd()

        # model files
        # NOTE: will save the current model to model_name
        self.model_name  = self.root_dir + "/models/" + self.refs + ".pth"
        self.model_name_ite  = self.root_dir + "/models/" + self.refs
        # NOTE: will load pretrained model_file if not None
        self.model_file  = None#self.root_dir + "/models/{TODO:FILL_IN_PRETAINED_MODEL_FILE}.pth"
        if self.mode == 2:
            self.model_file  = self.model_name  # NOTE: so only need to change self.mode to 2 to test the current training
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + "_test"     # NOTE: using this as env for visdom for testing, to avoid accidentally redraw on the training plots

        # logging configs
        self.log_name    = self.root_dir + "/logs/" + self.refs + ".log"
        self.logger      = loggerConfig(self.log_name, self.verbose)
        self.logger.warning("<===================================>")

        if self.visualize:
            self.vis = visdom.Visdom()
            self.logger.warning("bash$: python -m visdom.server")           # activate visdom server on bash
            self.logger.warning("http://localhost:8097/env/" + self.refs)   # open this address on browser
Esempio n. 5
0
    def __init__(self):
        self.verbose     = 0            # 0(warning) | 1(info) | 2(debug)

        # training signature
        self.machine     = "aisdaim"    # "machine_id"
        self.timestamp   = "17082400"   # "yymmdd##"
        # training configuration
        self.mode        = 1            # 1(train) | 2(test model_file)
        self.config      = 7

        self.seed        = 123
        self.render      = False        # whether render the window from the original envs or not
        self.visualize   = True         # whether do online plotting and stuff or not
        self.save_best   = False        # save model w/ highest reward if True, otherwise always save the latest model

        self.agent_type, self.env_type, self.game, self.model_type, self.memory_type = CONFIGS[self.config]

        if self.agent_type == "dqn":
            self.enable_double_dqn  = False
            self.enable_dueling     = False
            self.dueling_type       = 'avg' # avg | max | naive

            if self.env_type == "gym":
                self.hist_len       = 1
                self.hidden_dim     = 16
            else:
                self.hist_len       = 4
                self.hidden_dim     = 256

            self.use_cuda           = torch.cuda.is_available()
            self.dtype              = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor
        elif self.agent_type == "a3c":
            self.enable_log_at_train_step = True # when False, x-axis would be frame_step instead of train_step

            self.enable_lstm        = True
            if "-con" in self.model_type:
                self.enable_continuous  = True
            else:
                self.enable_continuous  = False
            self.num_processes      = 16

            self.hist_len           = 1
            self.hidden_dim         = 128

            self.use_cuda           = False
            self.dtype              = torch.FloatTensor
        elif self.agent_type == "acer":
            self.enable_bias_correction   = True
            self.enable_1st_order_trpo    = True
            self.enable_log_at_train_step = True # when False, x-axis would be frame_step instead of train_step

            self.enable_lstm        = True
            if "-con" in self.model_type:
                self.enable_continuous  = True
            else:
                self.enable_continuous  = False
            self.num_processes      = 16

            self.hist_len           = 1
            self.hidden_dim         = 32

            self.use_cuda           = False
            self.dtype              = torch.FloatTensor
        else:
            self.hist_len           = 1
            self.hidden_dim         = 256

            self.use_cuda           = torch.cuda.is_available()
            self.dtype              = torch.cuda.FloatTensor if torch.cuda.is_available() else torch.FloatTensor

        # prefix for model/log/visdom
        self.refs        = self.machine + "_" + self.timestamp # NOTE: using this as env for visdom
        self.root_dir    = os.getcwd()

        # model files
        # NOTE: will save the current model to model_name
        self.model_name  = self.root_dir + "/models/" + self.refs + ".pth"
        # NOTE: will load pretrained model_file if not None
        self.model_file  = None#self.root_dir + "/models/{TODO:FILL_IN_PRETAINED_MODEL_FILE}.pth"
        if self.mode == 2:
            self.model_file  = self.model_name  # NOTE: so only need to change self.mode to 2 to test the current training
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + "_test"     # NOTE: using this as env for visdom for testing, to avoid accidentally redraw on the training plots

        # logging configs
        self.log_name    = self.root_dir + "/logs/" + self.refs + ".log"
        self.logger      = loggerConfig(self.log_name, self.verbose)
        self.logger.warning("<===================================>")

        if self.visualize:
            self.vis = visdom.Visdom()
            self.logger.warning("bash$: python -m visdom.server")           # activate visdom server on bash
            self.logger.warning("http://localhost:8097/env/" + self.refs)   # open this address on browser
Esempio n. 6
0
    def __init__(self):
        self.verbose = 2  # 0(warning) | 1(info) | 2(debug)

        # training signature
        # TODO: fix action stats for multi-robot!
        # self.machine = "aiscpu4"  # "machine_id"
        # self.timestamp = "18032100"  # "yymmdd##"
        # self.step = ""

        # signatures of the best models
        self.machine = "aiscpu4"
        self.timestamp = "18032100"
        self.step = "3000021"
        self.icm_step = "3000021"
        #
        # self.machine = "aiscpu4"
        # self.timestamp = "18031601"
        # self.step = "2844054"
        # self.icm_step = "2844054"
        # self.machine = "aiscpu2"
        # self.timestamp = "18031700"
        # self.step = "2556792"
        # self.machine = "aiscpu4"
        # self.timestamp = "18031600"
        # self.step = "2976216"
        # self.icm_step = "2976216"  # "60109"  # "115896"

        # self.machine = "aiscpu4"
        # self.timestamp = "18031300"
        # self.step = "2760065"
        # self.machine = "aiscpu2"
        # self.timestamp = "18031300"
        # self.step = "1585315"
        # self.machine = "aiscpu4"
        # self.timestamp = "18031000"
        # self.step = "1299783"

        # self.test_ref_postfix = '_' + self.step + "_title"
        self.test_ref_postfix = '_' + self.step + "_test"
        # self.test_ref_postfix = '_' + self.step + "_test_gen"
        # self.test_ref_postfix = '_' + self.step + "_test_gen2"
        # self.test_ref_postfix = '_' + self.step + "_test_gen3"
        # self.test_ref_postfix = '_' + self.step + "_test_gen_hard"
        # training configuration
        self.mode = 2  # 1(train) | 2(test model_file)
        self.config = 18

        self.seed = 123
        self.render = False  # whether render the window from the original envs or not
        self.visualize = True  # whether do online plotting and stuff or not
        self.save_best = False  # save model w/ highest reward if True, otherwise always save the latest model
        self.icm_save_best = False
        self.plot_icm_test = False
        self.plot_env_picture = False
        self.verbose_test = False

        self.agent_type, self.env_type, self.game, self.model_type, self.memory_type = CONFIGS[
            self.config]

        self.icm = False

        if self.mode != 2:
            self.step = None

        if self.agent_type == "dqn":
            self.enable_double_dqn = False
            self.enable_dueling = False
            self.dueling_type = 'avg'  # avg | max | naive

            if self.env_type == "gym":
                self.hist_len = 1
                self.hidden_dim = 16
            else:
                self.hist_len = 4
                self.hidden_dim = 256

            self.use_cuda = torch.cuda.is_available()
            self.dtype = torch.cuda.FloatTensor if torch.cuda.is_available(
            ) else torch.FloatTensor
        elif self.agent_type == "a3c":
            self.enable_log_at_train_step = True  # when False, x-axis would be frame_step instead of train_step

            self.enable_lstm = True

            if "-con" in self.model_type:
                self.enable_continuous = True
            else:
                self.enable_continuous = False
            self.num_processes = 16

            self.hist_len = 1

            if self.env_type == "minisim":
                from core.minisim.models.icm.icm_inverse import ICMInverseModel
                # from core.minisim.models.icm.icm_inverse_same_features import ICMInverseModelSameFeatures
                from core.minisim.models.icm.icm_forward import ICMForwardModel
                self.icm = True
                # self.icm = False  # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                self.icm_inv_model = ICMInverseModel
                # self.icm_inv_model = ICMInverseModelSameFeatures
                self.icm_fwd_model = ICMForwardModel
                self.num_processes = 22  # 6, 23  # 22 seems to be twice faster than 23, why? try other?
                if minisim_num_robots > 1:
                    self.num_processes = 22  # 4, 23

            self.use_cuda = False
            self.dtype = torch.FloatTensor
        else:
            self.hist_len = 1
            self.hidden_dim = 256

            self.use_cuda = torch.cuda.is_available()
            self.dtype = torch.cuda.FloatTensor if torch.cuda.is_available(
            ) else torch.FloatTensor

        # prefix for model/log/visdom
        self.refs = self.machine + "_" + self.timestamp  # NOTE: using this as env for visdom
        self.root_dir = os.getcwd()

        # model files
        if self.icm:
            self.icm_inv_model_name = "{0}/models/{1}_icm_inv{2}.pth".format(
                self.root_dir, self.refs,
                ("_step_" +
                 self.icm_step) if self.icm_step is not None else "")
            self.icm_fwd_model_name = "{0}/models/{1}_icm_fwd{2}.pth".format(
                self.root_dir, self.refs,
                ("_step_" +
                 self.icm_step) if self.icm_step is not None else "")
            self.icm_inv_model_file = None
            self.icm_fwd_model_file = None
            if self.mode == 2:  # NOTE: so only need to change self.mode to 2 to test the current training
                self.icm_inv_model_file = self.icm_inv_model_name
                self.icm_fwd_model_file = self.icm_fwd_model_name

        # NOTE: will save the current model to model_name
        self.model_name = "{0}/models/{1}{2}.pth".format(
            self.root_dir, self.refs,
            ("_step_" + self.step) if self.step is not None else "")
        # NOTE: will load pretrained model_file if not None
        self.model_file = None
        # self.model_file  = self.root_dir + "/models/aiscpu2_17110500.pth"
        if self.mode == 2:
            self.model_file = self.model_name  # NOTE: so only need to change self.mode to 2 to test the current training
            assert self.model_file is not None, "Pre-Trained model is None, Testing aborted!!!"
            self.refs = self.refs + self.test_ref_postfix  # NOTE: using this as env for visdom for testing, to avoid accidentally redraw on the training plots

        # logging configs
        self.log_name = self.root_dir + "/logs/" + self.refs + ".log"
        self.logger = loggerConfig(self.log_name, self.verbose)
        self.logger.warning("<===================================>")

        if self.visualize:
            self.vis = visdom.Visdom()
            self.logger.warning("bash$: python -m visdom.server"
                                )  # activate visdom server on bash
            self.logger.warning("http://localhost:8097/env/" +
                                self.refs)  # open this address on browser