def main(args): parser = argparse.ArgumentParser( description=("Run deep models for visual semantic role segmentation " "(or detection)")) parser.add_argument("mode", help="Mode to run model in (e.g. 'train')") parser.add_argument("-s", "--save_dir", help="directory for saving the model", default="saved_models/%s" % dt.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")) parser.add_argument("-e", "--epochs", help="number of epochs for training", type=int, default=50) parser.add_argument("-p", "--save_per", help="epochs to wait before saving", type=int, default=5) parser.add_argument("-l", "--learn_rate", help="learning rate", type=float, default=0.001) parser.add_argument("-c", "--cuda", type=int, nargs="+", help="ids of gpus to use during training", default=[]) parser.add_argument("-f", "--fake", action="store_true", help=("flag to use fake data that loads quickly (for" "development purposes)")) parser.add_argument( "--net", help="file in which model is stored. Used in test mode.", default=None) cfg = parser.parse_args(args) if cfg.mode == 'train': model = md.CtxBB() if cfg.fake: dataloader = get_fake_loader() else: dataloader = ld.get_loader("vcoco_train", ld.COCO_IMGDIR) trainer = md.BasicTrainer(model, dataloader, **vars(cfg)) logging.getLogger(__name__).info("Beginning Training...") trainer.train(cfg.epochs) elif cfg.mode == 'test': checkpoint = torch.load(cfg.net) model = checkpoint["model"] evaluator = ev.Evaluator(**vars(cfg)) ev.do_eval(evaluator, model, "vcoco_val", cfg.save_dir) else: logging.getLogger(__name__).error("Invalid mode '%s'" % str(cfg.mode)) sys.exit(1)
def save_trainer(trainer): # save the model if needed if mt.should_do(trainer.epoch, trainer.save_per) and \ trainer.save_dir is not None: logging.getLogger(__name__).info("Saving training file...") torch.save( trainer, os.path.join(trainer.save_dir, "trainer_%d.trn" % trainer.epoch))
def train(self, epochs): self.model.train() logging.getLogger(__name__).info("Starting training at epoch %d" % (self.epoch + 1)) for self.epoch in range(self.epoch + 1, self.epoch + 1 + epochs): logging.getLogger(__name__).info("Running epoch %d" % self.epoch) # Make a full pass over the training set. for self.iteration, data in enumerate(self.dataloader, start=1): self.handle_batch(data) self.run_batch_callbacks() self.run_epoch_callbacks() del self.epoch_data[:] # Clear the list of epoch data
#!/usr/bin/python # -*- coding: utf-8 -*- import configparser import sys import telebot import time from watchfile import configuracion from watchfile import fc from utils import mylogger logger = mylogger.getLogger() # DATOS DEL FICHERO DE CONFIGURACION config = configuracion['GENERAL'] primerEnvio = config['PrimerEnvio'] archivo = config['fichero'] parametros = configuracion['TELEGRAM'] Token = parametros['Token'] groupId = parametros['Id'] # Combinamos la declaración del Token con la función de la API tb = telebot.TeleBot(Token) # ENVIO DEL MENSAJE def env_archivo(f): tb.send_message(groupId, "Actualizado cuadre") doc = open(f, 'rb') tb.send_document(groupId, doc)
def print_loss(trainer): logging.getLogger(__name__).info( "---> After Epoch #%d: Loss=%.8f" % (trainer.epoch, sum(trainer.local_history) / len(trainer.local_history)))
def main(args): parser = argparse.ArgumentParser( description=("Run deep models for visual semantic role segmentation " "(or detection)")) parser.add_argument("mode", help="Mode to run model in (e.g. 'train')") parser.add_argument("-s", "--save_dir", help="directory for saving the model", default="saved_models/%s" % dt.datetime.now().strftime("%Y_%m_%d_%H_%M_%S")) parser.add_argument("-e", "--epochs", help="number of epochs for training", type=int, default=50) parser.add_argument("-p", "--save_per", help="epochs to wait before saving", type=int, default=5) parser.add_argument("-l", "--learn_rate", help="learning rate", type=float, default=0.001) parser.add_argument("-c", "--cuda", type=int, nargs="+", help="ids of gpus to use during training", default=[]) parser.add_argument( "--net", help="file in which model is stored. Used in test mode.", default=None) parser.add_argument( "--coco_root", help=("path to coco directory, which must have an 'images'" "subfolder with images inside"), default=ld.COCO_ROOT) parser.add_argument( "--vcoco_root", help=("path to v-coco directory, which must have a 'coco'" "subfolder with another subfolder containing" "images/train2014 and images/val2014"), default=ld.VCOCO_ROOT) cfg = parser.parse_args(args) pathman = ld.PathManager(coco_root=cfg.coco_root, vcoco_root=cfg.vcoco_root) if cfg.mode == 'train': vcoco_all = vu.load_vcoco("vcoco_train") categories = [x["name"] for x in vu.load_coco().cats.itervalues()] translator = ld.VCocoTranslator(vcoco_all, categories) n_action_classes = translator.num_actions n_action_nonagent_roles = translator.num_action_nonagent_roles dataloader = ld.RoiVCocoBoxes("vcoco_train", pathman.coco_root, pathman.vcoco_root) classes = dataloader.get_classes() model = fhoi.HoiModel( classes, n_action_classes, n_action_nonagent_roles, faster_rcnn_command_line=["NCLASSES", len(classes)], cuda=cfg.cuda) trainer = thoi.HoiTrainer(model, dataloader, **vars(cfg)) logging.getLogger(__name__).info("Beginning Training...") trainer.train(cfg.epochs) """ # TODO build this test code. elif cfg.mode == 'test': checkpoint = torch.load(cfg.net) model = checkpoint["model"] evaluator = ev.Evaluator(**vars(cfg)) ev.do_eval(evaluator, model, "vcoco_val", cfg.save_dir) """ else: logging.getLogger(__name__).error("Invalid mode '%s'" % str(cfg.mode)) sys.exit(1)