Skip to content

Commit

Permalink
fix json.decoder.JSONDecodeError in coco to yolov5 conversion (#786)
Browse files Browse the repository at this point in the history
Co-authored-by: fatih <[email protected]>
  • Loading branch information
kadirnar and fcakyon authored Dec 20, 2022
1 parent ce6926a commit ebf9341
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions sahi/utils/coco.py
Original file line number Diff line number Diff line change
Expand Up @@ -1535,7 +1535,7 @@ def export_yolov5_images_and_txts_from_coco_object(output_dir, coco, ignore_nega


def export_single_yolov5_image_and_corresponding_txt(
coco_image, coco_image_dir, output_dir, ignore_negative_samples=False
coco_image, coco_image_dir, output_dir, ignore_negative_samples=False, disable_symlink=False
):
"""
Generates yolov5 formatted image symlink and annotation txt file.
Expand Down Expand Up @@ -1578,7 +1578,12 @@ def export_single_yolov5_image_and_corresponding_txt(
yolo_image_path = str(parent_dir / (filename + filesuffix))
name_increment += 1
# create a symbolic link pointing to coco_image_path named yolo_image_path
os.symlink(coco_image_path, yolo_image_path)
if disable_symlink:
import shutil

shutil.copy(coco_image_path, yolo_image_path)
else:
os.symlink(coco_image_path, yolo_image_path)
# calculate annotation normalization ratios
width = coco_image.width
height = coco_image.height
Expand Down
3 changes: 2 additions & 1 deletion sahi/utils/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def unzip(file_path: str, dest_dir: str):
zf.extractall(dest_dir)


def save_json(data, save_path, indent: Optional[int] = 4):
def save_json(data, save_path, indent: Optional[int] = None):
"""
Saves json formatted data (given as "data") as save_path
Example inputs:
data: {"image_id": 5}
save_path: "dirname/coco.json"
indent: Train json files with indent=None, val json files with indent=4
"""
# create dir if not present
Path(save_path).parent.mkdir(parents=True, exist_ok=True)
Expand Down

0 comments on commit ebf9341

Please sign in to comment.