diff --git a/.gitignore b/.gitignore index da0ec900..40868fda 100644 --- a/.gitignore +++ b/.gitignore @@ -28,6 +28,7 @@ share/python-wheels/ .installed.cfg *.egg MANIFEST +.gptexecthread # PyInstaller # Usually these files are written by a python script from a template diff --git a/roboflow/adapters/rfapi.py b/roboflow/adapters/rfapi.py index 638aebda..83407423 100644 --- a/roboflow/adapters/rfapi.py +++ b/roboflow/adapters/rfapi.py @@ -1,6 +1,6 @@ import os import urllib - +import json import requests from requests_toolbelt.multipart.encoder import MultipartEncoder @@ -83,6 +83,7 @@ def save_annotation( annotation_string: str, image_id: str, is_prediction: bool = False, + annotation_labelmap=None, ): """ Upload an annotation to a specific project. @@ -98,8 +99,8 @@ def save_annotation( response = requests.post( upload_url, - data=annotation_string, - headers={"Content-Type": "text/plain"}, + data=json.dumps({"data": annotation_string, "labelmap": annotation_labelmap}), + headers={"Content-Type": "application/json"}, ) responsejson = None try: diff --git a/roboflow/core/project.py b/roboflow/core/project.py index 2e963d2a..bc7b629b 100644 --- a/roboflow/core/project.py +++ b/roboflow/core/project.py @@ -465,6 +465,7 @@ def single_upload( self, image_path=None, annotation_path=None, + annotation_labelmap=None, hosted_image=False, image_id=None, split="train", @@ -506,6 +507,7 @@ def single_upload( annotation_str, image_id, is_prediction=is_prediction, + annotation_labelmap=annotation_labelmap, ) except BaseException as e: uploaded_annotation = {"error": e} diff --git a/roboflow/core/workspace.py b/roboflow/core/workspace.py index a85c0c8e..a2000af9 100644 --- a/roboflow/core/workspace.py +++ b/roboflow/core/workspace.py @@ -374,9 +374,13 @@ def _upload_image(imagedesc): annotationdesc = imagedesc.get("annotationfile") if annotationdesc: annotation_path = f"{location}{annotationdesc['file']}" + labelmap = annotationdesc.get("labelmap") try: uploadres = project.single_upload( - image_path=image_path, annotation_path=annotation_path, split=split + image_path=image_path, + annotation_path=annotation_path, + annotation_labelmap=labelmap, + split=split, ) _log_img_upload(image_path, uploadres) except Exception as e: diff --git a/roboflow/util/folderparser.py b/roboflow/util/folderparser.py index 860fe0a8..3b33a974 100644 --- a/roboflow/util/folderparser.py +++ b/roboflow/util/folderparser.py @@ -13,6 +13,7 @@ def parsefolder(folder): _decide_split(images) annotations = [f for f in files if f["extension"] in ANNOTATION_EXTENSIONS] labelmaps = [f for f in files if f["extension"] in LABELMAPS_EXTENSIONS] + labelmaps = _load_labelmaps(folder, labelmaps) _map_labelmaps_to_annotations(annotations, labelmaps) _map_annotations_to_images(images, annotations) return { @@ -72,7 +73,23 @@ def _map_labelmaps_to_annotations(annotations, labelmaps): for ann in annotations: labelmap = labelmapmap.get(ann["dirname"]) if labelmap: - ann["labelmapfile"] = labelmap + ann["labelmap"] = labelmap["labelmap"] + + +def _load_labelmaps(folder, labelmaps): + for labelmap in labelmaps: + try: + labelmap["labelmap"] = _load_labelmap(f"{folder}/{labelmap['file']}") + except: + # raise + pass + return [lm for lm in labelmaps if lm.get("labelmap")] + + +def _load_labelmap(f): + with open(f, "r") as file: + lines = [line for line in file.readlines() if line.strip()] + return {i: l.strip() for i, l in enumerate(lines)} def _decide_split(images): diff --git a/tests/manual/debugme.py b/tests/manual/debugme.py index 667b9973..143f94e1 100644 --- a/tests/manual/debugme.py +++ b/tests/manual/debugme.py @@ -1,6 +1,10 @@ import sys import os +# import requests + +# requests.urllib3.disable_warnings() + thisdir = os.path.dirname(os.path.abspath(__file__)) rootdir = os.path.abspath(f"{thisdir}/../..") os.environ["ROBOFLOW_CONFIG_DIR"] = f"{thisdir}/data/.config" @@ -14,7 +18,7 @@ # args = parser.parse_args(f"upload {thisdir}/../datasets/chess -w wolfodorpythontests -p chess -f auto".split()) args = parser.parse_args( # f"upload {thisdir}/data/cultura-pepino-voc -w wolfodorpythontests -p cultura-pepino-voc -f auto -c 50".split() - f"upload {thisdir}/data/cultura-pepino-darknet -w wolfodorpythontests -p cultura-pepino-darknet -f auto -c 50".split() + f"upload {thisdir}/data/cultura-pepino-darknet -w wolfodorpythontests -p cultura-pepino-darknet -f auto -c 100".split() # f"upload {thisdir}/data/0311fisheye -w wolfodorpythontests -p 0311fisheye -f auto -c 50".split() ) args.func(args) diff --git a/tests/manual/upload.sh b/tests/manual/upload.sh index f8091188..7d0ea29d 100755 --- a/tests/manual/upload.sh +++ b/tests/manual/upload.sh @@ -3,3 +3,4 @@ export ROBOFLOW_CONFIG_DIR=./data/.config # python ../../roboflowpy.py upload ./data/cultura-pepino-yolov8 -w wolfodorpythontests -p cultura-pepino-upload-test-yolov8 -f yolov8 python ../../roboflowpy.py upload ./data/yellow -w wolfodorpythontests -p yellow-auto -f darknet # python ../../roboflowpy.py upload ./data/cultura-pepino-yolov5pytorch -w wolfodorpythontests -p cultura-pepino-upload-test-yolov5 -f yolov5 +# python ../../roboflowpy.py upload ./data/0311fisheye -w wolfodorpythontests -p 0311fisheye -f auto diff --git a/tests/manual/uselocal b/tests/manual/uselocal new file mode 100644 index 00000000..a33ac183 --- /dev/null +++ b/tests/manual/uselocal @@ -0,0 +1,3 @@ +#!/bin/bash +export API_URL=https://localhost.roboflow.one +export APP_URL=https://localhost.roboflow.one