Skip to content

Commit 0566a49

Browse files
authored
Merge pull request #95 from fastlabel/feature/1116-image-size-check
Add size check of image
2 parents 1a67268 + 4dd7e51 commit 0566a49

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ task_id = client.create_image_task(
105105

106106
> Check [examples/create_image_task.py](/examples/create_image_task.py).
107107
108+
##### Limitation
109+
* You can upload up to a size of 20 MB.
110+
108111
#### Find Task
109112

110113
Find a single task.
@@ -321,6 +324,9 @@ task_id = client.create_image_classification_task(
321324
)
322325
```
323326

327+
##### Limitation
328+
* You can upload up to a size of 20 MB.
329+
324330
#### Find Task
325331

326332
Find a single task.
@@ -433,6 +439,7 @@ task = client.create_multi_image_task(
433439
```
434440

435441
##### Limitation
442+
* You can upload up to a size of 20 MB.
436443
* You can upload up to a total size of 512 MB.
437444
* You can upload up to 250 files in total.
438445

fastlabel/__init__.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,10 @@ def create_image_task(
375375
if not utils.is_image_supported_ext(file_path):
376376
raise FastLabelInvalidException(
377377
"Supported extensions are png, jpg, jpeg.", 422)
378+
if not utils.is_image_supported_size(file_path):
379+
raise FastLabelInvalidException(
380+
f"Supported image size is under 20 MB.", 422)
381+
378382
file = utils.base64_encode(file_path)
379383
payload = {"project": project, "name": name, "file": file}
380384
if status:
@@ -424,6 +428,10 @@ def create_image_classification_task(
424428
if not utils.is_image_supported_ext(file_path):
425429
raise FastLabelInvalidException(
426430
"Supported extensions are png, jpg, jpeg.", 422)
431+
if not utils.is_image_supported_size(file_path):
432+
raise FastLabelInvalidException(
433+
f"Supported image size is under 20 MB.", 422)
434+
427435
file = utils.base64_encode(file_path)
428436
payload = {"project": project, "name": name, "file": file}
429437
if status:
@@ -483,6 +491,10 @@ def create_multi_image_task(
483491
raise FastLabelInvalidException(
484492
"Supported extensions are png, jpg, jpeg.", 422)
485493

494+
if not utils.is_image_supported_size(file_path):
495+
raise FastLabelInvalidException(
496+
f"Supported image size is under 20 MB.", 422)
497+
486498
if len(contents) == 250:
487499
raise FastLabelInvalidException(
488500
"The count of files should be under 250", 422)
@@ -543,7 +555,7 @@ def create_video_task(
543555
if not utils.is_video_supported_ext(file_path):
544556
raise FastLabelInvalidException(
545557
"Supported extensions are mp4.", 422)
546-
if os.path.getsize(file_path) > const.SUPPORTED_VIDEO_SIZE:
558+
if not utils.is_video_supported_size(file_path):
547559
raise FastLabelInvalidException(
548560
f"Supported video size is under 250 MB.", 422)
549561

@@ -596,7 +608,7 @@ def create_video_classification_task(
596608
if not utils.is_video_supported_ext(file_path):
597609
raise FastLabelInvalidException(
598610
"Supported extensions are mp4.", 422)
599-
if os.path.getsize(file_path) > const.SUPPORTED_VIDEO_SIZE:
611+
if not utils.is_video_supported_size(file_path):
600612
raise FastLabelInvalidException(
601613
f"Supported video size is under 250 MB.", 422)
602614

fastlabel/const.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
from enum import Enum
23

34
# only 57 types
@@ -7,8 +8,11 @@
78
# Because of V8's limitation, API only can accept the JSON string that length is under this.
89
SUPPORTED_CONTENTS_SIZE = 536870000
910

10-
# API can accept under 250 MB ( 250 * 1024 * 1024 )
11-
SUPPORTED_VIDEO_SIZE = 262144000
11+
# API can accept under 250 MB
12+
SUPPORTED_VIDEO_SIZE = 250 * math.pow(1024, 2)
13+
14+
# API can accept under 20 MB
15+
SUPPORTED_IMAGE_SIZE = 20 * math.pow(1024, 2)
1216

1317

1418
class AnnotationType(Enum):

fastlabel/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import geojson
55
import json
66
from typing import List
7+
from fastlabel import const
78

89

910
def base64_encode(file_path: str) -> str:
@@ -19,6 +20,14 @@ def is_video_supported_ext(file_path: str) -> bool:
1920
return file_path.lower().endswith('.mp4')
2021

2122

23+
def is_image_supported_size(file_path: str) -> bool:
24+
return os.path.getsize(file_path) <= const.SUPPORTED_IMAGE_SIZE
25+
26+
27+
def is_video_supported_size(file_path: str) -> bool:
28+
return os.path.getsize(file_path) <= const.SUPPORTED_VIDEO_SIZE
29+
30+
2231
def is_json_ext(file_name: str) -> bool:
2332
return file_name.lower().endswith('.json')
2433

0 commit comments

Comments
 (0)