def get_classes(): logging.info(Config.get_var("class.names")) return jsonify({ "classNames": Config.get_var("class.names"), "classColors": Config.get_var("class.colors"), "minHeight": Config.get_var("min_height"), "minWidth": Config.get_var("min_width") })
def test_load_conf_os_env(self, mock_args): Config.clear() Config.define_bool("VaR", False, "turn me true") Config.define_int("v1", 0, "var") Config.define_int("nm.v2", 0, "var") Config.load_conf() self.assertEqual(Config.get_var("v1"), 1) self.assertEqual(Config.get_var("nm.v2"), 2) self.assertEqual(Config.get_var("VAr"), True)
def main(): global image_provider Config.load_conf() image_provider = ImageProvider() # Write txt file containing class info with open( os.path.join(Config.get_var("human_annotations_path"), "class_names.txt"), "w") as f: f.write(','.join(Config.get_var("class.names"))) app.run(host='0.0.0.0', threaded=True)
def set_image(): message = flask.request.get_json() logging.info(message) for shape in message["detectedObjects"]: assert shape["class"] in Config.get_var("class.names") json_name = os.path.splitext(os.path.split( message['imageSrc'])[1])[0] + ".json" with open( os.path.join(Config.get_var("human_annotations_path"), json_name), 'w') as outfile: json.dump({"rectangles": message["detectedObjects"]}, outfile) return "ok"
def __init__(self): """class providing path of images to process """ # user-provided attributes self.images_path = Config.get_var("images_path") self.human_annotations_path = Config.get_var("human_annotations_path") self.model_annotations_path = Config.get_var("model_annotations_path") # other attributes self.lock = threading.Lock() self.current_image = 0 # Handle paths assert os.path.exists(self.images_path) os.makedirs(self.human_annotations_path, exist_ok=True) if self.model_annotations_path: os.makedirs(self.model_annotations_path, exist_ok=True) # Handle lists self.images_list = os.listdir(self.images_path) self.human_annotations_list = os.listdir(self.human_annotations_path) if self.model_annotations_path: self.model_annotations_list = os.listdir( self.model_annotations_path) else: self.model_annotations_list = [] logging.info(f"there are {len(self.images_list)} images in total") # Only keep images that where not yet processed new_list = [] human_annotation_ids = [ os.path.splitext(file_name)[0] for file_name in self.human_annotations_list ] for image_name in self.images_list: image_id, _ = os.path.splitext(image_name) if image_id not in human_annotation_ids: new_list.append(image_name) self.images_list = new_list logging.info(f"there are {len(self.images_list)} images to annotate") self.images_list.sort() self.n_images = len(self.images_list)
def test_load_conf_cmd(self, mock_args): Config.clear() Config.define_bool("VaR", False, "turn me true") Config.define_int("v1", 1, "var") Config.define_int("v2", 2, "var") Config.define_float_list("list", [5., 6, "7."], "A test for list") with Config.namespace("n1"): Config.define_int("v1", 1, "var") Config.define_int("v2", 2, "var") Config.define_bool("V3", True, "turn me false") Config.load_conf() self.assertEqual(Config.get_var("v1"), 2) self.assertEqual(Config.get_var("v2"), 3) self.assertEqual(Config.get_var("n1.v1"), 2) self.assertEqual(Config.get_var("n1.v2"), 3) self.assertEqual(Config.get_var("n1.v3"), False) self.assertEqual(Config.get_var("VAr"), True) self.assertEqual(Config.get_var("list"), [1.0, 2.0, 3.0])