Python utils.config.Config() Examples
The following are 9
code examples of utils.config.Config().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
utils.config
, or try the search function
.
Example #1
Source File: wrapper.py From rd-usb with GNU General Public License v3.0 | 6 votes |
def run(self): config = Config() version = config.read("version") if version.startswith("TC"): if version.endswith("USB"): interface = TcSerialInterface(config.read("port")) else: interface = TcBleInterface(config.read("ble_address")) else: interface = UmInterface(config.read("port")) if version == "UM25C": interface.enable_higher_resolution() while True: message = self.command.get() if message == "connect": self.result.put(self.call(interface.connect, "connected")) if message == "disconnect": self.result.put(self.call(interface.disconnect, "disconnected")) if message == "read": self.result.put(self.call(interface.read))
Example #2
Source File: lslocal.py From lightsocks with MIT License | 6 votes |
def run_server(config: lsConfig.Config): loop = asyncio.get_event_loop() listenAddr = net.Address(config.localAddr, config.localPort) remoteAddr = net.Address(config.serverAddr, config.serverPort) server = LsLocal( loop=loop, password=config.password, listenAddr=listenAddr, remoteAddr=remoteAddr) def didListen(address): print('Listen to %s:%d\n' % address) asyncio.ensure_future(server.listen(didListen)) loop.run_forever()
Example #3
Source File: index.py From rd-usb with GNU General Public License v3.0 | 5 votes |
def init(self): self.config = Config() self.storage = Storage()
Example #4
Source File: backend.py From rd-usb with GNU General Public License v3.0 | 5 votes |
def init(self): self.config = Config()
Example #5
Source File: backend.py From rd-usb with GNU General Public License v3.0 | 5 votes |
def run(self): self.storage = Storage() self.config = Config() self.interface = Wrapper() try: self.log("Connecting") self.retry(self.interface.connect) self.emit("connected") self.log("Connected") while self.running: data = self.retry(self.interface.read) self.log(json.dumps(data)) if data: data["name"] = self.config.read("name") self.update(data) self.storage.store_measurement(data) sleep(self.config.read("rate")) except (KeyboardInterrupt, SystemExit): raise except: logging.exception(sys.exc_info()[0]) self.emit("log", traceback.format_exc()) self.emit("log-error") finally: self.interface.disconnect() self.emit("disconnected") self.log("Disconnected") self.thread = None
Example #6
Source File: main.py From dialog-eval with MIT License | 5 votes |
def main(): config = Config() parser = argparse.ArgumentParser( description='Code for evaluating dialog models\' responses with ' + '17 evaluation metrics (arxiv.org/abs/1905.05471)') parser.add_argument('-tns', '--train_source', default=config.train_source, help='Path to the train source file, where each line ' + 'corresponds to one train input', metavar='') parser.add_argument('-tts', '--test_source', default=config.test_source, help='Path to the test source file, where each line ' + 'corresponds to one test input', metavar='') parser.add_argument('-ttt', '--test_target', default=config.test_target, help='Path to the test target file, where each line ' + 'corresponds to one test target', metavar='') parser.add_argument('-r', '--test_responses', default=config.test_responses, help='Path to the test model responses file', metavar='') parser.add_argument('-tv', '--text_vocab', default=config.text_vocab, help='A file where each line is a word in the vocab', metavar='') parser.add_argument('-vv', '--vector_vocab', default=config.vector_vocab, help='A file where each line is a word in the vocab ' + 'followed by a vector', metavar='') parser.add_argument('-s', '--bleu_smoothing', default=config.bleu_smoothing, help='Bleu smoothing method (choices: %(choices)s)', metavar='', choices=[0, 1, 2, 3, 4, 5, 6, 7]) parser.add_argument('-t', '--t', default=config.t, help='t value for confidence level calculation ' + '(default: %(default)s)', metavar='', type=int) parser.parse_args(namespace=config) m = Metrics(config) m.run()
Example #7
Source File: lsserver.py From lightsocks with MIT License | 5 votes |
def run_server(config: lsConfig.Config): loop = asyncio.get_event_loop() listenAddr = net.Address(config.serverAddr, config.serverPort) server = LsServer(loop=loop, password=config.password, listenAddr=listenAddr) def didListen(address): print('Listen to %s:%d\n' % address) print('Please use:\n') print('''lslocal -u "http://hostname:port/#''' f'''{dumpsPassword(config.password)}"''') print('\nto config lslocal') asyncio.ensure_future(server.listen(didListen)) loop.run_forever()
Example #8
Source File: web.py From rd-usb with GNU General Public License v3.0 | 4 votes |
def run(browser=True): port = 5000 if len(sys.argv) > 1: port = int(sys.argv[1]) app = Flask(__name__, static_folder=static_path) app.register_blueprint(Index().register()) logger = logging.getLogger() logger.setLevel(logging.INFO) formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s") console = StreamHandler() console.setLevel(logging.DEBUG) console.setFormatter(formatter) logger.addHandler(console) if not app.debug: file = TimedRotatingFileHandler(data_path + "/error.log", when="w0", backupCount=14) file.setLevel(logging.ERROR) file.setFormatter(formatter) logger.addHandler(file) try: config = Config() secret_key = config.read("secret_key") if not secret_key: secret_key = "".join(random.choice(string.ascii_uppercase + string.digits) for _ in range(16)) config.write("secret_key", secret_key) app.secret_key = secret_key Storage().init() sockets = socketio.Server() app.wsgi_app = socketio.Middleware(sockets, app.wsgi_app) sockets.register_namespace(Backend()) def open_in_browser(): logging.info("Application is starting...") url = "http://127.0.0.1:%s" % port while not url_ok(url): sleep(0.5) logging.info("Application is available at " + url) if not app.debug and browser: webbrowser.open(url) Thread(target=open_in_browser, daemon=True).start() app.run(host="0.0.0.0", port=port, threaded=True, use_reloader=False) except (KeyboardInterrupt, SystemExit): raise except: logging.exception(sys.exc_info()[0])
Example #9
Source File: LightheadRCNN_Learner.py From Lighthead-RCNN-in-Pytorch0.4.1 with MIT License | 4 votes |
def __init__(self, training=True): super(LightHeadRCNN_Learner, self).__init__() self.conf = Config() self.class_2_color = get_class_colors(self.conf) self.rpn = RegionProposalNetwork().to(self.conf.device) self.loc_normalize_mean=(0., 0., 0., 0.), self.loc_normalize_std=(0.1, 0.1, 0.2, 0.2) self.head = LightHeadRCNNResNet101_Head(self.conf.class_num + 1, self.conf.roi_size).to(self.conf.device) self.class_2_color = get_class_colors(self.conf) self.detections = namedtuple('detections', ['roi_cls_locs', 'roi_scores', 'rois']) if training: self.extractor = ResNet101Extractor(self.conf.pretrained_model_path).to(self.conf.device) self.train_dataset = coco_dataset(self.conf, mode = 'train') self.train_length = len(self.train_dataset) self.val_dataset = coco_dataset(self.conf, mode = 'val') self.val_length = len(self.val_dataset) self.anchor_target_creator = AnchorTargetCreator() self.proposal_target_creator = ProposalTargetCreator(loc_normalize_mean = self.loc_normalize_mean, loc_normalize_std = self.loc_normalize_std) self.step = 0 self.optimizer = SGD([ {'params' : get_trainables(self.extractor.parameters())}, {'params' : self.rpn.parameters()}, {'params' : [*self.head.parameters()][:8], 'lr' : self.conf.lr*3}, {'params' : [*self.head.parameters()][8:]}, ], lr = self.conf.lr, momentum=self.conf.momentum, weight_decay=self.conf.weight_decay) self.base_lrs = [params['lr'] for params in self.optimizer.param_groups] self.warm_up_duration = 5000 self.warm_up_rate = 1 / 5 self.train_outputs = namedtuple('train_outputs', ['loss_total', 'rpn_loc_loss', 'rpn_cls_loss', 'ohem_roi_loc_loss', 'ohem_roi_cls_loss', 'total_roi_loc_loss', 'total_roi_cls_loss']) self.writer = SummaryWriter(self.conf.log_path) self.board_loss_every = self.train_length // self.conf.board_loss_interval self.evaluate_every = self.train_length // self.conf.eval_interval self.eva_on_coco_every = self.train_length // self.conf.eval_coco_interval self.board_pred_image_every = self.train_length // self.conf.board_pred_image_interval self.save_every = self.train_length // self.conf.save_interval # only for debugging # self.board_loss_every = 5 # self.evaluate_every = 6 # self.eva_on_coco_every = 7 # self.board_pred_image_every = 8 # self.save_every = 10 else: self.extractor = ResNet101Extractor().to(self.conf.device)