Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ annotation.json
*.png
*.mp4
tests/
output/
output/
.eggs/
venv/
4 changes: 1 addition & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/psf/black
rev: 20.8b1
rev: 22.10.0
Copy link
Contributor Author

@fuji44 fuji44 Oct 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#125 の問題。
issueに書いた回避策では pre-commit で動作しなかったため、バージョンアップで対処。

hooks:
- id: black
files: '^.*\.py'
Expand All @@ -9,13 +9,11 @@ repos:
rev: 3.8.4
hooks:
- id: flake8
args: ['--extend-ignore=E203', '--max-line-length=88']
files: '^.*\.py'
types: [file]
- repo: https://github.com/pycqa/isort
rev: 5.6.4
hooks:
- id: isort
args: ['--profile', 'black']
files: '^.*\.py'
types: [file]
7 changes: 7 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"recommendations": [
"ms-python.python",
"streetsidesoftware.code-spell-checker"
],
"unwantedRecommendations": []
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"python.formatting.provider": "black",
"python.linting.flake8Enabled": true,
"python.linting.enabled": true
}
2 changes: 1 addition & 1 deletion contributing/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
black==20.8b1
black==22.10.0
flake8==3.8.4
isort==5.6.4
pre-commit==2.16.0
34 changes: 14 additions & 20 deletions examples/create_image_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,21 @@
project = "YOUR_PROJECT_SLUG"
name = "YOUR_DATA_NAME"
file_path = "YOUR_DATA_FILE_PATH" # e.g.) ./cat.jpg
annotations = [{
"type": "bbox",
"value": "cat",
"attributes": [
{
"key": "kind",
"value": "Scottish field"
}
],
"points": [
100, # top-left x
100, # top-left y
200, # bottom-right x
200 # bottom-right y
]
}]
annotations = [
{
"type": "bbox",
"value": "cat",
"attributes": [{"key": "kind", "value": "Scottish field"}],
"points": [
100, # top-left x
100, # top-left y
200, # bottom-right x
200, # bottom-right y
],
}
]

task_id = client.create_image_task(
project=project,
name=name,
file_path=file_path,
annotations=annotations
project=project, name=name, file_path=file_path, annotations=annotations
)
pprint(task_id)
13 changes: 7 additions & 6 deletions examples/download_images.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import fastlabel
import os
import time
import urllib.request
from multiprocessing import Pool, cpu_count

import fastlabel

client = fastlabel.Client()
IMAGE_DIR = "images"
PROJECT_SLUG = "YOUR_PROJECT_SLUG"


def get_all_tasks() -> list:
# Iterate pages until new tasks are empty.
all_tasks = []
Expand All @@ -17,9 +18,7 @@ def get_all_tasks() -> list:
time.sleep(1)

tasks = client.get_image_classification_tasks(
project=PROJECT_SLUG,
limit=1000,
offset=offset
project=PROJECT_SLUG, limit=1000, offset=offset
)
all_tasks.extend(tasks)

Expand All @@ -30,13 +29,15 @@ def get_all_tasks() -> list:

return all_tasks


def download_image(task: dict):
urllib.request.urlretrieve(task["url"], os.path.join(IMAGE_DIR, task["name"]))

if __name__ == '__main__':

if __name__ == "__main__":

os.makedirs(IMAGE_DIR, exist_ok=True)

tasks = get_all_tasks()
with Pool(cpu_count()) as p:
p.map(download_image, tasks)
p.map(download_image, tasks)
35 changes: 17 additions & 18 deletions fastlabel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import glob
import json
import logging
import os
import re
import logging
from typing import List
from concurrent.futures import ThreadPoolExecutor
from typing import List

import cv2
import numpy as np
import xmltodict
from PIL import Image, ImageColor, ImageDraw

