Skip to content

Commit d4c7cd7

Browse files
authored
Merge pull request #82 from fastlabel/bugfix/789-limitation-size
Add request size check
2 parents 1309785 + 63d7ae5 commit d4c7cd7

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ task = client.create_multi_image_task(
433433
```
434434

435435
##### Limitation
436-
436+
* You can upload up to a total size of 512 MB.
437437
* You can upload up to 250 files in total.
438438

439439
#### Find Task
@@ -565,6 +565,9 @@ task_id = client.create_video_task(
565565
)
566566
```
567567

568+
##### Limitation
569+
* You can upload up to a size of 250 MB.
570+
568571
#### Find Task
569572

570573
Find a single task.
@@ -669,6 +672,9 @@ task_id = client.create_video_classification_task(
669672
)
670673
```
671674

675+
##### Limitation
676+
* You can upload up to a size of 250 MB.
677+
672678
#### Find Task
673679

674680
Find a single task.

fastlabel/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ def create_multi_image_task(
477477
raise FastLabelInvalidException(
478478
"Folder does not have any file.", 422)
479479
contents = []
480+
contents_size = 0
480481
for file_path in file_paths:
481482
if not utils.is_image_supported_ext(file_path):
482483
raise FastLabelInvalidException(
@@ -491,6 +492,11 @@ def create_multi_image_task(
491492
"name": os.path.basename(file_path),
492493
"file": file
493494
})
495+
contents_size += utils.get_json_length(contents[-1])
496+
if contents_size > const.SUPPORTED_CONTENTS_SIZE:
497+
raise FastLabelInvalidException(
498+
f"Supported contents size is under {const.SUPPORTED_CONTENTS_SIZE}.", 422)
499+
494500
payload = {"project": project, "name": name, "contents": contents}
495501
if status:
496502
payload["status"] = status
@@ -537,6 +543,10 @@ def create_video_task(
537543
if not utils.is_video_supported_ext(file_path):
538544
raise FastLabelInvalidException(
539545
"Supported extensions are mp4.", 422)
546+
if os.path.getsize(file_path) > const.SUPPORTED_VIDEO_SIZE:
547+
raise FastLabelInvalidException(
548+
f"Supported video size is under 250 MB.", 422)
549+
540550
file = utils.base64_encode(file_path)
541551
payload = {"project": project, "name": name, "file": file}
542552
if status:
@@ -586,6 +596,10 @@ def create_video_classification_task(
586596
if not utils.is_video_supported_ext(file_path):
587597
raise FastLabelInvalidException(
588598
"Supported extensions are mp4.", 422)
599+
if os.path.getsize(file_path) > const.SUPPORTED_VIDEO_SIZE:
600+
raise FastLabelInvalidException(
601+
f"Supported video size is under 250 MB.", 422)
602+
589603
file = utils.base64_encode(file_path)
590604
payload = {"project": project, "name": name, "file": file}
591605
if status:

fastlabel/const.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33
# only 57 types
44
COLOR_PALETTE = [0, 0, 0, 228, 26, 28, 55, 126, 184, 77, 175, 74, 152, 78, 163, 255, 127, 0, 255, 255, 51, 166, 86, 40, 247, 129, 191, 153, 153, 153, 102, 194, 165, 252, 141, 98, 141, 160, 203, 231, 138, 195, 166, 216, 84, 255, 217, 47, 229, 196, 148, 179, 179, 179, 141, 211, 199, 255, 255, 179, 190, 186, 218, 251, 128, 114, 128, 177, 211, 253, 180, 98, 179, 222, 105, 252, 205, 229, 217, 217, 217, 188, 128, 189, 204, 235, 197, 255, 237, 111, 166, 206, 227, 31, 120, 180, 178, 223, 138, 51, 160, 44, 251, 154, 153, 227, 26, 28, 253, 191, 111, 255, 127, 0, 202, 178, 214, 106, 61, 154, 255, 255, 153, 177, 89, 40, 127, 201, 127, 190, 174, 212, 253, 192, 134, 255, 255, 153, 56, 108, 176, 240, 2, 127, 191, 91, 22, 102, 102, 102, 27, 158, 119, 217, 95, 2, 117, 112, 179, 231, 41, 138, 102, 166, 30, 230, 171, 2, 166, 118, 29, 102, 102, 102]
55

6+
# under 512 MB. Actual size is 536870888 bytes, but to consider other attributes, minus 888 bytes.
7+
# Because of V8's limitation, API only can accept the JSON string that length is under this.
8+
SUPPORTED_CONTENTS_SIZE = 536870000
9+
10+
# API can accept under 250 MB ( 250 * 1024 * 1024 )
11+
SUPPORTED_VIDEO_SIZE = 262144000
12+
13+
614
class AnnotationType(Enum):
715
bbox = "bbox"
816
polygon = "polygon"
917
keypoint = "keypoint"
1018
line = "line"
1119
segmentation = "segmentation"
1220
classification = "classification"
13-
pose_estimation = "pose_estimation"
21+
pose_estimation = "pose_estimation"

fastlabel/utils.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import base64
33
import numpy as np
44
import geojson
5+
import json
56
from typing import List
67

78

@@ -15,7 +16,7 @@ def is_image_supported_ext(file_path: str) -> bool:
1516

1617

1718
def is_video_supported_ext(file_path: str) -> bool:
18-
return file_path.lower().endswith(('.mp4'))
19+
return file_path.lower().endswith('.mp4')
1920

2021

2122
def get_basename(file_path: str) -> str:
@@ -44,13 +45,14 @@ def reverse_points(points: List[int]) -> List[int]:
4445
0, points[index])
4546
return reversed_points
4647

48+
4749
def is_clockwise(points: list) -> bool:
4850
"""
4951
points: [x1, y1, x2, y2, x3, y3, ... xn, yn]
50-
Sum over the edges, (x2 − x1)(y2 + y1).
52+
Sum over the edges, (x2 − x1)(y2 + y1).
5153
If the result is positive the curve is clockwise, if it's negative the curve is counter-clockwise.
52-
53-
The above is assumes a normal Cartesian coordinate system.
54+
55+
The above is assumes a normal Cartesian coordinate system.
5456
HTML5 canvas, use an inverted Y-axis.
5557
Therefore If the area is negative, the curve is clockwise.
5658
"""
@@ -65,4 +67,10 @@ def is_clockwise(points: list) -> bool:
6567

6668
if sum_edges < 0:
6769
return True
68-
return False
70+
return False
71+
72+
73+
def get_json_length(value) -> int:
74+
json_str = json.dumps(value)
75+
return len(json_str)
76+

0 commit comments

Comments
 (0)