-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathupload-training.py
More file actions
22 lines (19 loc) · 1.06 KB
/
upload-training.py
File metadata and controls
22 lines (19 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os, requests
from tqdm import tqdm
pathToAnnotations = './annotations/json'
pathToImages = './images'
model_id = os.environ.get('NANONETS_MODEL_ID')
api_key = os.environ.get('NANONETS_API_KEY')
for root, dirs, files in os.walk(pathToAnnotations, topdown=False):
for name in tqdm(files):
annotation = open(os.path.join(root, name), "r")
filePath = os.path.join(root, name)
imageName, ext = name.split(".")
imagePath = os.path.join(pathToImages, imageName + '.jpg')
jsonData = annotation.read()
url = 'https://app.nanonets.com/api/v2/ObjectDetection/Model/' + model_id + '/UploadFile/'
data = {'file' :open(imagePath, 'rb'), 'data' :('', '[{"filename":"' + imageName+".jpg" + '", "object": '+ jsonData+'}]'), 'modelId' :('', model_id)}
response = requests.post(url, auth=requests.auth.HTTPBasicAuth(api_key, ''), files=data)
if response.status_code > 250 or response.status_code<200:
print(response.text), response.status_code
print("\n\n\nNEXT RUN: python ./code/train-model.py")