from fastlabel import const, converters, utils
from fastlabel.const import (
EXPORT_IMAGE_WITH_ANNOTATIONS_SUPPORTED_IMAGE_TYPES,
Expand Down Expand Up @@ -1614,7 +1616,7 @@ def find_integrated_video_task_by_prefix(
"""
endpoint = "tasks/integrate/videos"
params = {"project": project, "prefix": prefix}

return self.api.get_request(endpoint, params=params)

def find_integrated_audio_task_by_prefix(
Expand All @@ -1630,9 +1632,8 @@ def find_integrated_audio_task_by_prefix(
"""
endpoint = "tasks/integrate/audios"
params = {"project": project, "prefix": prefix}

return self.api.get_request(endpoint, params=params)

return self.api.get_request(endpoint, params=params)

# Convert to Fastlabel

Expand Down Expand Up @@ -1673,7 +1674,9 @@ def convert_coco_to_fastlabel(self, file_path: str, annotation_type: str) -> dic
]
}
"""
return converters.execute_coco_to_fastlabel(json.load(open(file_path)), annotation_type)
return converters.execute_coco_to_fastlabel(
json.load(open(file_path)), annotation_type
)

def convert_labelme_to_fastlabel(self, folder_path: str) -> dict:
"""
Expand Down Expand Up @@ -2826,23 +2829,19 @@ def copy_project(self, project_id: str) -> None:
return self.api.post_request(endpoint, payload=payload)

def update_aws_s3_storage(
self,
project: str,
bucket_name: str,
bucket_region: str,
prefix: str = None
self, project: str, bucket_name: str, bucket_region: str, prefix: str = None
) -> str:
"""
Insert or update AWS S3 storage settings.

project is a slug of the project (Required).
bucket_name is a bucket name of the aws s3 (Required).
bucket_region is a bucket region of the aws s3 (Required).
prefix is a folder name in the aws s3 bucket. (Optional).
If sample_dir is specified as a prefix in the case of a hierarchical structure like the bucket below,
only the data under the sample_dir directory will be linked.
If not specified, everything under the bucket will be linked.

[tree structure]
fastlabel
├── sample1.jpg
Expand All @@ -2858,17 +2857,17 @@ def update_aws_s3_storage(
if prefix:
payload["prefix"] = prefix
return self.api.put_request(endpoint, payload=payload)

def create_task_from_aws_s3(
self,
self,
project: str,
status: str = "registered",
tags: List[str] = [],
priority: int = 0,
) -> dict:
"""
Insert or update AWS S3 storage settings.

project is a slug of the project (Required).
status can be 'registered', 'completed', 'skipped',
'reviewed', 'sent_back', 'approved', 'declined' (default: registered) (Optional).
Expand All @@ -2888,9 +2887,9 @@ def create_task_from_aws_s3(
"priority": priority,
}
return self.api.post_request(endpoint, payload=payload)

def get_aws_s3_import_status_by_project(
self,
self,
project: str,
) -> dict:
"""
Expand Down
13 changes: 5 additions & 8 deletions fastlabel/api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import requests

from .exceptions import FastLabelException, FastLabelInvalidException
Expand All @@ -13,8 +14,7 @@ class Api:
def __init__(self):
if not os.environ.get("FASTLABEL_ACCESS_TOKEN"):
raise ValueError("FASTLABEL_ACCESS_TOKEN is not configured.")
self.access_token = "Bearer " + \
os.environ.get("FASTLABEL_ACCESS_TOKEN")
self.access_token = "Bearer " + os.environ.get("FASTLABEL_ACCESS_TOKEN")

def get_request(self, endpoint: str, params=None) -> dict:
"""Makes a get request to an endpoint.
Expand All @@ -27,8 +27,7 @@ def get_request(self, endpoint: str, params=None) -> dict:
"Content-Type": "application/json",
"Authorization": self.access_token,
}
r = requests.get(FASTLABEL_ENDPOINT + endpoint,
headers=headers, params=params)
r = requests.get(FASTLABEL_ENDPOINT + endpoint, headers=headers, params=params)

if r.status_code == 200:
return r.json()
Expand Down Expand Up @@ -78,8 +77,7 @@ def post_request(self, endpoint, payload=None):
"Content-Type": "application/json",
"Authorization": self.access_token,
}
r = requests.post(FASTLABEL_ENDPOINT + endpoint,
json=payload, headers=headers)
r = requests.post(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers)

if r.status_code == 200:
return r.json()
Expand All @@ -104,8 +102,7 @@ def put_request(self, endpoint, payload=None):
"Content-Type": "application/json",
"Authorization": self.access_token,
}
r = requests.put(FASTLABEL_ENDPOINT + endpoint,
json=payload, headers=headers)
r = requests.put(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers)

if r.status_code == 200:
return r.json()
Expand Down
Loading