forked from XCRobert/Labelme2Coco
-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from fcakyon/refactor
refactor codebase to utilize sahi
- Loading branch information
Showing
13 changed files
with
307 additions
and
373 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
name: Package Testing | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Runs at 00:00 UTC every day | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
operating-system: [ubuntu-latest, windows-latest, macos-latest] | ||
python-version: [3.7, 3.8, 3.9, "3.10"] | ||
fail-fast: false | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Restore Ubuntu cache | ||
uses: actions/cache@v1 | ||
if: matrix.operating-system == 'ubuntu-latest' | ||
with: | ||
path: ~/.cache/pip | ||
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}} | ||
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}- | ||
|
||
- name: Restore MacOS cache | ||
uses: actions/cache@v1 | ||
if: matrix.operating-system == 'macos-latest' | ||
with: | ||
path: ~/Library/Caches/pip | ||
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}} | ||
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}- | ||
|
||
- name: Restore Windows cache | ||
uses: actions/cache@v1 | ||
if: matrix.operating-system == 'windows-latest' | ||
with: | ||
path: ~\AppData\Local\pip\Cache | ||
key: ${{ matrix.os }}-${{ matrix.python-version }}-${{ hashFiles('**/setup.py')}} | ||
restore-keys: ${{ matrix.os }}-${{ matrix.python-version }}- | ||
|
||
- name: Update pip | ||
run: python -m pip install --upgrade pip | ||
|
||
- name: Install latest labelme2coco package | ||
run: > | ||
pip install --upgrade --force-reinstall labelme2coco | ||
- name: Test with unittest | ||
run: | | ||
pip install pytest | ||
python -m unittest | ||
- name: Test CLI | ||
run: | | ||
pip install . | ||
labelme2coco tests/data/labelme_annot --train_split_rate 0.85 |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,46 @@ | ||
from __future__ import absolute_import | ||
|
||
__version__ = "0.1.2" | ||
__version__ = "0.2.0" | ||
|
||
from labelme2coco.labelme2coco import labelme2coco | ||
import logging | ||
import os | ||
from pathlib import Path | ||
|
||
from sahi.utils.file import save_json | ||
|
||
def convert(labelme_folder: str, save_json_path: str): | ||
from labelme2coco.labelme2coco import get_coco_from_labelme_folder | ||
|
||
logger = logging.getLogger(__name__) | ||
logging.basicConfig( | ||
format="%(asctime)s - %(levelname)s - %(name)s - %(message)s", | ||
datefmt="%m/%d/%Y %H:%M:%S", | ||
level=os.environ.get("LOGLEVEL", "INFO").upper(), | ||
) | ||
|
||
|
||
def convert( | ||
labelme_folder: str, | ||
export_dir: str = "runs/labelme2coco/", | ||
train_split_rate: float = 1, | ||
): | ||
""" | ||
Args: | ||
labelme_folder: folder that contains labelme annotations and image files | ||
save_json_path: oath for coco json to be saved | ||
export_dir: path for coco jsons to be exported | ||
train_split_rate: ration fo train split | ||
""" | ||
labelme2coco(labelme_folder, save_json_path) | ||
coco = get_coco_from_labelme_folder(labelme_folder) | ||
if train_split_rate < 1: | ||
result = coco.split_coco_as_train_val(train_split_rate) | ||
# export train split | ||
save_path = str(Path(export_dir) / "train.json") | ||
save_json(result["train_coco"].json, save_path) | ||
logger.info(f"Training split in COCO format is exported to {save_path}") | ||
# export val split | ||
save_path = str(Path(export_dir) / "val.json") | ||
save_json(result["val_coco"].json, save_path) | ||
logger.info(f"Validation split in COCO format is exported to {save_path}") | ||
else: | ||
save_path = str(Path(export_dir) / "dataset.json") | ||
save_json(coco.json, save_path) | ||
logger.info(f"Converted annotations in COCO format is exported to {save_path}") |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import fire | ||
|
||
from labelme2coco import convert | ||
|
||
|
||
def app() -> None: | ||
"""Cli app.""" | ||
fire.Fire(convert) | ||
|
||
|
||
if __name__ == "__main__": | ||
app() |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.