clarifai 11.3.0rc2__py3-none-any.whl → 11.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clarifai/__init__.py +1 -1
- clarifai/cli/__main__.py +1 -1
- clarifai/cli/base.py +144 -136
- clarifai/cli/compute_cluster.py +45 -31
- clarifai/cli/deployment.py +93 -76
- clarifai/cli/model.py +578 -180
- clarifai/cli/nodepool.py +100 -82
- clarifai/client/__init__.py +12 -2
- clarifai/client/app.py +973 -911
- clarifai/client/auth/helper.py +345 -342
- clarifai/client/auth/register.py +7 -7
- clarifai/client/auth/stub.py +107 -106
- clarifai/client/base.py +185 -178
- clarifai/client/compute_cluster.py +214 -180
- clarifai/client/dataset.py +793 -698
- clarifai/client/deployment.py +55 -50
- clarifai/client/input.py +1223 -1088
- clarifai/client/lister.py +47 -45
- clarifai/client/model.py +1939 -1717
- clarifai/client/model_client.py +525 -502
- clarifai/client/module.py +82 -73
- clarifai/client/nodepool.py +358 -213
- clarifai/client/runner.py +58 -0
- clarifai/client/search.py +342 -309
- clarifai/client/user.py +419 -414
- clarifai/client/workflow.py +294 -274
- clarifai/constants/dataset.py +11 -17
- clarifai/constants/model.py +8 -2
- clarifai/datasets/export/inputs_annotations.py +233 -217
- clarifai/datasets/upload/base.py +63 -51
- clarifai/datasets/upload/features.py +43 -38
- clarifai/datasets/upload/image.py +237 -207
- clarifai/datasets/upload/loaders/coco_captions.py +34 -32
- clarifai/datasets/upload/loaders/coco_detection.py +72 -65
- clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
- clarifai/datasets/upload/loaders/xview_detection.py +274 -132
- clarifai/datasets/upload/multimodal.py +55 -46
- clarifai/datasets/upload/text.py +55 -47
- clarifai/datasets/upload/utils.py +250 -234
- clarifai/errors.py +51 -50
- clarifai/models/api.py +260 -238
- clarifai/modules/css.py +50 -50
- clarifai/modules/pages.py +33 -33
- clarifai/rag/rag.py +312 -288
- clarifai/rag/utils.py +91 -84
- clarifai/runners/models/model_builder.py +906 -802
- clarifai/runners/models/model_class.py +370 -331
- clarifai/runners/models/model_run_locally.py +459 -419
- clarifai/runners/models/model_runner.py +170 -162
- clarifai/runners/models/model_servicer.py +78 -70
- clarifai/runners/server.py +111 -101
- clarifai/runners/utils/code_script.py +225 -187
- clarifai/runners/utils/const.py +4 -1
- clarifai/runners/utils/data_types/__init__.py +12 -0
- clarifai/runners/utils/data_types/data_types.py +598 -0
- clarifai/runners/utils/data_utils.py +387 -440
- clarifai/runners/utils/loader.py +247 -227
- clarifai/runners/utils/method_signatures.py +411 -386
- clarifai/runners/utils/openai_convertor.py +108 -109
- clarifai/runners/utils/serializers.py +175 -179
- clarifai/runners/utils/url_fetcher.py +35 -35
- clarifai/schema/search.py +56 -63
- clarifai/urls/helper.py +125 -102
- clarifai/utils/cli.py +129 -123
- clarifai/utils/config.py +127 -87
- clarifai/utils/constants.py +49 -0
- clarifai/utils/evaluation/helpers.py +503 -466
- clarifai/utils/evaluation/main.py +431 -393
- clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
- clarifai/utils/logging.py +324 -306
- clarifai/utils/misc.py +60 -56
- clarifai/utils/model_train.py +165 -146
- clarifai/utils/protobuf.py +126 -103
- clarifai/versions.py +3 -1
- clarifai/workflows/export.py +48 -50
- clarifai/workflows/utils.py +39 -36
- clarifai/workflows/validate.py +55 -43
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
- clarifai-11.4.0.dist-info/RECORD +109 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/errors.cpython-311.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
- clarifai/client/cli/__init__.py +0 -0
- clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/base_cli.py +0 -88
- clarifai/client/cli/model_cli.py +0 -29
- clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
- clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
- clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/base_typed_model.py +0 -238
- clarifai/runners/models/model_class_refract.py +0 -80
- clarifai/runners/models/model_upload.py +0 -607
- clarifai/runners/models/temp.py +0 -25
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_handler.py +0 -231
- clarifai/runners/utils/data_handler_refract.py +0 -213
- clarifai/runners/utils/data_types.py +0 -469
- clarifai/runners/utils/logger.py +0 -0
- clarifai/runners/utils/openai_format.py +0 -87
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
- clarifai-11.3.0rc2.dist-info/RECORD +0 -322
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
@@ -5,57 +5,62 @@ from typing import List, Optional, Union
|
|
5
5
|
|
6
6
|
@dataclass
|
7
7
|
class TextFeatures:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
"""Text classification datasets preprocessing output features."""
|
9
|
+
|
10
|
+
text: str
|
11
|
+
labels: List[Union[str, int]] = None # List[str or int] to cater for multi-class tasks
|
12
|
+
id: Optional[int] = None # text_id
|
13
|
+
metadata: Optional[dict] = None
|
14
|
+
label_ids: Optional[List[str]] = None
|
14
15
|
|
15
16
|
|
16
17
|
@dataclass
|
17
18
|
class VisualClassificationFeatures:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
"""Image classification datasets preprocessing output features."""
|
20
|
+
|
21
|
+
image_path: str
|
22
|
+
labels: List[Union[str, int]] # List[str or int] to cater for multi-class tasks
|
23
|
+
geo_info: Optional[List[float]] = None # [Longitude, Latitude]
|
24
|
+
id: Optional[int] = None # image_id
|
25
|
+
metadata: Optional[dict] = None
|
26
|
+
image_bytes: Optional[bytes] = None
|
27
|
+
label_ids: Optional[List[str]] = None
|
26
28
|
|
27
29
|
|
28
30
|
@dataclass
|
29
31
|
class VisualDetectionFeatures:
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
32
|
+
"""Image Detection datasets preprocessing output features."""
|
33
|
+
|
34
|
+
image_path: str
|
35
|
+
labels: List[Union[str, int]]
|
36
|
+
bboxes: List[List[float]]
|
37
|
+
geo_info: Optional[List[float]] = None # [Longitude, Latitude]
|
38
|
+
id: Optional[int] = None # image_id
|
39
|
+
metadata: Optional[dict] = None
|
40
|
+
image_bytes: Optional[bytes] = None
|
41
|
+
label_ids: Optional[List[str]] = None
|
39
42
|
|
40
43
|
|
41
44
|
@dataclass
|
42
45
|
class VisualSegmentationFeatures:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
"""Image Segmentation datasets preprocessing output features."""
|
47
|
+
|
48
|
+
image_path: str
|
49
|
+
labels: List[Union[str, int]]
|
50
|
+
polygons: List[List[List[float]]]
|
51
|
+
geo_info: Optional[List[float]] = None # [Longitude, Latitude]
|
52
|
+
id: Optional[int] = None # image_id
|
53
|
+
metadata: Optional[dict] = None
|
54
|
+
image_bytes: Optional[bytes] = None
|
55
|
+
label_ids: Optional[List[str]] = None
|
52
56
|
|
53
57
|
|
54
58
|
@dataclass
|
55
59
|
class MultiModalFeatures:
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
60
|
+
"""Multi-modal datasets preprocessing output features."""
|
61
|
+
|
62
|
+
text: str
|
63
|
+
image_bytes: str
|
64
|
+
labels: List[Union[str, int]] = None # List[str or int] to cater for multi-class tasks
|
65
|
+
id: Optional[int] = None # image_id
|
66
|
+
metadata: Optional[dict] = None
|
@@ -11,217 +11,247 @@ from clarifai.utils.misc import get_uuid
|
|
11
11
|
|
12
12
|
|
13
13
|
class VisualClassificationDataset(ClarifaiDataset):
|
14
|
+
def __init__(
|
15
|
+
self, data_generator: Type[ClarifaiDataLoader], dataset_id: str, max_workers: int = 4
|
16
|
+
) -> None:
|
17
|
+
super().__init__(data_generator, dataset_id, max_workers)
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
19
|
+
def _extract_protos(
|
20
|
+
self, batch_input_ids: List[str]
|
21
|
+
) -> Tuple[List[resources_pb2.Input], List[resources_pb2.Annotation]]:
|
22
|
+
"""Create input image and annotation protos for batch of input ids.
|
23
|
+
Args:
|
24
|
+
batch_input_ids: List of input IDs to retrieve the protos for.
|
25
|
+
Returns:
|
26
|
+
input_protos: List of input protos.
|
27
|
+
annotation_protos: List of annotation protos.
|
28
|
+
"""
|
29
|
+
input_protos, annotation_protos = [], []
|
30
|
+
|
31
|
+
def process_data_item(id):
|
32
|
+
data_item = self.data_generator[id]
|
33
|
+
metadata = Struct()
|
34
|
+
image_path = data_item.image_path
|
35
|
+
labels = (
|
36
|
+
data_item.labels if isinstance(data_item.labels, list) else [data_item.labels]
|
37
|
+
) # clarifai concept
|
38
|
+
label_ids = data_item.label_ids
|
39
|
+
input_id = (
|
40
|
+
f"{self.dataset_id}-{get_uuid(8)}"
|
41
|
+
if data_item.id is None
|
42
|
+
else f"{self.dataset_id}-{str(data_item.id)}"
|
43
|
+
)
|
44
|
+
geo_info = data_item.geo_info
|
45
|
+
if data_item.metadata is not None:
|
46
|
+
metadata.update(data_item.metadata)
|
47
|
+
elif image_path is not None:
|
48
|
+
metadata.update({"filename": os.path.basename(image_path)})
|
49
|
+
else:
|
50
|
+
metadata = None
|
51
|
+
|
52
|
+
self.all_input_ids[id] = input_id
|
53
|
+
if data_item.image_bytes is not None:
|
54
|
+
input_protos.append(
|
55
|
+
Inputs.get_input_from_bytes(
|
56
|
+
input_id=input_id,
|
57
|
+
image_bytes=data_item.image_bytes,
|
58
|
+
dataset_id=self.dataset_id,
|
59
|
+
labels=labels,
|
60
|
+
label_ids=label_ids,
|
61
|
+
geo_info=geo_info,
|
62
|
+
metadata=metadata,
|
63
|
+
)
|
64
|
+
)
|
65
|
+
else:
|
66
|
+
input_protos.append(
|
67
|
+
Inputs.get_input_from_file(
|
68
|
+
input_id=input_id,
|
69
|
+
image_file=image_path,
|
70
|
+
dataset_id=self.dataset_id,
|
71
|
+
labels=labels,
|
72
|
+
label_ids=label_ids,
|
73
|
+
geo_info=geo_info,
|
74
|
+
metadata=metadata,
|
75
|
+
)
|
76
|
+
)
|
77
|
+
|
78
|
+
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
|
79
|
+
futures = [executor.submit(process_data_item, id) for id in batch_input_ids]
|
80
|
+
for job in futures:
|
81
|
+
job.result()
|
82
|
+
|
83
|
+
return input_protos, annotation_protos
|
76
84
|
|
77
85
|
|
78
86
|
class VisualDetectionDataset(ClarifaiDataset):
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
87
|
+
"""Visual detection dataset proto class."""
|
88
|
+
|
89
|
+
def __init__(
|
90
|
+
self, data_generator: Type[ClarifaiDataLoader], dataset_id: str, max_workers: int = 4
|
91
|
+
) -> None:
|
92
|
+
super().__init__(data_generator, dataset_id, max_workers)
|
93
|
+
|
94
|
+
def _extract_protos(
|
95
|
+
self, batch_input_ids: List[int]
|
96
|
+
) -> Tuple[List[resources_pb2.Input], List[resources_pb2.Annotation]]:
|
97
|
+
"""Create input image protos for each data generator item.
|
98
|
+
Args:
|
99
|
+
batch_input_ids: List of input IDs to retrieve the protos for.
|
100
|
+
Returns:
|
101
|
+
input_protos: List of input protos.
|
102
|
+
annotation_protos: List of annotation protos.
|
103
|
+
"""
|
104
|
+
input_protos, annotation_protos = [], []
|
105
|
+
|
106
|
+
def process_data_item(id):
|
107
|
+
data_item = self.data_generator[id]
|
108
|
+
metadata = Struct()
|
109
|
+
image = data_item.image_path
|
110
|
+
labels = data_item.labels # list:[l1,...,ln]
|
111
|
+
if data_item.label_ids is not None:
|
112
|
+
assert len(labels) == len(data_item.label_ids), (
|
113
|
+
"Length of labels and label_ids must be equal"
|
114
|
+
)
|
115
|
+
label_ids = data_item.label_ids
|
116
|
+
else:
|
117
|
+
label_ids = None
|
118
|
+
bboxes = data_item.bboxes # [[xmin,ymin,xmax,ymax],...,[xmin,ymin,xmax,ymax]]
|
119
|
+
input_id = (
|
120
|
+
f"{self.dataset_id}-{get_uuid(8)}"
|
121
|
+
if data_item.id is None
|
122
|
+
else f"{self.dataset_id}-{str(data_item.id)}"
|
123
|
+
)
|
124
|
+
if data_item.metadata is not None:
|
125
|
+
metadata.update(data_item.metadata)
|
126
|
+
else:
|
127
|
+
metadata.update({"filename": os.path.basename(image)})
|
128
|
+
geo_info = data_item.geo_info
|
129
|
+
|
130
|
+
self.all_input_ids[id] = input_id
|
131
|
+
if data_item.image_bytes is not None:
|
132
|
+
input_protos.append(
|
133
|
+
Inputs.get_input_from_bytes(
|
134
|
+
input_id=input_id,
|
135
|
+
image_bytes=data_item.image_bytes,
|
136
|
+
dataset_id=self.dataset_id,
|
137
|
+
geo_info=geo_info,
|
138
|
+
metadata=metadata,
|
139
|
+
)
|
140
|
+
)
|
141
|
+
else:
|
142
|
+
input_protos.append(
|
143
|
+
Inputs.get_input_from_file(
|
144
|
+
input_id=input_id,
|
145
|
+
image_file=image,
|
146
|
+
dataset_id=self.dataset_id,
|
147
|
+
geo_info=geo_info,
|
148
|
+
metadata=metadata,
|
149
|
+
)
|
150
|
+
)
|
151
|
+
# iter over bboxes and labels
|
152
|
+
# one id could have more than one bbox and label
|
153
|
+
for i in range(len(bboxes)):
|
154
|
+
annotation_protos.append(
|
155
|
+
Inputs.get_bbox_proto(
|
156
|
+
input_id=input_id,
|
157
|
+
label=labels[i],
|
158
|
+
bbox=bboxes[i],
|
159
|
+
label_id=label_ids[i] if label_ids else None,
|
160
|
+
)
|
161
|
+
)
|
162
|
+
|
163
|
+
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
|
164
|
+
futures = [executor.submit(process_data_item, id) for id in batch_input_ids]
|
165
|
+
for job in futures:
|
166
|
+
job.result()
|
167
|
+
|
168
|
+
return input_protos, annotation_protos
|
150
169
|
|
151
170
|
|
152
171
|
class VisualSegmentationDataset(ClarifaiDataset):
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
172
|
+
"""Visual segmentation dataset proto class."""
|
173
|
+
|
174
|
+
def __init__(
|
175
|
+
self, data_generator: Type[ClarifaiDataLoader], dataset_id: str, max_workers: int = 4
|
176
|
+
) -> None:
|
177
|
+
super().__init__(data_generator, dataset_id, max_workers)
|
178
|
+
|
179
|
+
def _extract_protos(
|
180
|
+
self, batch_input_ids: List[str]
|
181
|
+
) -> Tuple[List[resources_pb2.Input], List[resources_pb2.Annotation]]:
|
182
|
+
"""Create input image and annotation protos for batch of input ids.
|
183
|
+
Args:
|
184
|
+
batch_input_ids: List of input IDs to retrieve the protos for.
|
185
|
+
Returns:
|
186
|
+
input_protos: List of input protos.
|
187
|
+
annotation_protos: List of annotation protos.
|
188
|
+
"""
|
189
|
+
input_protos, annotation_protos = [], []
|
190
|
+
|
191
|
+
def process_data_item(id):
|
192
|
+
data_item = self.data_generator[id]
|
193
|
+
metadata = Struct()
|
194
|
+
image = data_item.image_path
|
195
|
+
labels = data_item.labels
|
196
|
+
if data_item.label_ids is not None:
|
197
|
+
assert len(labels) == len(data_item.label_ids), (
|
198
|
+
"Length of labels and label_ids must be equal"
|
199
|
+
)
|
200
|
+
label_ids = data_item.label_ids
|
201
|
+
else:
|
202
|
+
label_ids = None
|
203
|
+
_polygons = data_item.polygons # list of polygons: [[[x,y],...,[x,y]],...]
|
204
|
+
input_id = (
|
205
|
+
f"{self.dataset_id}-{get_uuid(8)}"
|
206
|
+
if data_item.id is None
|
207
|
+
else f"{self.dataset_id}-{str(data_item.id)}"
|
208
|
+
)
|
209
|
+
if data_item.metadata is not None:
|
210
|
+
metadata.update(data_item.metadata)
|
211
|
+
else:
|
212
|
+
metadata.update({"filename": os.path.basename(image)})
|
213
|
+
geo_info = data_item.geo_info
|
214
|
+
|
215
|
+
self.all_input_ids[id] = input_id
|
216
|
+
if data_item.image_bytes is not None:
|
217
|
+
input_protos.append(
|
218
|
+
Inputs.get_input_from_bytes(
|
219
|
+
input_id=input_id,
|
220
|
+
image_bytes=data_item.image_bytes,
|
221
|
+
dataset_id=self.dataset_id,
|
222
|
+
geo_info=geo_info,
|
223
|
+
metadata=metadata,
|
224
|
+
)
|
225
|
+
)
|
226
|
+
else:
|
227
|
+
input_protos.append(
|
228
|
+
Inputs.get_input_from_file(
|
229
|
+
input_id=input_id,
|
230
|
+
image_file=image,
|
231
|
+
dataset_id=self.dataset_id,
|
232
|
+
geo_info=geo_info,
|
233
|
+
metadata=metadata,
|
234
|
+
)
|
235
|
+
)
|
236
|
+
|
237
|
+
## Iterate over each masked image and create a proto for upload to clarifai
|
238
|
+
## The length of masks/polygons-list and labels must be equal
|
239
|
+
for i, _polygon in enumerate(_polygons):
|
240
|
+
try:
|
241
|
+
annotation_protos.append(
|
242
|
+
Inputs.get_mask_proto(
|
243
|
+
input_id=input_id,
|
244
|
+
label=labels[i],
|
245
|
+
polygons=_polygon,
|
246
|
+
label_id=label_ids[i] if label_ids else None,
|
247
|
+
)
|
248
|
+
)
|
249
|
+
except IndexError:
|
250
|
+
continue
|
251
|
+
|
252
|
+
with ThreadPoolExecutor(max_workers=self.max_workers) as executor:
|
253
|
+
futures = [executor.submit(process_data_item, id) for id in batch_input_ids]
|
254
|
+
for job in futures:
|
255
|
+
job.result()
|
256
|
+
|
257
|
+
return input_protos, annotation_protos
|
@@ -6,49 +6,51 @@ from clarifai.datasets.upload.base import ClarifaiDataLoader
|
|
6
6
|
|
7
7
|
from ..features import VisualClassificationFeatures
|
8
8
|
|
9
|
-
#pycocotools is a dependency for this loader
|
9
|
+
# pycocotools is a dependency for this loader
|
10
10
|
try:
|
11
|
-
|
11
|
+
from pycocotools.coco import COCO
|
12
12
|
except ImportError:
|
13
|
-
|
14
|
-
|
13
|
+
raise ImportError(
|
14
|
+
"Could not import pycocotools package. "
|
15
|
+
"Please do `pip install 'clarifai[all]'` to import pycocotools."
|
16
|
+
)
|
15
17
|
|
16
18
|
|
17
19
|
class COCOCaptionsDataLoader(ClarifaiDataLoader):
|
18
|
-
|
20
|
+
"""COCO Image Captioning Dataset."""
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
def __init__(self, images_dir, label_filepath):
|
23
|
+
"""
|
24
|
+
Args:
|
25
|
+
images_dir: Directory containing the images.
|
26
|
+
label_filepath: Path to the COCO annotation file.
|
27
|
+
"""
|
28
|
+
self.images_dir = images_dir
|
29
|
+
self.label_filepath = label_filepath
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
+
self.map_ids = {}
|
32
|
+
self.load_data()
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
-
|
34
|
+
@property
|
35
|
+
def task(self):
|
36
|
+
return "visual_captioning"
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
38
|
+
def load_data(self) -> None:
|
39
|
+
self.coco = COCO(self.label_filepath)
|
40
|
+
self.map_ids = {i: img_id for i, img_id in enumerate(list(self.coco.imgs.keys()))}
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
def __len__(self):
|
43
|
+
return len(self.coco.imgs)
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def __getitem__(self, index):
|
46
|
+
value = self.coco.imgs[self.map_ids[index]]
|
47
|
+
image_path = os.path.join(self.images_dir, value['file_name'])
|
48
|
+
annots = []
|
47
49
|
|
48
|
-
|
49
|
-
|
50
|
+
input_ann_ids = self.coco.getAnnIds(imgIds=[value['id']])
|
51
|
+
input_anns = self.coco.loadAnns(input_ann_ids)
|
50
52
|
|
51
|
-
|
52
|
-
|
53
|
+
for ann in input_anns:
|
54
|
+
annots.append(ann['caption'])
|
53
55
|
|
54
|
-
|
56
|
+
return VisualClassificationFeatures(image_path, labels=annots[0], id=str(value['id']))
|