clarifai 9.10.2__py3-none-any.whl → 9.10.3__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/client/__init__.py +3 -2
- clarifai/client/app.py +39 -23
- clarifai/client/base.py +6 -6
- clarifai/client/dataset.py +113 -55
- clarifai/client/input.py +47 -55
- clarifai/client/model.py +27 -25
- clarifai/client/module.py +13 -11
- clarifai/client/runner.py +5 -3
- clarifai/client/search.py +7 -3
- clarifai/client/user.py +14 -8
- clarifai/client/workflow.py +22 -20
- clarifai/constants/dataset.py +22 -0
- clarifai/datasets/upload/base.py +9 -7
- clarifai/datasets/upload/features.py +3 -3
- clarifai/datasets/upload/image.py +49 -50
- clarifai/datasets/upload/loaders/coco_captions.py +26 -80
- clarifai/datasets/upload/loaders/coco_detection.py +56 -115
- clarifai/datasets/upload/loaders/coco_segmentation.py +69 -137
- clarifai/datasets/upload/loaders/imagenet_classification.py +2 -3
- clarifai/datasets/upload/loaders/xview_detection.py +3 -3
- clarifai/datasets/upload/text.py +16 -16
- clarifai/datasets/upload/utils.py +196 -21
- clarifai/utils/misc.py +21 -0
- clarifai/versions.py +1 -1
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/METADATA +3 -3
- clarifai-9.10.3.dist-info/RECORD +96 -0
- clarifai-9.10.3.dist-info/top_level.txt +1 -0
- clarifai/auth/__init__.py +0 -6
- clarifai/auth/helper.py +0 -367
- clarifai/auth/register.py +0 -23
- clarifai/auth/stub.py +0 -127
- clarifai/datasets/upload/examples/README.md +0 -31
- clarifai/datasets/upload/examples/image_classification/__init__.py +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/__init__.py +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/cifar_small_test.csv +0 -10
- clarifai/datasets/upload/examples/image_classification/cifar10/cifar_small_train.csv +0 -10
- clarifai/datasets/upload/examples/image_classification/cifar10/dataset.py +0 -46
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/__init__.py +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/dataset.py +0 -39
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
- clarifai/datasets/upload/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
- clarifai/datasets/upload/examples/text_classification/__init__.py +0 -0
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/__init__.py +0 -0
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +0 -42
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/test.csv +0 -201
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/train.csv +0 -201
- clarifai/datasets/upload/loaders/README.md +0 -49
- clarifai/models/model_serving/README.md +0 -155
- clarifai/models/model_serving/docs/custom_config.md +0 -33
- clarifai/models/model_serving/docs/dependencies.md +0 -11
- clarifai/models/model_serving/docs/inference_parameters.md +0 -134
- clarifai/models/model_serving/docs/model_types.md +0 -20
- clarifai/models/model_serving/docs/output.md +0 -28
- clarifai/models/model_serving/examples/README.md +0 -7
- clarifai/models/model_serving/examples/image_classification/README.md +0 -9
- clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/README.md +0 -11
- clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/config.json +0 -42
- clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/preprocessor_config.json +0 -15
- clarifai/models/model_serving/examples/image_classification/age_vit/config.pbtxt +0 -23
- clarifai/models/model_serving/examples/image_classification/age_vit/labels.txt +0 -9
- clarifai/models/model_serving/examples/image_classification/age_vit/requirements.txt +0 -7
- clarifai/models/model_serving/examples/text_classification/README.md +0 -9
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/README.md +0 -12
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/config.json +0 -34
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/special_tokens_map.json +0 -1
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/config.pbtxt +0 -21
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/labels.txt +0 -3
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +0 -7
- clarifai/models/model_serving/examples/text_embedding/README.md +0 -9
- clarifai/models/model_serving/examples/text_to_image/README.md +0 -9
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/__init__.py +0 -0
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/inference.py +0 -52
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/model.py +0 -60
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/config.pbtxt +0 -22
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +0 -6
- clarifai/models/model_serving/examples/text_to_text/README.md +0 -10
- clarifai/models/model_serving/examples/text_to_text/bart-summarize/config.pbtxt +0 -20
- clarifai/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +0 -4
- clarifai/models/model_serving/examples/visual_detection/README.md +0 -11
- clarifai/models/model_serving/examples/visual_detection/yolov5x/config.pbtxt +0 -36
- clarifai/models/model_serving/examples/visual_detection/yolov5x/labels.txt +0 -80
- clarifai/models/model_serving/examples/visual_detection/yolov5x/requirements.txt +0 -12
- clarifai/models/model_serving/examples/visual_embedding/README.md +0 -9
- clarifai/models/model_serving/examples/visual_embedding/vit-base/config.pbtxt +0 -22
- clarifai/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +0 -5
- clarifai/models/model_serving/examples/visual_segmentation/README.md +0 -9
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/config.pbtxt +0 -24
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/labels.txt +0 -18
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +0 -5
- clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +0 -24
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +0 -28
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +0 -18
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +0 -18
- clarifai/modules/README.md +0 -5
- clarifai/modules/style.css +0 -217
- clarifai-9.10.2.dist-info/RECORD +0 -386
- clarifai-9.10.2.dist-info/top_level.txt +0 -2
- clarifai_utils/__init__.py +0 -0
- clarifai_utils/auth/__init__.py +0 -6
- clarifai_utils/auth/helper.py +0 -367
- clarifai_utils/auth/register.py +0 -23
- clarifai_utils/auth/stub.py +0 -127
- clarifai_utils/cli.py +0 -0
- clarifai_utils/client/__init__.py +0 -16
- clarifai_utils/client/app.py +0 -684
- clarifai_utils/client/auth/__init__.py +0 -4
- clarifai_utils/client/auth/helper.py +0 -367
- clarifai_utils/client/auth/register.py +0 -23
- clarifai_utils/client/auth/stub.py +0 -127
- clarifai_utils/client/base.py +0 -131
- clarifai_utils/client/dataset.py +0 -442
- clarifai_utils/client/input.py +0 -892
- clarifai_utils/client/lister.py +0 -54
- clarifai_utils/client/model.py +0 -575
- clarifai_utils/client/module.py +0 -94
- clarifai_utils/client/runner.py +0 -161
- clarifai_utils/client/search.py +0 -254
- clarifai_utils/client/user.py +0 -253
- clarifai_utils/client/workflow.py +0 -223
- clarifai_utils/constants/model.py +0 -4
- clarifai_utils/constants/search.py +0 -2
- clarifai_utils/datasets/__init__.py +0 -0
- clarifai_utils/datasets/export/__init__.py +0 -0
- clarifai_utils/datasets/export/inputs_annotations.py +0 -222
- clarifai_utils/datasets/upload/__init__.py +0 -0
- clarifai_utils/datasets/upload/base.py +0 -66
- clarifai_utils/datasets/upload/examples/README.md +0 -31
- clarifai_utils/datasets/upload/examples/image_classification/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/cifar_small_test.csv +0 -10
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/cifar_small_train.csv +0 -10
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/dataset.py +0 -46
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/dataset.py +0 -39
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
- clarifai_utils/datasets/upload/examples/text_classification/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/__init__.py +0 -0
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +0 -42
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/test.csv +0 -201
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/train.csv +0 -201
- clarifai_utils/datasets/upload/features.py +0 -44
- clarifai_utils/datasets/upload/image.py +0 -165
- clarifai_utils/datasets/upload/loaders/README.md +0 -49
- clarifai_utils/datasets/upload/loaders/__init__.py +0 -0
- clarifai_utils/datasets/upload/loaders/coco_captions.py +0 -103
- clarifai_utils/datasets/upload/loaders/coco_detection.py +0 -134
- clarifai_utils/datasets/upload/loaders/coco_segmentation.py +0 -166
- clarifai_utils/datasets/upload/loaders/imagenet_classification.py +0 -59
- clarifai_utils/datasets/upload/loaders/xview_detection.py +0 -148
- clarifai_utils/datasets/upload/text.py +0 -53
- clarifai_utils/datasets/upload/utils.py +0 -63
- clarifai_utils/errors.py +0 -89
- clarifai_utils/models/__init__.py +0 -0
- clarifai_utils/models/api.py +0 -283
- clarifai_utils/models/model_serving/README.md +0 -155
- clarifai_utils/models/model_serving/__init__.py +0 -12
- clarifai_utils/models/model_serving/cli/__init__.py +0 -12
- clarifai_utils/models/model_serving/cli/deploy_cli.py +0 -123
- clarifai_utils/models/model_serving/cli/model_zip.py +0 -61
- clarifai_utils/models/model_serving/cli/repository.py +0 -87
- clarifai_utils/models/model_serving/constants.py +0 -1
- clarifai_utils/models/model_serving/docs/custom_config.md +0 -33
- clarifai_utils/models/model_serving/docs/dependencies.md +0 -11
- clarifai_utils/models/model_serving/docs/inference_parameters.md +0 -134
- clarifai_utils/models/model_serving/docs/model_types.md +0 -20
- clarifai_utils/models/model_serving/docs/output.md +0 -28
- clarifai_utils/models/model_serving/examples/README.md +0 -7
- clarifai_utils/models/model_serving/examples/image_classification/README.md +0 -9
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/inference.py +0 -56
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/model.py +0 -61
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/README.md +0 -11
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/config.json +0 -42
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/preprocessor_config.json +0 -15
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/config.pbtxt +0 -23
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/labels.txt +0 -9
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/requirements.txt +0 -7
- clarifai_utils/models/model_serving/examples/text_classification/README.md +0 -9
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/inference.py +0 -55
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/model.py +0 -61
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/README.md +0 -12
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/config.json +0 -34
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/special_tokens_map.json +0 -1
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/config.pbtxt +0 -21
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/labels.txt +0 -3
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +0 -7
- clarifai_utils/models/model_serving/examples/text_embedding/README.md +0 -9
- clarifai_utils/models/model_serving/examples/text_to_image/README.md +0 -9
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/1/inference.py +0 -52
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/config.pbtxt +0 -22
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +0 -6
- clarifai_utils/models/model_serving/examples/text_to_text/README.md +0 -10
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/1/inference.py +0 -47
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/config.pbtxt +0 -20
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +0 -4
- clarifai_utils/models/model_serving/examples/visual_detection/README.md +0 -11
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/1/inference.py +0 -72
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/1/model.py +0 -61
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/config.pbtxt +0 -36
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/labels.txt +0 -80
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/requirements.txt +0 -12
- clarifai_utils/models/model_serving/examples/visual_embedding/README.md +0 -9
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/1/inference.py +0 -51
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/config.pbtxt +0 -22
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +0 -5
- clarifai_utils/models/model_serving/examples/visual_segmentation/README.md +0 -9
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/1/__init__.py +0 -0
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/1/inference.py +0 -55
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/1/model.py +0 -60
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/config.pbtxt +0 -24
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/labels.txt +0 -18
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +0 -5
- clarifai_utils/models/model_serving/model_config/__init__.py +0 -14
- clarifai_utils/models/model_serving/model_config/config.py +0 -302
- clarifai_utils/models/model_serving/model_config/inference_parameter.py +0 -124
- clarifai_utils/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +0 -24
- clarifai_utils/models/model_serving/model_config/model_types_config/text-classifier.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/text-embedder.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/text-to-image.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/text-to-text.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-classifier.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-detector.yaml +0 -28
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-embedder.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +0 -18
- clarifai_utils/models/model_serving/model_config/serializer.py +0 -134
- clarifai_utils/models/model_serving/models/__init__.py +0 -12
- clarifai_utils/models/model_serving/models/default_test.py +0 -275
- clarifai_utils/models/model_serving/models/inference.py +0 -42
- clarifai_utils/models/model_serving/models/model_types.py +0 -265
- clarifai_utils/models/model_serving/models/output.py +0 -124
- clarifai_utils/models/model_serving/models/pb_model.py +0 -74
- clarifai_utils/models/model_serving/models/test.py +0 -64
- clarifai_utils/models/model_serving/pb_model_repository.py +0 -101
- clarifai_utils/modules/README.md +0 -5
- clarifai_utils/modules/__init__.py +0 -0
- clarifai_utils/modules/css.py +0 -60
- clarifai_utils/modules/pages.py +0 -42
- clarifai_utils/modules/style.css +0 -217
- clarifai_utils/runners/__init__.py +0 -0
- clarifai_utils/runners/example.py +0 -33
- clarifai_utils/schema/search.py +0 -69
- clarifai_utils/urls/helper.py +0 -103
- clarifai_utils/utils/__init__.py +0 -0
- clarifai_utils/utils/logging.py +0 -90
- clarifai_utils/utils/misc.py +0 -33
- clarifai_utils/utils/model_train.py +0 -157
- clarifai_utils/versions.py +0 -6
- clarifai_utils/workflows/__init__.py +0 -0
- clarifai_utils/workflows/export.py +0 -68
- clarifai_utils/workflows/utils.py +0 -59
- clarifai_utils/workflows/validate.py +0 -67
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/LICENSE +0 -0
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/WHEEL +0 -0
- {clarifai-9.10.2.dist-info → clarifai-9.10.3.dist-info}/entry_points.txt +0 -0
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 Clarifai, Inc.
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
# you may not use this file except in compliance with the License.
|
|
4
|
-
# You may obtain a copy of the License at
|
|
5
|
-
#
|
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
#
|
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
# See the License for the specific language governing permissions and
|
|
12
|
-
# limitations under the License.
|
|
13
|
-
"""
|
|
14
|
-
Parse inference model predictions to triton inference responses
|
|
15
|
-
per model type.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
from functools import wraps
|
|
19
|
-
from itertools import zip_longest
|
|
20
|
-
from typing import Callable, Dict
|
|
21
|
-
import numpy as np
|
|
22
|
-
|
|
23
|
-
try:
|
|
24
|
-
import triton_python_backend_utils as pb_utils
|
|
25
|
-
except ModuleNotFoundError:
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def visual_detector(func: Callable):
|
|
30
|
-
"""
|
|
31
|
-
Visual detector type output parser.
|
|
32
|
-
"""
|
|
33
|
-
|
|
34
|
-
@wraps(func)
|
|
35
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
36
|
-
"""
|
|
37
|
-
Format predictions and return clarifai compatible output.
|
|
38
|
-
"""
|
|
39
|
-
out_bboxes = []
|
|
40
|
-
out_labels = []
|
|
41
|
-
out_scores = []
|
|
42
|
-
for item in input_data:
|
|
43
|
-
preds = func(self, item, *args, **kwargs)
|
|
44
|
-
out_bboxes.append(preds.predicted_bboxes)
|
|
45
|
-
out_labels.append(preds.predicted_labels)
|
|
46
|
-
out_scores.append(preds.predicted_scores)
|
|
47
|
-
|
|
48
|
-
if len(out_bboxes) < 1 or len(out_labels) < 1:
|
|
49
|
-
out_tensor_bboxes = pb_utils.Tensor("predicted_bboxes", np.zeros((0, 4), dtype=np.float32))
|
|
50
|
-
out_tensor_labels = pb_utils.Tensor("predicted_labels", np.zeros((0, 1), dtype=np.int32))
|
|
51
|
-
out_tensor_scores = pb_utils.Tensor("predicted_scores", np.zeros((0, 1), dtype=np.float32))
|
|
52
|
-
else:
|
|
53
|
-
out_tensor_bboxes = pb_utils.Tensor("predicted_bboxes",
|
|
54
|
-
np.asarray(out_bboxes, dtype=np.float32))
|
|
55
|
-
out_tensor_labels = pb_utils.Tensor("predicted_labels",
|
|
56
|
-
np.asarray(out_labels, dtype=np.int32))
|
|
57
|
-
out_tensor_scores = pb_utils.Tensor("predicted_scores",
|
|
58
|
-
np.asarray(out_scores, dtype=np.float32))
|
|
59
|
-
|
|
60
|
-
inference_response = pb_utils.InferenceResponse(
|
|
61
|
-
output_tensors=[out_tensor_bboxes, out_tensor_labels, out_tensor_scores])
|
|
62
|
-
|
|
63
|
-
return inference_response
|
|
64
|
-
|
|
65
|
-
return parse_predictions
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
def visual_classifier(func: Callable):
|
|
69
|
-
"""
|
|
70
|
-
Visual classifier type output parser.
|
|
71
|
-
"""
|
|
72
|
-
|
|
73
|
-
@wraps(func)
|
|
74
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
75
|
-
"""
|
|
76
|
-
Format predictions and return clarifai compatible output.
|
|
77
|
-
"""
|
|
78
|
-
out_scores = []
|
|
79
|
-
for item in input_data:
|
|
80
|
-
preds = func(self, item, *args, **kwargs)
|
|
81
|
-
out_scores.append(preds.predicted_scores)
|
|
82
|
-
|
|
83
|
-
out_tensor_scores = pb_utils.Tensor("softmax_predictions",
|
|
84
|
-
np.asarray(out_scores, dtype=np.float32))
|
|
85
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_tensor_scores])
|
|
86
|
-
|
|
87
|
-
return inference_response
|
|
88
|
-
|
|
89
|
-
return parse_predictions
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
def text_classifier(func: Callable):
|
|
93
|
-
"""
|
|
94
|
-
Text classifier type output parser.
|
|
95
|
-
"""
|
|
96
|
-
|
|
97
|
-
@wraps(func)
|
|
98
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
99
|
-
"""
|
|
100
|
-
Format predictions and return clarifai compatible output.
|
|
101
|
-
"""
|
|
102
|
-
out_scores = []
|
|
103
|
-
input_data = [in_elem[0].decode() for in_elem in input_data]
|
|
104
|
-
for item in input_data:
|
|
105
|
-
preds = func(self, item, *args, **kwargs)
|
|
106
|
-
out_scores.append(preds.predicted_scores)
|
|
107
|
-
|
|
108
|
-
out_tensor_scores = pb_utils.Tensor("softmax_predictions",
|
|
109
|
-
np.asarray(out_scores, dtype=np.float32))
|
|
110
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_tensor_scores])
|
|
111
|
-
|
|
112
|
-
return inference_response
|
|
113
|
-
|
|
114
|
-
return parse_predictions
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def text_to_text(func: Callable):
|
|
118
|
-
"""
|
|
119
|
-
Text to text type output parser.
|
|
120
|
-
Convert a sequence of text into another e.g. text generation,
|
|
121
|
-
summarization or translation.
|
|
122
|
-
"""
|
|
123
|
-
|
|
124
|
-
@wraps(func)
|
|
125
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
126
|
-
"""
|
|
127
|
-
Format predictions and return clarifai compatible output.
|
|
128
|
-
"""
|
|
129
|
-
out_text = []
|
|
130
|
-
input_data = [in_elem[0].decode() for in_elem in input_data]
|
|
131
|
-
for item in input_data:
|
|
132
|
-
preds = func(self, item, *args, **kwargs)
|
|
133
|
-
out_text.append(preds.predicted_text)
|
|
134
|
-
|
|
135
|
-
out_text_tensor = pb_utils.Tensor("text", np.asarray(out_text, dtype=object))
|
|
136
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_text_tensor])
|
|
137
|
-
|
|
138
|
-
return inference_response
|
|
139
|
-
|
|
140
|
-
return parse_predictions
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
def text_embedder(func: Callable):
|
|
144
|
-
"""
|
|
145
|
-
Text embedder type output parser.
|
|
146
|
-
Generates embeddings for an input text.
|
|
147
|
-
"""
|
|
148
|
-
|
|
149
|
-
@wraps(func)
|
|
150
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
151
|
-
"""
|
|
152
|
-
Format predictions and return clarifai compatible output.
|
|
153
|
-
"""
|
|
154
|
-
out_embeddings = []
|
|
155
|
-
input_data = [in_elem[0].decode() for in_elem in input_data]
|
|
156
|
-
for item in input_data:
|
|
157
|
-
preds = func(self, item, *args, **kwargs)
|
|
158
|
-
out_embeddings.append(preds.embedding_vector)
|
|
159
|
-
|
|
160
|
-
out_embed_tensor = pb_utils.Tensor("embeddings", np.asarray(out_embeddings, dtype=np.float32))
|
|
161
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_embed_tensor])
|
|
162
|
-
|
|
163
|
-
return inference_response
|
|
164
|
-
|
|
165
|
-
return parse_predictions
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def visual_embedder(func: Callable):
|
|
169
|
-
"""
|
|
170
|
-
Visual embedder type output parser.
|
|
171
|
-
Generates embeddings for an input image.
|
|
172
|
-
"""
|
|
173
|
-
|
|
174
|
-
@wraps(func)
|
|
175
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
176
|
-
"""
|
|
177
|
-
Format predictions and return clarifai compatible output.
|
|
178
|
-
"""
|
|
179
|
-
out_embeddings = []
|
|
180
|
-
for item in input_data:
|
|
181
|
-
preds = func(self, item, *args, **kwargs)
|
|
182
|
-
out_embeddings.append(preds.embedding_vector)
|
|
183
|
-
|
|
184
|
-
out_embed_tensor = pb_utils.Tensor("embeddings", np.asarray(out_embeddings, dtype=np.float32))
|
|
185
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_embed_tensor])
|
|
186
|
-
|
|
187
|
-
return inference_response
|
|
188
|
-
|
|
189
|
-
return parse_predictions
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def visual_segmenter(func: Callable):
|
|
193
|
-
"""
|
|
194
|
-
Visual segmenter type output parser.
|
|
195
|
-
"""
|
|
196
|
-
|
|
197
|
-
@wraps(func)
|
|
198
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
199
|
-
"""
|
|
200
|
-
Format predictions and return clarifai compatible output.
|
|
201
|
-
"""
|
|
202
|
-
masks = []
|
|
203
|
-
for item in input_data:
|
|
204
|
-
preds = func(self, item, *args, **kwargs)
|
|
205
|
-
masks.append(preds.predicted_mask)
|
|
206
|
-
|
|
207
|
-
out_mask_tensor = pb_utils.Tensor("predicted_mask", np.asarray(masks, dtype=np.int64))
|
|
208
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_mask_tensor])
|
|
209
|
-
|
|
210
|
-
return inference_response
|
|
211
|
-
|
|
212
|
-
return parse_predictions
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
def text_to_image(func: Callable):
|
|
216
|
-
"""
|
|
217
|
-
Text to image type output parser.
|
|
218
|
-
"""
|
|
219
|
-
|
|
220
|
-
@wraps(func)
|
|
221
|
-
def parse_predictions(self, input_data: np.ndarray, *args, **kwargs):
|
|
222
|
-
"""
|
|
223
|
-
Format predictions and return clarifai compatible output.
|
|
224
|
-
"""
|
|
225
|
-
gen_images = []
|
|
226
|
-
input_data = [in_elem[0].decode() for in_elem in input_data]
|
|
227
|
-
for item in input_data:
|
|
228
|
-
preds = func(self, item, *args, **kwargs)
|
|
229
|
-
gen_images.append(preds.image)
|
|
230
|
-
|
|
231
|
-
out_image_tensor = pb_utils.Tensor("image", np.asarray(gen_images, dtype=np.uint8))
|
|
232
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_image_tensor])
|
|
233
|
-
|
|
234
|
-
return inference_response
|
|
235
|
-
|
|
236
|
-
return parse_predictions
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
def multimodal_embedder(func: Callable):
|
|
240
|
-
"""
|
|
241
|
-
Multimodal embedder type output parser.
|
|
242
|
-
Generates embeddings for image or text input.
|
|
243
|
-
"""
|
|
244
|
-
|
|
245
|
-
@wraps(func)
|
|
246
|
-
def parse_predictions(self, input_data: Dict[str, np.ndarray], *args, **kwargs):
|
|
247
|
-
"""
|
|
248
|
-
Format predictions and return clarifai compatible output.
|
|
249
|
-
"""
|
|
250
|
-
out_embeddings = []
|
|
251
|
-
for group in zip_longest(*input_data.values()):
|
|
252
|
-
_input_data = dict(zip(input_data, group))
|
|
253
|
-
for k, v in _input_data.items():
|
|
254
|
-
# decode np.object to string
|
|
255
|
-
if isinstance(v, np.ndarray) and v.dtype == np.object_:
|
|
256
|
-
_input_data.update({k: v[0].decode()})
|
|
257
|
-
preds = func(self, _input_data, *args, **kwargs)
|
|
258
|
-
out_embeddings.append(preds.embedding_vector)
|
|
259
|
-
|
|
260
|
-
out_embed_tensor = pb_utils.Tensor("embeddings", np.asarray(out_embeddings, dtype=np.float32))
|
|
261
|
-
inference_response = pb_utils.InferenceResponse(output_tensors=[out_embed_tensor])
|
|
262
|
-
|
|
263
|
-
return inference_response
|
|
264
|
-
|
|
265
|
-
return parse_predictions
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 Clarifai, Inc.
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
# you may not use this file except in compliance with the License.
|
|
4
|
-
# You may obtain a copy of the License at
|
|
5
|
-
#
|
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
#
|
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
# See the License for the specific language governing permissions and
|
|
12
|
-
# limitations under the License.
|
|
13
|
-
"""
|
|
14
|
-
Output Predictions format for different model types.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
from dataclasses import dataclass
|
|
18
|
-
import numpy as np
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@dataclass
|
|
22
|
-
class VisualDetectorOutput:
|
|
23
|
-
predicted_bboxes: np.ndarray
|
|
24
|
-
predicted_labels: np.ndarray
|
|
25
|
-
predicted_scores: np.ndarray
|
|
26
|
-
|
|
27
|
-
def __post_init__(self):
|
|
28
|
-
"""
|
|
29
|
-
Validate input upon initialization.
|
|
30
|
-
"""
|
|
31
|
-
assert self.predicted_bboxes.ndim == self.predicted_labels.ndim == \
|
|
32
|
-
self.predicted_scores.ndim==2, f"All predictions must be 2-dimensional, \
|
|
33
|
-
Got bbox-dims: {self.predicted_bboxes.ndim}, label-dims: {self.predicted_labels.ndim}, \
|
|
34
|
-
scores-dims: {self.predicted_scores.ndim} instead."
|
|
35
|
-
assert self.predicted_bboxes.shape[0] == self.predicted_labels.shape[0] == \
|
|
36
|
-
self.predicted_scores.shape[0], f"The Number of predicted bounding boxes, \
|
|
37
|
-
predicted labels and predicted scores MUST match. Got {len(self.predicted_bboxes)}, \
|
|
38
|
-
{self.predicted_labels.shape[0]}, {self.predicted_scores.shape[0]} instead."
|
|
39
|
-
|
|
40
|
-
if len(self.predicted_labels) > 0:
|
|
41
|
-
assert self.predicted_bboxes.shape[
|
|
42
|
-
1] == 4, f"Box coordinates must have a length of 4. Actual:{self.predicted_bboxes.shape[1]}"
|
|
43
|
-
assert np.all(np.logical_and(0 <= self.predicted_bboxes, self.predicted_bboxes <= 1)), \
|
|
44
|
-
"Bounding box coordinates must be between 0 and 1"
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
@dataclass
|
|
48
|
-
class ClassifierOutput:
|
|
49
|
-
"""
|
|
50
|
-
Takes model softmax predictions
|
|
51
|
-
"""
|
|
52
|
-
predicted_scores: np.ndarray
|
|
53
|
-
|
|
54
|
-
# the index of each predicted score as returned by the model must correspond
|
|
55
|
-
# to the predicted label index in the labels.txt file
|
|
56
|
-
|
|
57
|
-
def __post_init__(self):
|
|
58
|
-
"""
|
|
59
|
-
Validate input upon initialization.
|
|
60
|
-
"""
|
|
61
|
-
assert self.predicted_scores.ndim == 1, \
|
|
62
|
-
f"All predictions must be 1-dimensional, Got scores-dims: {self.predicted_scores.ndim} instead."
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
@dataclass
|
|
66
|
-
class TextOutput:
|
|
67
|
-
"""
|
|
68
|
-
Takes model text predictions
|
|
69
|
-
"""
|
|
70
|
-
predicted_text: np.ndarray
|
|
71
|
-
|
|
72
|
-
def __post_init__(self):
|
|
73
|
-
"""
|
|
74
|
-
Validate input upon initialization.
|
|
75
|
-
"""
|
|
76
|
-
assert self.predicted_text.ndim == 0, \
|
|
77
|
-
f"All predictions must be 0-dimensional, Got text-dims: {self.predicted_text.ndim} instead."
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
@dataclass
|
|
81
|
-
class EmbeddingOutput:
|
|
82
|
-
"""
|
|
83
|
-
Takes embedding vector returned by a model.
|
|
84
|
-
"""
|
|
85
|
-
embedding_vector: np.ndarray
|
|
86
|
-
|
|
87
|
-
def __post_init__(self):
|
|
88
|
-
"""
|
|
89
|
-
Validate input upon initialization.
|
|
90
|
-
"""
|
|
91
|
-
assert self.embedding_vector.ndim == 1, \
|
|
92
|
-
f"Embeddings must be 1-dimensional, Got embedding-dims: {self.embedding_vector.ndim} instead."
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
@dataclass
|
|
96
|
-
class MasksOutput:
|
|
97
|
-
"""
|
|
98
|
-
Takes image segmentation masks returned by a model.
|
|
99
|
-
"""
|
|
100
|
-
predicted_mask: np.ndarray
|
|
101
|
-
|
|
102
|
-
def __post_init__(self):
|
|
103
|
-
"""
|
|
104
|
-
Validate input upon initialization.
|
|
105
|
-
"""
|
|
106
|
-
assert self.predicted_mask.ndim == 2, \
|
|
107
|
-
f"predicted_mask must be 2-dimensional, Got mask dims: {self.predicted_mask.ndim} instead."
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
@dataclass
|
|
111
|
-
class ImageOutput:
|
|
112
|
-
"""
|
|
113
|
-
Takes a predicted/generated image array as returned by a model.
|
|
114
|
-
"""
|
|
115
|
-
image: np.ndarray
|
|
116
|
-
|
|
117
|
-
def __post_init__(self):
|
|
118
|
-
"""
|
|
119
|
-
Validate input upon initialization.
|
|
120
|
-
"""
|
|
121
|
-
assert self.image.ndim == 3, \
|
|
122
|
-
f"Generated image must be 3-dimensional, Got image-dims: {self.image.ndim} instead."
|
|
123
|
-
assert self.image.shape[2] == 3, \
|
|
124
|
-
f"The image channels dimension must equal 3, Got channel dim: {self.image.shape[2]} instead."
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 Clarifai, Inc.
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
# you may not use this file except in compliance with the License.
|
|
4
|
-
# You may obtain a copy of the License at
|
|
5
|
-
#
|
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
#
|
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
# See the License for the specific language governing permissions and
|
|
12
|
-
# limitations under the License.
|
|
13
|
-
"""Triton inference server Python Backend Model."""
|
|
14
|
-
|
|
15
|
-
import os
|
|
16
|
-
import sys
|
|
17
|
-
|
|
18
|
-
try:
|
|
19
|
-
import triton_python_backend_utils as pb_utils
|
|
20
|
-
except ModuleNotFoundError:
|
|
21
|
-
pass
|
|
22
|
-
from google.protobuf import text_format
|
|
23
|
-
from tritonclient.grpc.model_config_pb2 import ModelConfig
|
|
24
|
-
from clarifai.models.model_serving.model_config.inference_parameter import parse_req_parameters
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class TritonPythonModel:
|
|
28
|
-
"""
|
|
29
|
-
Triton Python BE Model.
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
def initialize(self, args):
|
|
33
|
-
"""
|
|
34
|
-
Triton server init.
|
|
35
|
-
"""
|
|
36
|
-
args["model_repository"] = args["model_repository"].replace("/1/model.py", "")
|
|
37
|
-
sys.path.append(os.path.dirname(__file__))
|
|
38
|
-
from inference import InferenceModel
|
|
39
|
-
|
|
40
|
-
self.inference_obj = InferenceModel()
|
|
41
|
-
|
|
42
|
-
# Read input_name from config file
|
|
43
|
-
self.config_msg = ModelConfig()
|
|
44
|
-
with open(os.path.join(args["model_repository"], "config.pbtxt"), "r") as f:
|
|
45
|
-
cfg = f.read()
|
|
46
|
-
text_format.Merge(cfg, self.config_msg)
|
|
47
|
-
self.input_names = [inp.name for inp in self.config_msg.input]
|
|
48
|
-
|
|
49
|
-
def execute(self, requests):
|
|
50
|
-
"""
|
|
51
|
-
Serve model inference requests.
|
|
52
|
-
"""
|
|
53
|
-
responses = []
|
|
54
|
-
|
|
55
|
-
for request in requests:
|
|
56
|
-
parameters = request.parameters()
|
|
57
|
-
parameters = parse_req_parameters(parameters) if parameters else {}
|
|
58
|
-
|
|
59
|
-
if len(self.input_names) == 1:
|
|
60
|
-
in_batch = pb_utils.get_input_tensor_by_name(request, self.input_names[0])
|
|
61
|
-
in_batch = in_batch.as_numpy()
|
|
62
|
-
inference_response = self.inference_obj.get_predictions(in_batch, **parameters)
|
|
63
|
-
else:
|
|
64
|
-
multi_in_batch_dict = {}
|
|
65
|
-
for input_name in self.input_names:
|
|
66
|
-
in_batch = pb_utils.get_input_tensor_by_name(request, input_name)
|
|
67
|
-
in_batch = in_batch.as_numpy() if in_batch is not None else []
|
|
68
|
-
multi_in_batch_dict.update({input_name: in_batch})
|
|
69
|
-
|
|
70
|
-
inference_response = self.inference_obj.get_predictions(multi_in_batch_dict, **parameters)
|
|
71
|
-
|
|
72
|
-
responses.append(inference_response)
|
|
73
|
-
|
|
74
|
-
return responses
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import logging
|
|
2
|
-
import os
|
|
3
|
-
import unittest
|
|
4
|
-
|
|
5
|
-
from clarifai.models.model_serving.models.default_test import DefaultTestInferenceModel
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class CustomTestInferenceModel(DefaultTestInferenceModel):
|
|
9
|
-
"""
|
|
10
|
-
Run this file to test your implementation of InferenceModel in inference.py with default tests of Triton configuration and its output values based on basic predefined inputs
|
|
11
|
-
If you want to write custom testcase or just test output value.
|
|
12
|
-
Please follow these instrucitons:
|
|
13
|
-
1. Name your test function with prefix "test" so that pytest can execute
|
|
14
|
-
2. In order to obtain output of InferenceModel, call `self.triton_get_predictions(input_data)`.
|
|
15
|
-
3. If your input is `image` and you have set custom size of it when building model repository,
|
|
16
|
-
call `self.preprocess(image)` to obtain correct resized input
|
|
17
|
-
4. Run this test by calling
|
|
18
|
-
```bash
|
|
19
|
-
pytest ./your_triton_folder/1/test.py
|
|
20
|
-
#to see std output
|
|
21
|
-
pytest --log-cli-level=INFO -s ./your_triton_folder/1/test.py
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
### Examples:
|
|
25
|
-
+ test text-to-image output
|
|
26
|
-
```
|
|
27
|
-
def test_text_to_image_output(self):
|
|
28
|
-
text = "Test text"
|
|
29
|
-
output = self.triton_get_predictions(text)
|
|
30
|
-
image = output.image # uint8 np.ndarray image
|
|
31
|
-
#show or save
|
|
32
|
-
```
|
|
33
|
-
+ test visual-classifier output
|
|
34
|
-
```
|
|
35
|
-
def test_visual_classifier(self):
|
|
36
|
-
image = cv2.imread("your/local/image.jpg") # Keep in mind of format of image (BGR or RGB)
|
|
37
|
-
output = self.triton_get_predictions(image)
|
|
38
|
-
scores = output.predicted_scores # np.ndarray
|
|
39
|
-
#process scores to get class id and its score
|
|
40
|
-
logger.info(result)
|
|
41
|
-
"""
|
|
42
|
-
|
|
43
|
-
# Insert your inference parameters json path here
|
|
44
|
-
# or insert a dictionary of your_parameter_name and value, e.g dict(x=1.5, y="text", c=True)
|
|
45
|
-
# or Leave it as "" if you don't have it.
|
|
46
|
-
inference_parameters = ""
|
|
47
|
-
|
|
48
|
-
########### Initialization. Do not change it ###########
|
|
49
|
-
__test__ = True
|
|
50
|
-
|
|
51
|
-
def setUp(self) -> None:
|
|
52
|
-
logging.info("Initializing...")
|
|
53
|
-
model_type = "clarifai-model-type" # your model type
|
|
54
|
-
self.intitialize(
|
|
55
|
-
model_type,
|
|
56
|
-
repo_version_dir=os.path.dirname(__file__),
|
|
57
|
-
is_instance_kind_gpu=True,
|
|
58
|
-
inference_parameters=self.inference_parameters)
|
|
59
|
-
|
|
60
|
-
########################################################
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if __name__ == '__main__':
|
|
64
|
-
unittest.main()
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 Clarifai, Inc.
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
# you may not use this file except in compliance with the License.
|
|
4
|
-
# You may obtain a copy of the License at
|
|
5
|
-
#
|
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
#
|
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
# See the License for the specific language governing permissions and
|
|
12
|
-
# limitations under the License.
|
|
13
|
-
"""
|
|
14
|
-
Triton python backend inference model controller.
|
|
15
|
-
"""
|
|
16
|
-
|
|
17
|
-
import inspect
|
|
18
|
-
import os
|
|
19
|
-
from pathlib import Path
|
|
20
|
-
from typing import Callable, Type
|
|
21
|
-
|
|
22
|
-
from .model_config import Serializer, TritonModelConfig
|
|
23
|
-
from .models import inference, pb_model, test
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
class TritonModelRepository:
|
|
27
|
-
"""
|
|
28
|
-
Triton Python BE Model Repository Generator.
|
|
29
|
-
"""
|
|
30
|
-
|
|
31
|
-
def __init__(self, model_config: Type[TritonModelConfig]):
|
|
32
|
-
self.model_config = model_config
|
|
33
|
-
self.config_proto = Serializer(model_config)
|
|
34
|
-
|
|
35
|
-
def _module_to_file(self, module_name: Callable, filename: str, destination_dir: str) -> None:
|
|
36
|
-
"""
|
|
37
|
-
Write Python Module to file.
|
|
38
|
-
|
|
39
|
-
Args:
|
|
40
|
-
-----
|
|
41
|
-
module_name: Python module name to write to file
|
|
42
|
-
filename: Name of the file to write to destination_dir
|
|
43
|
-
destination_dir: Directory to save the generated triton model file.
|
|
44
|
-
|
|
45
|
-
Returns:
|
|
46
|
-
--------
|
|
47
|
-
None
|
|
48
|
-
"""
|
|
49
|
-
module_path: Path = os.path.join(destination_dir, filename)
|
|
50
|
-
source_code = inspect.getsource(module_name)
|
|
51
|
-
with open(module_path, "w") as pb_model:
|
|
52
|
-
pb_model.write(source_code)
|
|
53
|
-
|
|
54
|
-
def build_repository(self, repository_dir: Path = os.curdir):
|
|
55
|
-
"""
|
|
56
|
-
Generate Triton Model Repository.
|
|
57
|
-
|
|
58
|
-
Args:
|
|
59
|
-
-----
|
|
60
|
-
repository_dir: Directory to create triton model repository
|
|
61
|
-
|
|
62
|
-
Returns:
|
|
63
|
-
--------
|
|
64
|
-
None
|
|
65
|
-
"""
|
|
66
|
-
model_repository = self.model_config.model_name
|
|
67
|
-
model_version = self.model_config.model_version
|
|
68
|
-
repository_path = os.path.join(repository_dir, model_repository)
|
|
69
|
-
model_version_path = os.path.join(repository_path, model_version)
|
|
70
|
-
|
|
71
|
-
if not os.path.isdir(repository_path):
|
|
72
|
-
os.mkdir(repository_path)
|
|
73
|
-
self.config_proto.to_file(repository_path)
|
|
74
|
-
for out_field in self.model_config.output:
|
|
75
|
-
#predicted int labels must have corresponding names in file
|
|
76
|
-
if hasattr(out_field, "label_filename"):
|
|
77
|
-
with open(os.path.join(repository_path, "labels.txt"), "w"):
|
|
78
|
-
pass
|
|
79
|
-
else:
|
|
80
|
-
continue
|
|
81
|
-
# gen requirements
|
|
82
|
-
with open(os.path.join(repository_path, "requirements.txt"), "w") as f:
|
|
83
|
-
f.write("clarifai>9.5.3\ntritonclient[all]") # for model upload utils
|
|
84
|
-
|
|
85
|
-
if not os.path.isdir(model_version_path):
|
|
86
|
-
os.mkdir(model_version_path)
|
|
87
|
-
if not os.path.exists(os.path.join(model_version_path, "__init__.py")):
|
|
88
|
-
with open(os.path.join(model_version_path, "__init__.py"), "w"):
|
|
89
|
-
pass
|
|
90
|
-
# generate model.py & inference.py modules
|
|
91
|
-
self._module_to_file(pb_model, filename="model.py", destination_dir=model_version_path)
|
|
92
|
-
self._module_to_file(inference, filename="inference.py", destination_dir=model_version_path)
|
|
93
|
-
# generate test.py
|
|
94
|
-
custom_test_path = os.path.join(model_version_path, "test.py")
|
|
95
|
-
test_source_code = inspect.getsource(test)
|
|
96
|
-
with open(custom_test_path, "w") as fp:
|
|
97
|
-
# change model type
|
|
98
|
-
test_source_code = test_source_code.replace("clarifai-model-type",
|
|
99
|
-
self.model_config.model_type)
|
|
100
|
-
# write it to file
|
|
101
|
-
fp.write(test_source_code)
|
clarifai_utils/modules/README.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
# Module Utils
|
|
2
|
-
|
|
3
|
-
Additional helper functions for creating Clarifai Modules should be placed here so that they can be reused across modules.
|
|
4
|
-
|
|
5
|
-
This should still not import streamlit as we want to keep clarifai-python-utils lightweight. If you find we need utilities for streamlit itself we should start a new repo for that. Please contact support@clarifai.com to do so.
|
|
File without changes
|
clarifai_utils/modules/css.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class ClarifaiStreamlitCSS(object):
|
|
5
|
-
""" ClarifaiStreamlitCSS helps get a consistent style by default for Clarifai provided
|
|
6
|
-
streamlit apps.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
@classmethod
|
|
10
|
-
def insert_default_css(cls, st):
|
|
11
|
-
""" Inserts the default style provided in style.css in this folder into the streamlit page
|
|
12
|
-
|
|
13
|
-
Example:
|
|
14
|
-
ClarifaiStreamlitCSS.insert_default_css()
|
|
15
|
-
|
|
16
|
-
Note:
|
|
17
|
-
This must be placed in both the app.py AND all the pages/*.py files to get the custom styles.
|
|
18
|
-
"""
|
|
19
|
-
file_name = os.path.join(os.path.dirname(__file__), "style.css")
|
|
20
|
-
cls.insert_css_file(file_name, st)
|
|
21
|
-
|
|
22
|
-
@classmethod
|
|
23
|
-
def insert_css_file(cls, css_file, st):
|
|
24
|
-
""" Open the full filename to the css file and insert it's contents the style of the page.
|
|
25
|
-
"""
|
|
26
|
-
with open(css_file) as f:
|
|
27
|
-
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)
|
|
28
|
-
|
|
29
|
-
@classmethod
|
|
30
|
-
def buttonlink(cls, st, label, link, target="_parent", style=""):
|
|
31
|
-
"""
|
|
32
|
-
This is a streamlit button that will link to another page (or _self if target is _self).
|
|
33
|
-
It is styled to look like the other stButton>button buttons that are created with st.button().
|
|
34
|
-
|
|
35
|
-
You must insert_default_css(st) before using on a page.
|
|
36
|
-
|
|
37
|
-
Example:
|
|
38
|
-
ClarifaiStreamlitCSS.insert_default_css(st)
|
|
39
|
-
cols = st.columns(4)
|
|
40
|
-
ClarifaiStreamlitCSS.buttonlink(cols[3], "Button", "https://clarifai.com", "_blank")
|
|
41
|
-
|
|
42
|
-
Args:
|
|
43
|
-
st: the streamlit package.
|
|
44
|
-
label: the text string to display in the button.
|
|
45
|
-
link: the url to link the button to.
|
|
46
|
-
target: to open the link in same page (_parent) or new tab (_blank).
|
|
47
|
-
style: additional style to apply to the button link.
|
|
48
|
-
Ex: "background-color: rgb(45, 164, 78); color:white;" makes the button green background with white text.
|
|
49
|
-
"""
|
|
50
|
-
astyle = ""
|
|
51
|
-
if style:
|
|
52
|
-
astyle = f'style="{style}"'
|
|
53
|
-
|
|
54
|
-
st.markdown(
|
|
55
|
-
f'''
|
|
56
|
-
<div class="stButton">
|
|
57
|
-
<a href="{link}" target="{target}" {astyle}>{label}</a>
|
|
58
|
-
</div>
|
|
59
|
-
''',
|
|
60
|
-
unsafe_allow_html=True)
|