Skip to content

Commit

Permalink
Add json methods to multiple class
Browse files Browse the repository at this point in the history
  • Loading branch information
jrrodri committed Mar 12, 2024
1 parent 874e5b0 commit 82f70b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
14 changes: 11 additions & 3 deletions abraia/multiple.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,21 @@ def save_image(self, path, img, metadata={}):
Image.fromarray(img).save(src)
return self.upload_file(src, path)

def load_json(self, path):
return json.loads(self.load_file(path))

def save_json(self, path, values):
return self.save_file(path, json.dumps(values))

def load_dataset(self, dataset, shuffle=True):
paths, labels = [], []
[files, folders] = self.list_files(f"{dataset}/")
if any([file['name'] == 'annotations.json' for file in files]):
annotations = json.loads(self.load_file(f"{dataset}/annotations.json"))
if self.check_file(f"{dataset}/annotations.json"):
annotations = self.load_json(f"{dataset}/annotations.json")
keys = list(filter(lambda k: k != 'filename', annotations[0].keys()))
paths = [f"{dataset}/{annotation['filename']}" for annotation in annotations]
labels = [annotation['label'] for annotation in annotations]
else:
[files, folders] = self.list_files(f"{dataset}/")
for folder in folders:
files = self.list_files(folder['path'])[0]
paths.extend([file['path'] for file in files])
Expand All @@ -120,4 +127,5 @@ def load_dataset(self, dataset, shuffle=True):
paths = [paths[id] for id in ids]
labels = [labels[id] for id in ids]
return paths, labels


Binary file modified images/screenshot.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion notebooks/YOLOv8.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"#@markdown # YOLOv8 dataset training\n",
"!python -m pip install onnx\n",
"!python -m pip install abraia\n",
"!python -m pip install rasterio\n",
"!python -m pip install ultralytics\n",
"\n",
"import os\n",
Expand Down

0 comments on commit 82f70b0

Please sign in to comment.