action='store_true', default=False) parser.add_argument('--use_batch_norm', action='store_true', default=False) args = parser.parse_args() current_model = args.model num_epoch = args.num_epoch batch_size = args.batch_size optimizer = args.optimizer lr = args.lr embedding_trainable = args.embedding_trainable use_batch_norm = args.use_batch_norm config = Config('./', current_model, num_epoch=num_epoch, batch_size=batch_size, optimizer=optimizer, lr=lr, embedding_trainable=embedding_trainable, use_batch_norm=use_batch_norm) os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' os.environ['CUDA_VISIBLE_DEVICES'] = '0' config_proto = tf.ConfigProto( allow_soft_placement=True) # 创建配置,允许将无法放入GPU的操作放在CUP上执行 config_proto.gpu_options.allow_growth = True # 运行时动态增加内存使用量 judger = Judger(config.accu_dict, config.art_dict) def save_result(outputs, result_file, id_2_accu, id_2_art): task_1_output, task_2_output, task_3_output = outputs
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--config', help='name of config file in the checkpoint path') parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument( '--model', type=int, choices=[1, 2, 3, 4], help= '1: edge model, 2: inpaint model, 3: edge-inpaint model, 4: joint model' ) parser.add_argument('--gpu', type=int, nargs='+') # test mode if mode == 2: parser.add_argument( '--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') parser.add_argument('--edge', type=str, help='path to the edges directory or an edge file') parser.add_argument('--output', type=str, help='path to the output directory') args = parser.parse_args() if args.config is None: config_path = os.path.join(args.path, 'config.yml') else: config_path = args.config # create checkpoints path if does't exist if not os.path.exists(args.path): os.makedirs(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) if args.config is not None: config.PATH = args.path if args.gpu is not None: config.GPU = args.gpu # train mode if mode == 1: config.MODE = 1 if args.model: config.MODEL = args.model # test mode elif mode == 2: config.MODE = 2 config.MODEL = args.model if args.model is not None else 3 config.INPUT_SIZE = 0 if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.edge is not None: config.TEST_EDGE_FLIST = args.edge if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 config.MODEL = args.model if args.model is not None else 3 return config
import cv2 import pandas as pd import numpy as np from src.config import Config from src.kpda_parser import KPDA from src.utils import draw_keypoint_with_caption if __name__ == '__main__': config = Config('blouse') test_kpda = KPDA(config, config.data_path, 'test') df = pd.read_csv(config.proj_path + 'kp_predictions/' + config.clothes + '.csv') for idx in range(3): img_path = test_kpda.get_image_path(idx) img0 = cv2.imread(img_path) # BGR row = test_kpda.anno_df.iloc[idx] row2 = df[df['image_id'] == row['image_id']].T.squeeze() hps = [] for k, v in row2.iteritems(): if k in ['image_id', 'image_category'] or v.split('_')[2] == '-1': continue x = int(v.split('_')[0]) y = int(v.split('_')[1]) image = draw_keypoint_with_caption(img0, [x, y], k) hps.append(image) cv2.imwrite('/home/storage/lsy/fashion/tmp/%d.png' % idx, np.concatenate(hps, axis=1))
source: https://github.com/Birdback/manage.py see also: requirements_manager.txt """ from manager import Manager from datetime import datetime, timedelta import subprocess from src.repository.factory import RepositoryFactory from src.repository.misc import SearchScope from src.config import Config from src.constants import CONFIGFILE from src.expression.builder import ExpressionBuilder Config().setup( os.path.join(BASEDIR, CONFIGFILE), BASEDIR ) pidfile = os.path.join(BASEDIR, 'tamandua.pid') manager = Manager() global cleanupPID cleanupPID = True def exit_if_already_running(): if os.path.exists(pidfile): print('There is already a tamandua process running. Exiting.') global cleanupPID cleanupPID = False
# -*- coding: utf-8 -*- import unittest from unittest import TestCase import torch as t from torch.utils.data.dataloader import DataLoader from src.dataset import Shanghai from src.config import Config opts = Config() class DatasetTest(TestCase): def test_dataset(self): shanghai = Shanghai(opts.data_dir, train=True) dataloader = DataLoader(shanghai, batch_size=1, shuffle=True, num_workers=2) for i, (data, labels) in enumerate(dataloader): print(i, labels[0].sum())
def main(): # create instance of config config = Config() assert config.data_keyname == 'pico' config.num_augmentation = 0 config.batch_size = 20 config.batch_size_aug = 20 config.dir_output = 'test-num_augmentation-{}'.format( config.num_augmentation) config.dir_model = os.path.join(config.dir_output, "model.weights") config.data_root = '../data/{}/10_folds'.format(config.data_keyname) result_file_path = os.path.join(config.dir_output, 'cross_validate_results') precisions = {'P': [], 'I': [], 'O': []} recalls = {'P': [], 'I': [], 'O': []} f1s = {'P': [], 'I': [], 'O': []} for fold in range(1, 11): # build model # tf.reset_default_graph() print('Fold {}'.format(fold)) # build model model = HANNModel(config) model.build() # if config.restore: # model.restore_session("results/test/model.weights/") # optional, restore weights # model.reinitialize_weights("proj") # create datasets train = Dataset(os.path.join(config.data_root, str(fold), 'train.txt'), config.processing_word, config.processing_tag) dev = Dataset(os.path.join(config.data_root, str(fold), 'dev.txt'), config.processing_word, config.processing_tag) test = Dataset(os.path.join(config.data_root, str(fold), 'test.txt'), config.processing_word, config.processing_tag) if config.num_augmentation: data_aug = Dataset(config.filename_aug, config.processing_word, max_iter=config.num_augmentation) else: data_aug = None # train model model.train(train, dev, data_aug) # evaluate model model.restore_session(config.dir_model) metrics = model.evaluate(test) [ precisions[tag].append(metrics['precision'][tag]) for tag in ['P', 'I', 'O'] ] [ recalls[tag].append(metrics['recall'][tag]) for tag in ['P', 'I', 'O'] ] [f1s[tag].append(metrics['f1'][tag]) for tag in ['P', 'I', 'O']] msg = 'fold: {}\tprecision: {}\trecall: {}\tf1: {}\n'.format( fold, metrics['precision'], metrics['recall'], metrics['f1']) print(msg) with open(result_file_path, 'a') as ofile: ofile.write(msg) # print('Precision: ', 'P: ', (precisions['P']), 'I: ', (precisions['I']), 'O: ', (precisions['O'])) # print('Recall: ', 'P: ', (recalls['P']), 'I: ', (recalls['I']), 'O: ', (recalls['O'])) # print('F1: ', 'P: ', (f1s['P']), 'I: ', (f1s['I']), 'O: ', (f1s['O'])) # print('Precision: ', 'P: ', np.mean(precisions['P']), 'I: ', np.mean(precisions['I']), 'O: ', np.mean(precisions['O'])) # print('Recall: ', 'P: ', np.mean(recalls['P']), 'I: ', np.mean(recalls['I']), 'O: ', np.mean(recalls['O'])) # res = np.mean([np.mean(values) for values in f1s.values()]) # print('F1: ', 'P: ', np.mean(f1s['P']), 'I: ', np.mean(f1s['I']), 'O: ', np.mean(f1s['O']), 'all avg: ', res) msg = 'Average Precision: P: {}\tI: {}\tO: {}\n'.format( np.mean(precisions['P']), np.mean(precisions['I']), np.mean(precisions['O'])) print(msg) with open(result_file_path, 'a') as ofile: ofile.write(msg) msg = 'Average Recall: P: {}\tI: {}\tO: {}\n'.format( np.mean(recalls['P']), np.mean(recalls['I']), np.mean(recalls['O'])) print(msg) with open(result_file_path, 'a') as ofile: ofile.write(msg) res = np.mean([np.mean(values) for values in f1s.values()]) msg = 'Average F1: P: {}\tI: {}\tO: {}\tall: {}\n'.format( np.mean(f1s['P']), np.mean(f1s['I']), np.mean(f1s['O']), res) print(msg) with open(result_file_path, 'a') as ofile: ofile.write(msg) ofile.write('\n\n\n')
def test_env_has_secondaly_highest_priority(self): os.environ['EDITOR'] = 'ENV EDITOR' self.assertEqual( os.getenv('EDITOR'), EditorDetector(Config({}), SubProcessRunner()).detect())
import sys from src.config import Config from src.TinyImageNet import ImageNet if len(sys.argv) < 4: print( "Usage: python DataProcessor.py [type] [source_data_path] [output_base_path]" ) exit(1) config = Config(sys.argv) Container = ImageNet(config) Container.process()
def __init__(self, link): conf = Config() self.api_key = conf.get_api() self.youtube = build('youtube', 'v3', developerKey=self.api_key) self.link = link
def setUp(self) -> None: self.config = Config()
from src.config import Config from src import models, trainer, dataset, transforms, utils config = Config().get_yaml() utils.set_random_seeds(config.get("seed"))
stride=1, padding=0)) def forward(self, p2, p3, p4, p5): p2 = self.bottleneck2(p2) p3 = self.bottleneck3(p3) p4 = self.bottleneck4(p4) p5 = self.bottleneck5(p5) return self.output(torch.cat([p2, p3, p4, p5], dim=1)) class CascadePyramidNetV4(nn.Module): def __init__(self, config): super(CascadePyramidNetV4, self).__init__() self.global_net = GlobalNet(config) self.refine_net = RefineNet(config) def forward(self, x): p2, p3, p4, p5 = self.global_net(x) out = self.refine_net(p2, p3, p4, p5) return p2, out if __name__ == '__main__': import torch from torch.autograd import Variable from src.config import Config config = Config('outwear') net = CascadePyramidNetV4(config) fms = net(Variable(torch.randn(1, 3, 512, 512)))
def setUp(self) -> None: self.mother = np.ones((4, 2)) self.image = cv2.imread(os.path.join(Config().path_data, "test", "test_flower.jpg")) random.seed(1234)
def __init__(self): self.config = Config()
label_size = len(train_dataset.label2idx) #precisa chamar pra instanciar uns atributos, por mais que nao va usar elmo embeddings test_dataset.convert_instances_to_feature_tensors(word2idx=word2idx, char2idx=char2idx, elmo_vecs=None) #se nao me engano isso ja pode ser passado para o model test_dataloader = DataLoader(test_dataset, shuffle=False, num_workers=num_workers, collate_fn=test_dataset.collate_fn) parser = argparse.ArgumentParser(description="LSTM CRF implementation") opt = parse_arguments(parser) conf = Config(opt) conf.build_emb_table(word2idx=word2idx) #carregando modelo folder_name = opt.model_path f = open(folder_name + "/config.conf", 'rb') model = NNCRF(pickle.load(f)) model.load_state_dict( torch.load(folder_name + "/lstm_crf.m", map_location="cpu")) model.eval() batch_size = test_dataloader.batch_size #avaliando
def main(): parser = argparse.ArgumentParser() parser.add_argument("-c", "--config", help="Device config") parser.add_argument("-t", "--test", help="Testmode", action="store_true") parser.add_argument("-w", "--watchdog", help="Watchdog address(in hex) for testmode") parser.add_argument("-v", "--var_1", help="var_1 value(in hex) for testmode") parser.add_argument("-p", "--payload_address", help="payload_address value(in hex) for testmode") arguments = parser.parse_args() if arguments.config: if not os.path.exists(arguments.config): raise RuntimeError("Config file {} doesn't exist".format(arguments.config)) elif not os.path.exists(DEFAULT_CONFIG): raise RuntimeError("Default config is missing") device = Device().find() device.handshake() hw_code = device.get_hw_code() hw_sub_code, hw_ver, sw_ver = device.get_hw_dict() secure_boot, serial_link_authorization, download_agent_authorization = device.get_target_config() if arguments.config: config_file = open(arguments.config) config = Config().from_file(config_file, hw_code) config_file.close() else: try: config = Config().default(hw_code) except NotImplementedError as e: if arguments.test: config = Config() if arguments.var_1: config.var_1 = int(arguments.var_1, 16) if arguments.watchdog: config.watchdog_address = int(arguments.watchdog, 16) if arguments.payload_address: config.payload_address = int(arguments.payload_address, 16) config.payload = "generic_dump_payload.bin" log(e) else: raise e if not os.path.exists(PAYLOAD_DIR + config.payload): raise RuntimeError("Payload file {} doesn't exist".format(PAYLOAD_DIR + config.payload)) print() log("Device hw code: {}".format(hex(hw_code))) log("Device hw sub code: {}".format(hex(hw_sub_code))) log("Device hw version: {}".format(hex(hw_ver))) log("Device sw version: {}".format(hex(sw_ver))) log("Device secure boot: {}".format(secure_boot)) log("Device serial link authorization: {}".format(serial_link_authorization)) log("Device download agent authorization: {}".format(download_agent_authorization)) print() log("Disabling watchdog timer") device.write32(config.watchdog_address, 0x22000064) if serial_link_authorization or download_agent_authorization: log("Disabling protection") with open(PAYLOAD_DIR + config.payload, "rb") as payload: payload = payload.read() result = exploit(device, config.watchdog_address, config.payload_address, config.var_0, config.var_1, payload) if arguments.test: while not result: device.dev.close() config.var_1 += 1 log("Test mode, testing " + hex(config.var_1) + "...") device = Device().find() device.handshake() result = exploit(device, config.watchdog_address, config.payload_address, config.var_0, config.var_1, payload) bootrom__name = "bootrom_" + hex(hw_code)[2:] + ".bin" if result == to_bytes(0xA1A2A3A4, 4): log("Protection disabled") elif result == to_bytes(0xC1C2C3C4, 4): dump_brom(device, bootrom__name) elif result == to_bytes(0x0000C1C2, 4) and device.read(4) == to_bytes(0xC1C2C3C4, 4): dump_brom(device, bootrom__name, True)
def main(): if not Path(GLOBAL.defaultConfigDirectory).is_dir(): os.makedirs(GLOBAL.defaultConfigDirectory) if Path("config.json").exists(): GLOBAL.configDirectory = Path("config.json") else: GLOBAL.configDirectory = GLOBAL.defaultConfigDirectory / "config.json" try: GLOBAL.config = Config(GLOBAL.configDirectory).generate() except InvalidJSONFile as exception: VanillaPrint(str(exception.__class__.__name__), ">>", str(exception)) VanillaPrint("Resolve it or remove it to proceed") input("\nPress enter to quit") sys.exit() sys.argv = sys.argv + GLOBAL.config["options"].split() arguments = Arguments.parse() GLOBAL.arguments = arguments if arguments.set_filename: Config(GLOBAL.configDirectory).setCustomFileName() sys.exit() if arguments.set_folderpath: Config(GLOBAL.configDirectory).setCustomFolderPath() sys.exit() if arguments.set_default_directory: Config(GLOBAL.configDirectory).setDefaultDirectory() sys.exit() if arguments.set_default_options: Config(GLOBAL.configDirectory).setDefaultOptions() sys.exit() if arguments.use_local_config: JsonFile(".\\config.json").add(GLOBAL.config) sys.exit() if arguments.directory: GLOBAL.directory = Path(arguments.directory.strip()) elif "default_directory" in GLOBAL.config and GLOBAL.config[ "default_directory"] != "": GLOBAL.directory = Path( GLOBAL.config["default_directory"].format(time=GLOBAL.RUN_TIME)) else: GLOBAL.directory = Path(input("\ndownload directory: ").strip()) if arguments.downloaded_posts: GLOBAL.downloadedPosts = Store(arguments.downloaded_posts) else: GLOBAL.downloadedPosts = Store() printLogo() print("\n", " ".join(sys.argv), "\n", noPrint=True) if arguments.log is not None: logDir = Path(arguments.log) download(postFromLog(logDir)) sys.exit() programMode = ProgramMode(arguments).generate() try: posts = getPosts(programMode) except Exception as exc: logging.error(sys.exc_info()[0].__name__, exc_info=full_exc_info(sys.exc_info())) print(GLOBAL.log_stream.getvalue(), noPrint=True) print(exc) sys.exit() if posts is None: print("I could not find any posts in that URL") sys.exit() if GLOBAL.arguments.no_download: pass else: download(posts)
def main(argv): config = Config() # Get options and arguments try: opts, args = getopt.getopt( argv, 'hsn:a:p:v', ['help', 'shutdown', 'nmyo', 'address', 'port', 'verbose']) except getopt.GetoptError: sys.exit(2) turnoff = False for opt, arg in opts: if opt in ('-h', '--help'): print_usage() sys.exit() elif opt in ('-s', '--shutdown'): turnoff = True elif opt in ("-n", "--nmyo"): config.MYO_AMOUNT = int(arg) elif opt in ("-a", "--address"): config.OSC_ADDRESS = arg elif opt in ("-p", "--port"): config.OSC_PORT = arg elif opt in ("-v", "--verbose"): config.VERBOSE = True # Run myo_driver = None try: # Init myo_driver = MyoDriver(config) # Connect myo_driver.run() if turnoff: # Turn off myo_driver.deep_sleep_all() return if Config.GET_MYO_INFO: # Get info myo_driver.get_info() print("Ready for data.") print() # Receive and handle data while True: myo_driver.receive() except KeyboardInterrupt: print("Interrupted.") except serial.serialutil.SerialException: print( "ERROR: Couldn't open port. Please close MyoConnect and any program using this serial port." ) finally: print("Disconnecting...") if myo_driver is not None: if Config.DEEP_SLEEP_AT_KEYBOARD_INTERRUPT: myo_driver.deep_sleep_all() else: myo_driver.disconnect_all() print("Disconnected")
def test_config_is_prior_to_others(self): config_editor = 'configured editor' config = Config({'editor': config_editor}) detector = EditorDetector(config, SubProcessRunner()) self.assertEqual(config_editor, detector.detect())
from torchFewShot.losses import CrossEntropyLoss from torchFewShot.optimizers import init_optimizer import transforms as T from torchFewShot.utils.iotools import save_checkpoint, check_isfile from torchFewShot.utils.avgmeter import AverageMeter from torchFewShot.utils.logger import Logger from torchFewShot.utils.torchtools import one_hot, adjust_learning_rate sys.path.append('/home/lijunjie/edge-connect-master') from shutil import copyfile from src.config import Config from src.edge_connect_few_shot import EdgeConnect #config = load_config(mode) config_path = os.path.join('/home/lijunjie/edge-connect-master/checkpoints/places2_authormodel', 'config.yml') config = Config(config_path) config.TEST_FLIST = '/home/lijunjie/edge-connect-master/examples/test_result/' config.TEST_MASK_FLIST = '/home/lijunjie/edge-connect-master/examples/places2/masks' config.RESULTS = './checkpoints/EC_test' config.MODE = 2 if config.MODE == 2: config.MODEL = 3 config.INPUT_SIZE = 0 config.mask_id=2 #if args.input is not None: #config.TEST_FLIST = args.input #if args.mask is not None: #config.TEST_MASK_FLIST = args.mask #if args.edge is not None:
def test_vi_path_is_returnd_if_neigther_of_config_nor_env_exists(self): os.environ.pop('EDITOR') self.assertEqual( subprocess.check_output(['which', 'vi']).decode().strip(), EditorDetector(Config({}), SubProcessRunner()).detect())
help='one cloth type', default='outwear') args = parser.parse_args(sys.argv[1:]) print('Training ' + args.clothes) batch_size = 32 workers = 16 n_gpu = pytorch_utils.setgpu('0,1') epochs = 100 base_lr = 1e-2 # SGD L1 loss starts from 1e-2, L2 loss starts from 1e-3 save_dir = root_path + 'checkpoints/' if not os.path.exists(save_dir): os.mkdir(save_dir) resume = False config = Config(args.clothes) net = CascadePyramidNetV2(config) loss = VisErrorLossV2() train_data = KPDA(config, db_path, 'train') val_data = KPDA(config, db_path, 'val') print('Train sample number: %d' % train_data.size()) print('Val sample number: %d' % val_data.size()) start_epoch = 1 lr = base_lr best_val_loss = float('inf') log_mode = 'w' if resume: checkpoint = torch.load(save_dir + 'kpt_outwear_030.ckpt') start_epoch = checkpoint['epoch'] + 1 lr = checkpoint['lr']
def lambda_handler(event, context): ## ## Extract the request and pretty URI ## from the event. ## request = event['Records'][0]['cf']['request'] pretty_uri = request['uri'] ## ## If this is an echo request, just return ## the given request (for debugging). ## if pretty_uri == '/echo': response = { 'status': 200, 'body': json.dumps(request), } return response ## ## If this is a login request, set the appropriate user cookie. ## match = re.search(r'^/login/(\w+)$', pretty_uri) if match: user_cookie = match.group(1) response = { 'status': 200, 'headers': { 'Set-COOKIE': [{ 'key': 'Set-COOKIE', 'value': 'user={}; Path=/'.format(user_cookie) }] }, 'body': json.dumps('logged in as {}'.format(user_cookie)) } return response ## ## If this is a logout request, clear the user cookie. ## if pretty_uri == '/logout': expires = datetime.datetime.utcnow() + datetime.timedelta(days=-1) expires_str = expires.strftime("%a, %d %b %Y %H:%M:%S GMT") response = { 'status': 200, 'headers': { 'Set-COOKIE': [{ 'key': 'Set-COOKIE', 'value': 'user=deleted; Path=/; Expires={}'.format(expires_str) }] }, 'body': json.dumps('logged out') } return response ## ## Extract the relevant cookies from the request. ## cookies = parseCookies(request['headers']) user_cookie = cookies.get('user', 'anonymous') diversion_cookie = cookies.get('diversion', None) ## ## If the user does NOT have a diversion cookie, ## send them to the diversion page. Also add ## a custom header to indicate to the viewer ## response lambda function that a diversion ## cookie should be added. ## if diversion_cookie is None: request['uri'] = '/diversion/diversion_page.html' request['headers']['openstax-add-diversion'] = [{ 'key': 'Openstax-Add-Diversion', 'value': 'do-it-NOW!' }] return request ## ## Connect to DynamoDb and look up the ## current configuration. ## config = Config( region_name='us-east-1', table_name='kevin-pdfdistro-configs', ) ## ## Keep mapping uris until we reach a final, ## ugly behind-the-scenes one. ## ## If we couldn't find an explicit ugly uri, ## return File Not Found (404) ## ugly_uri = config.get_ugly_uri(pretty_uri) if ugly_uri is None: response = {'status': 404, 'body': json.dumps("Ain't no Thang!")} return response ## ## Check the permissions on the ugly uri, ## and return a Permission Denied (403) ## if appropriate. ## if not config.access_is_allowed(user=user_cookie, ugly_uri=ugly_uri): response = {'status': 403, 'body': json.dumps("Oh no you didn't!")} return response ## ## Adjust the uri and forward the request. ## request['uri'] = ugly_uri return request
def out_of_bounds(self) -> bool: return self.rect.top < 0 or self.rect.right > Config( ).width or self.rect.bottom > Config().height or self.rect.left < 0
if __name__ == "__main__": runtime = time.gmtime() timestamp = runtime.tm_mday.__str__() + '_' + runtime.tm_mon.__str__() + '_' + runtime.tm_year.__str__() + '-' + \ runtime.tm_hour.__str__() + '_' + runtime.tm_min.__str__() + '_' + runtime.tm_sec.__str__() parser = argparse.ArgumentParser() parser.add_argument('--data_prefix', help='data prefix') args = parser.parse_args() print("Running experiment with prefix:" + args.data_prefix) # generate_model_data_elmo(data_prefix=args.data_prefix) #only for first run config = Config() if args.data_prefix: cwd = os.getcwd() config.filename_dev = os.path.join( cwd, 'data', args.data_prefix + '_' + os.path.basename(config.filename_dev)) config.filename_test = os.path.join( cwd, 'data', args.data_prefix + '_' + os.path.basename(config.filename_test)) config.filename_train = os.path.join( cwd, 'data', args.data_prefix + '_' + os.path.basename(config.filename_train)) if config.use_elmo_and_words: dev = CoNLLDataset(config.filename_dev,
import sqlite3 #SQLite DB from src.config import Config #Config load configInformation = Config() scanNameList = configInformation.getTenableScanName() connection = sqlite3.connect(r"..\databases\Tenable_DB.db") cursor = connection.cursor() cursor.execute("SELECT name from sqlite_master WHERE type='table';") tableList = [] flag = False for table in cursor.fetchall(): tableList.append(str(table[0])) for scanName in scanNameList: scanName = scanName.replace("-", "_") #char sensitivity history = scanName + "_HISTORY" map = scanName + "_MAP" if history not in tableList: print("Creating Table:", history) cursor.execute("CREATE TABLE " + history + " (\ Scan_Date DATE PRIMARY KEY,\ Scan_Status BOOLEAN,\ Tickets_Created BOOLEAN\ );") flag = True if map not in tableList: print("Creating Table:", map) cursor.execute("CREATE TABLE " + map + " (\ Scan_Date DATE,\ Host TEXT,\ Name TEXT,\
def load_config(mode=None): r"""loads model config Args: mode (int): 1: train, 2: test, 3: eval, reads from config file if not specified """ parser = argparse.ArgumentParser() parser.add_argument('--path', '--checkpoints', type=str, default='./checkpoints', help='model checkpoints path (default: ./checkpoints)') parser.add_argument('--output', type=str, default='./output', help='path to the output directory') # test mode if mode == 2: parser.add_argument( '--input', type=str, help='path to the input images directory or an input image') parser.add_argument('--mask', type=str, help='path to the masks directory or a mask file') args = parser.parse_args() config_path = os.path.join(args.path, 'config.yml') # create checkpoints path if does't exist create_dir(args.path) # copy config template if does't exist if not os.path.exists(config_path): copyfile('./config.yml.example', config_path) # load config file config = Config(config_path) # train mode if mode == 1: config.MODE = 1 # test mode elif mode == 2: config.MODE = 2 # config.INPUT_SIZE = 0 Set to 0 for one to one mapping if args.input is not None: config.TEST_FLIST = args.input if args.mask is not None: config.TEST_MASK_FLIST = args.mask if args.output is not None: config.RESULTS = args.output # eval mode elif mode == 3: config.MODE = 3 return config
parser.add_argument('--do_train', action='store_true', default=False) parser.add_argument('--do_eval', action='store_true', default=False) parser.add_argument('--do_test', action='store_true', default=False) parser.add_argument('--epoch', type=int, default=30) parser.add_argument('--batch', type=int, default=32) parser.add_argument('--optimizer', type=str, default='Adam') parser.add_argument('--lr', type=float, default=1e-3) parser.add_argument('--model_file', type=str) parser.add_argument('--log_steps', type=int, default=10) parser.add_argument('--save_steps', type=int, default=100) parser.add_argument('--pre_train_epochs', type=int, default=4) parser.add_argument('--early_stop', action='store_true', default=False) args = parser.parse_args() config = Config('.', args.model, num_epoch=args.epoch, batch_size=args.batch, optimizer=args.optimizer, lr=args.lr) # os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' # os.environ['CUDA_VISIBLE_DEVICES'] = '' sess_config = tf.ConfigProto(allow_soft_placement=True) sess_config.gpu_options.allow_growth = True def save_result(predicted_ids, alignment_history, id_2_label, input_file, output_file): src_inputs = [] with open(input_file, 'r', encoding='utf-8') as fin: for line in fin: line = WikiEntity(line) box = line.get_box() if len(box) == 0:
def __init__(self, country_code): self._config = Config() self._event_manager = EventsManager(self._config, country_code) self._processor = EventProcessor(self._event_manager)
async def get_test_engine(): c = Config() c.with_environment() engine = await init_database(c) return engine