Created
September 29, 2020 08:51
-
-
Save Cospel/39c6bf7984c9cb38dd14e991ddbb6e39 to your computer and use it in GitHub Desktop.
medium microcontroller blog post upload to ximilar.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import csv | |
from ximilar.client import DetectionClient | |
client = DetectionClient("__YOUR_API_TOKEN__") | |
# mapping of your ids | |
labels = { | |
"ARDUINO": "8cfe23b5-30b3-4480-821e-bf58fe9eb3bd", | |
"ESP8266": "d113c969-a58c-4c3c-a5f9-31e038a9f488", | |
"HELTEC": "3fece1eb-5769-4f38-af78-95671de8c235", | |
"RASPBERRY": "3d989abc-8ad9-4f30-8ef6-354c97418220" | |
} | |
images = {} | |
with open('train_labels.csv', newline='') as f: | |
reader = csv.reader(f) | |
for i, row in enumerate(reader): | |
if i == 0: | |
continue | |
name, _, _, label, xmin, ymin, xmax, ymax = row | |
label = label.split("_")[0].upper() | |
label = labels[label] | |
if name in images: | |
image_id = images[name] | |
else: | |
uploadi, _ = client.upload_images([{"_file": os.path.join("train", name), "noresize": True}]) | |
images[name] = uploadi[0].id | |
image_id = images[name] | |
d_object, status = client.create_object(label, image_id, [xmin, ymin, xmax, ymax]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment