Skip to content

Commit a7355b6

Browse files
zhiltsov-maxMarishka17ivhusDzeranov
authored
Merge CVAT milestone 2 changes (humanprotocol#1746)
* Fix job event handling when no assignments exist * Implement boxes from points task creation * Refactor cloud storage api * Implement job downloading * Estimate max bbox * Little refactoring * Copy some shared code from excor to recor * Refactor task creation and export * Implement boxes from points validation * Integrate SDK updates * Fix escrow access * [Exchange/Recoring oracles] Add GCS support * Remove local dev mocks * Remove some extra changes * Update tests * Update some tests * Remove extra launcher change * Refactor code * Add google-cloud-storage dependency * Fix exception classes * Set env variables in docker-compose.test.yml * [CVAT] Points to boxes task (humanprotocol#1560) * Fix job event handling when no assignments exist * Implement boxes from points task creation * Refactor cloud storage api * Implement job downloading * Estimate max bbox * Little refactoring * Copy some shared code from excor to recor * Refactor task creation and export * Implement boxes from points validation * Integrate SDK updates * Fix escrow access * Remove local dev mocks * Remove some extra changes * Update tests * Update some tests * Remove extra launcher change * Use virtual hosted bucket style * Fix creating CS in CVAT * Fix tests * Add basic implementation for skeletons from boxes * Refactor and fix some errors * Implement job uploading * Implement downloading * Fix extra gt boxes in merged results from excor * Implement skeleton matching * Fix labels in merged annotations * Update project events handling in excor * Improve oks sigma comment * Remove local testing assets * Fix label mapping * Add extra skeleton validations in manifest * Update .env template * Update several comments * Fix failing tests * Update enum name * Add more annotation validations for skeletons * Extend input annotations validation * Fix quality computation, refactor * Unify assignment accuracy checks between different job types * Refactor GT downloading for validation * Add gcs support - fixes (#1) * Update code formatting * Update poetry lock * Refactor * Use dict for gcs file contents * Update class name * Add backward compatibility for data bucket env var * Remove extra changes * Remove extra import * Fix enum name * Update bucket access info parsing * Fix error type in cloud provider parsing * Update tests * Add job annotation mode param into assignment links * Add CD trigger for experimental cvat oracles * Update code formatting * Fix test * Format code * Fix bucket uses * Fix result sending * Remove extra changes * Fix extra code * Remove unused code * Align enum naming convention * Use relative paths in bucket in task creation * Improve error messages * Improve skeleton and bbox validation * Fix escrow manifest downloading * Update tests * Fix tests * Implement general image bans * Fix import * Make default gt ban threshold more strict * Fix comparison for absent points * Fix comparison for omitted points in jobs * Finish escrows with too many unverifiable assignments * Check if an increased healthcheck interval will fix unhealthy container (humanprotocol#1700) * Fix validations for boxes from points task creation * Clean code * disable roi estimation for unreliable cases * Fix manifest parsing * Remove m0 launcher stubs * Remove m0 rep or stubs * Make max assignment time optional in manifest * Make label type fully optional in manifest * Fix test * Enable and fix a disabled m1 task creation test * Fix RecOr tests --------- Co-authored-by: maya <[email protected]> Co-authored-by: Ivan <[email protected]> Co-authored-by: Dzeranov <[email protected]>
1 parent dbb0ef6 commit a7355b6

File tree

111 files changed

+8328
-1925
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+8328
-1925
lines changed

.github/workflows/cd-cvat-exchange-oracle.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Deploy CVAT Exchange Oracle
22

33
on:
44
push:
5-
branches: [ develop, main ]
5+
branches: [ develop, main, cvat-milestone-2 ]
66
paths:
77
- 'packages/examples/cvat/exchange-oracle/**'
88
pull_request:
9-
branches: [ develop, main ]
9+
branches: [ develop, main, cvat-milestone-2 ]
1010
paths:
1111
- 'packages/examples/cvat/exchange-oracle/**'
1212
workflow_dispatch:

.github/workflows/cd-cvat-recording-oracle.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ name: Deploy CVAT Recording Oracle
22

33
on:
44
push:
5-
branches: [ develop, main ]
5+
branches: [ develop, main, cvat-milestone-2 ]
66
paths:
77
- 'packages/examples/cvat/recording-oracle/**'
88
pull_request:
9-
branches: [ develop, main ]
9+
branches: [ develop, main, cvat-milestone-2 ]
1010
paths:
1111
- 'packages/examples/cvat/recording-oracle/**'
1212
workflow_dispatch:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""non-unique-escrows
2+
3+
Revision ID: c1e74c227cfe
4+
Revises: 16ecc586d685
5+
Create Date: 2024-02-05 22:54:42.478270
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlalchemy_utils
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = 'c1e74c227cfe'
15+
down_revision = '16ecc586d685'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade() -> None:
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.drop_constraint('projects_escrow_address_key', 'projects', type_='unique')
23+
# ### end Alembic commands ###
24+
25+
26+
def downgrade() -> None:
27+
# ### commands auto generated by Alembic - please adjust! ###
28+
op.create_unique_constraint('projects_escrow_address_key', 'projects', ['escrow_address'])
29+
# ### end Alembic commands ###

packages/examples/cvat/exchange-oracle/docker-compose.test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ services:
7070
STORAGE_SECRET_KEY: 'devdevdev'
7171
STORAGE_RESULTS_BUCKET_NAME: 'results'
7272
STORAGE_USE_SSL: False
73+
STORAGE_PROVIDER: 'aws'
7374
ENABLE_CUSTOM_CLOUD_HOST: Yes
7475
depends_on:
7576
postgres:

packages/examples/cvat/exchange-oracle/poetry.lock

+264-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/examples/cvat/exchange-oracle/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ human-protocol-sdk = "^1.1.19"
2323
xmltodict = "^0.13.0"
2424
datumaro = {git = "https://github.com/cvat-ai/datumaro.git", rev = "ff83c00c2c1bc4b8fdfcc55067fcab0a9b5b6b11"}
2525
boto3 = "^1.28.33"
26+
google-cloud-storage = "^2.14.0"
2627

2728

2829
[tool.poetry.group.dev.dependencies]

packages/examples/cvat/exchange-oracle/src/.env.template

+8-3
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ PROCESS_RECORDING_ORACLE_WEBHOOKS_CHUNK_SIZE=
3535
TRACK_COMPLETED_PROJECTS_INT=
3636
TRACK_COMPLETED_PROJECTS_CHUNK_SIZE=
3737
TRACK_COMPLETED_TASKS_INT=
38-
RETRIEVE_ANNOTATIONS_INT=
39-
RETRIEVE_ANNOTATIONS_CHUNK_SIZE=
38+
TRACK_COMPLETED_ESCROWS_INT=
39+
TRACK_COMPLETED_ESCROWS_CHUNK_SIZE=
4040
PROCESS_JOB_LAUNCHER_WEBHOOKS_INT=
4141
TRACK_CREATING_TASKS_INT=
42+
REJECTED_PROJECTS_CHUNK_SIZE=
43+
ACCEPTED_PROJECTS_CHUNK_SIZE=
4244

4345
# CVAT Config
4446

@@ -50,12 +52,14 @@ CVAT_INCOMING_WEBHOOKS_URL=
5052
CVAT_WEBHOOK_SECRET=
5153
CVAT_ORG_SLUG=
5254

53-
# S3 Storage Config
55+
# Storage Config (S3/GCS)
5456

57+
STORAGE_PROVIDER=
5558
STORAGE_ENDPOINT_URL=
5659
STORAGE_REGION=
5760
STORAGE_ACCESS_KEY=
5861
STORAGE_SECRET_KEY=
62+
STORAGE_KEY_FILE_PATH=
5963
STORAGE_RESULTS_BUCKET_NAME=
6064
STORAGE_USE_SSL=
6165

@@ -73,5 +77,6 @@ HUMAN_APP_SIGNATURE=
7377

7478
# Localhost
7579

80+
LOCALHOST_RECORDING_ORACLE_ADDRESS=
7681
LOCALHOST_RECORDING_ORACLE_URL=
7782
LOCALHOST_JOB_LAUNCHER_URL=

packages/examples/cvat/exchange-oracle/src/chain/escrow.py

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from human_protocol_sdk.escrow import EscrowData, EscrowUtils
66
from human_protocol_sdk.storage import StorageUtils
77

8+
from src.core.config import Config
9+
810

911
def get_escrow(chain_id: int, escrow_address: str) -> EscrowData:
1012
escrow = EscrowUtils.get_escrow(ChainId(chain_id), escrow_address)
@@ -51,4 +53,7 @@ def get_job_launcher_address(chain_id: int, escrow_address: str) -> str:
5153

5254

5355
def get_recording_oracle_address(chain_id: int, escrow_address: str) -> str:
56+
if address := Config.localhost.recording_oracle_address:
57+
return address
58+
5459
return get_escrow(chain_id, escrow_address).recording_oracle

packages/examples/cvat/exchange-oracle/src/core/annotation_meta.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pydantic import BaseModel
55

6-
ANNOTATION_METAFILE_NAME = "annotation_meta.json"
6+
ANNOTATION_RESULTS_METAFILE_NAME = "annotation_meta.json"
77
RESULTING_ANNOTATIONS_FILE = "resulting_annotations.zip"
88

99

packages/examples/cvat/exchange-oracle/src/core/config.py

+45-23
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# pylint: disable=too-few-public-methods,missing-class-docstring
22
""" Project configuration from env vars """
33
import os
4+
from typing import ClassVar, Optional
45

6+
from attrs.converters import to_bool
57
from dotenv import load_dotenv
68

79
from src.utils.logging import parse_log_level
@@ -10,12 +12,6 @@
1012
load_dotenv()
1113

1214

13-
def str_to_bool(val: str) -> bool:
14-
from distutils.util import strtobool
15-
16-
return val is True or strtobool(val)
17-
18-
1915
class PostgresConfig:
2016
port = os.environ.get("PG_PORT", "5432")
2117
host = os.environ.get("PG_HOST", "0.0.0.0")
@@ -53,6 +49,8 @@ class LocalhostConfig:
5349
addr = os.environ.get("LOCALHOST_MUMBAI_ADDR", "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266")
5450

5551
job_launcher_url = os.environ.get("LOCALHOST_JOB_LAUNCHER_URL")
52+
53+
recording_oracle_address = os.environ.get("LOCALHOST_RECORDING_ORACLE_ADDRESS")
5654
recording_oracle_url = os.environ.get("LOCALHOST_RECORDING_ORACLE_URL")
5755

5856

@@ -75,8 +73,20 @@ class CronConfig:
7573
track_assignments_int = int(os.environ.get("TRACK_ASSIGNMENTS_INT", 5))
7674
track_assignments_chunk_size = os.environ.get("TRACK_ASSIGNMENTS_CHUNK_SIZE", 10)
7775

78-
retrieve_annotations_int = int(os.environ.get("RETRIEVE_ANNOTATIONS_INT", 60))
79-
retrieve_annotations_chunk_size = os.environ.get("RETRIEVE_ANNOTATIONS_CHUNK_SIZE", 5)
76+
track_completed_escrows_int = int(
77+
# backward compatibility
78+
os.environ.get(
79+
"TRACK_COMPLETED_ESCROWS_INT", os.environ.get("RETRIEVE_ANNOTATIONS_INT", 60)
80+
)
81+
)
82+
track_completed_escrows_chunk_size = os.environ.get(
83+
# backward compatibility
84+
"TRACK_COMPLETED_ESCROWS_CHUNK_SIZE",
85+
os.environ.get("RETRIEVE_ANNOTATIONS_CHUNK_SIZE", 5),
86+
)
87+
88+
rejected_projects_chunk_size = os.environ.get("REJECTED_PROJECTS_CHUNK_SIZE", 20)
89+
accepted_projects_chunk_size = os.environ.get("ACCEPTED_PROJECTS_CHUNK_SIZE", 20)
8090

8191

8292
class CvatConfig:
@@ -94,39 +104,51 @@ class CvatConfig:
94104

95105

96106
class StorageConfig:
97-
endpoint_url = os.environ.get("STORAGE_ENDPOINT_URL", "storage.googleapis.com")
98-
region = os.environ.get("STORAGE_REGION", "")
99-
access_key = os.environ.get("STORAGE_ACCESS_KEY", "")
100-
secret_key = os.environ.get("STORAGE_SECRET_KEY", "")
101-
results_bucket_name = os.environ.get("STORAGE_RESULTS_BUCKET_NAME", "")
102-
secure = str_to_bool(os.environ.get("STORAGE_USE_SSL", "true"))
107+
provider: ClassVar[str] = os.environ["STORAGE_PROVIDER"].lower()
108+
data_bucket_name: ClassVar[str] = (
109+
os.environ.get("STORAGE_RESULTS_BUCKET_NAME") # backward compatibility
110+
or os.environ["STORAGE_BUCKET_NAME"]
111+
)
112+
endpoint_url: ClassVar[str] = os.environ[
113+
"STORAGE_ENDPOINT_URL"
114+
] # TODO: probably should be optional
115+
region: ClassVar[Optional[str]] = os.environ.get("STORAGE_REGION")
116+
results_dir_suffix: ClassVar[str] = os.environ.get("STORAGE_RESULTS_DIR_SUFFIX", "-results")
117+
secure: ClassVar[bool] = to_bool(os.environ.get("STORAGE_USE_SSL", "true"))
118+
119+
# S3 specific attributes
120+
access_key: ClassVar[Optional[str]] = os.environ.get("STORAGE_ACCESS_KEY")
121+
secret_key: ClassVar[Optional[str]] = os.environ.get("STORAGE_SECRET_KEY")
122+
123+
# GCS specific attributes
124+
key_file_path: ClassVar[Optional[str]] = os.environ.get("STORAGE_KEY_FILE_PATH")
103125

104126
@classmethod
105-
def provider_endpoint_url(cls):
106-
scheme = "https://" if cls.secure else "http://"
127+
def get_scheme(cls) -> str:
128+
return "https://" if cls.secure else "http://"
107129

108-
return f"{scheme}{cls.endpoint_url}"
130+
@classmethod
131+
def provider_endpoint_url(cls):
132+
return f"{cls.get_scheme()}{cls.endpoint_url}"
109133

110134
@classmethod
111135
def bucket_url(cls):
112-
scheme = "https://" if cls.secure else "http://"
113-
114136
if is_ipv4(cls.endpoint_url):
115-
return f"{scheme}{cls.endpoint_url}/{cls.results_bucket_name}/"
137+
return f"{cls.get_scheme()}{cls.endpoint_url}/{cls.data_bucket_name}/"
116138
else:
117-
return f"{scheme}{cls.results_bucket_name}.{cls.endpoint_url}/"
139+
return f"{cls.get_scheme()}{cls.data_bucket_name}.{cls.endpoint_url}/"
118140

119141

120142
class FeaturesConfig:
121-
enable_custom_cloud_host = str_to_bool(os.environ.get("ENABLE_CUSTOM_CLOUD_HOST", "no"))
143+
enable_custom_cloud_host = to_bool(os.environ.get("ENABLE_CUSTOM_CLOUD_HOST", "no"))
122144
"Allows using a custom host in manifest bucket urls"
123145

124146
default_export_timeout = int(os.environ.get("DEFAULT_EXPORT_TIMEOUT", 60))
125147
"Timeout, in seconds, for annotations or dataset export waiting"
126148

127149

128150
class CoreConfig:
129-
default_assignment_time = int(os.environ.get("DEFAULT_ASSIGNMENT_TIME", 300))
151+
default_assignment_time = int(os.environ.get("DEFAULT_ASSIGNMENT_TIME", 1800))
130152

131153

132154
class HumanAppConfig:

0 commit comments

Comments
 (0)