def download_pretrained_weights(weight_path): # download if not exist if not exists(weight_path): print("File yolov3.weights not exist. Downloading now.") weight_url = "https://pjreddie.com/media/files/yolov3.weights" r = PoolManager().request('GET', weight_url) with open(weight_path, 'wb') as f: f.write(r.data) r.release_conn() print("File yolov3.weights downloaded.") return weight_path
def load_class_names(class_name_path): # download if not exist if not exists(class_name_path): print("File coco.names not exist. Downloading now.") class_name_url = "https://raw.githubusercontent.com/ayooshkathuria/YOLO_v3_tutorial_from_scratch/master/data/coco.names" r = PoolManager().request('GET', class_name_url) with open(class_name_path, 'wb') as f: f.write(r.data) r.release_conn() print("File coco.names downloaded.") f = open(class_name_path, "r") class_names = f.read().split("\n")[:-1] return class_names
def parse_config(config_path): """ Check if configuration file exist, and download if not. Parse the configuration file and return a list. :param config_path: path of configuration file :return config: a list containing dicts, each dict is a config block """ # download if not exist if not exists(config_path): print("File yolov3.cfg not exist. Downloading now.") config_url = "https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg" r = PoolManager().request('GET', config_url) with open(config_path, 'wb') as f: f.write(r.data) r.release_conn() print("File yolov3.cfg downloaded.") # preprocess config file config_file = open(config_path, 'r') lines = config_file.read().split('\n') filtered_lines = [] for line in lines: # remove empty lines, space lines, and comment lines, and remove space in lines if len(line) == 0 or line.isspace() is True or line[0] == '#': continue filtered_lines.append(line.replace(' ', '')) # parse config config = [] for line in filtered_lines: if line[0] == '[': # new block starts config.append({}) block = config[-1] block['type'] = line[1:-1] else: key, value = line.split('=') block[key] = value # by default the height and width are supposed to be equal if config[0]['width'] != config[0]['height']: print( "By default 'height' and 'width' in configuration should be same, " "and image will be resize to height x height in this case.") if int(config[0]['width']) != 416 or int(config[0]['height']) != 416: print( "To match with the paper both 'height' and 'width' are recommended to be 416. Current values are {}, {}." .format(int(config[0]['width']), int(config[0]['height']))) return config
def download(filename: str) -> None: """ Downloads a file from the git repo and saves it to the local directory. :param filename: The filename to download from the repo. :type filename: `str` """ url = 'https://raw.githubusercontent.com/threadreaper/autodomme/master/' r = PoolManager().request('GET', url + filename, preload_content=False) with open(filename, 'wb') as out: while True: data = r.read(512) if not data: break out.write(data) r.release_conn()
def generate(salt): if not salt: return None render(config_file, 'salt-minion/minion.tmpl', salt, user=salt['user'], group=salt['group']) if not os.path.exists(master_keyfile): if salt['master_key']: req = PoolManager().request('GET', salt['master_key'], preload_content=False) with open(master_keyfile, 'wb') as f: while True: data = req.read(1024) if not data: break f.write(data) req.release_conn() chown(master_keyfile, salt['user'], salt['group']) return None