clarifai 9.7.0__py3-none-any.whl → 9.7.2__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/auth/__init__.py +6 -0
- clarifai/auth/helper.py +35 -36
- clarifai/auth/register.py +23 -0
- clarifai/{client → auth}/stub.py +10 -10
- clarifai/client/__init__.py +1 -4
- clarifai/client/app.py +483 -0
- clarifai/client/auth/__init__.py +4 -0
- clarifai/client/{abc.py → auth/abc.py} +2 -2
- clarifai/client/auth/helper.py +377 -0
- clarifai/client/auth/register.py +23 -0
- {clarifai_utils/client → clarifai/client/auth}/stub.py +10 -10
- clarifai/client/base.py +112 -0
- clarifai/client/dataset.py +290 -0
- clarifai/client/input.py +730 -0
- clarifai/client/lister.py +41 -0
- clarifai/client/model.py +218 -0
- clarifai/client/module.py +82 -0
- clarifai/client/user.py +125 -0
- clarifai/client/workflow.py +194 -0
- clarifai/datasets/upload/base.py +66 -0
- clarifai/datasets/upload/examples/README.md +31 -0
- clarifai/datasets/upload/examples/image_classification/cifar10/dataset.py +42 -0
- clarifai/datasets/upload/examples/image_classification/food-101/dataset.py +39 -0
- clarifai/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +37 -0
- clarifai/{data_upload/datasets → datasets/upload}/features.py +4 -12
- clarifai/datasets/upload/image.py +156 -0
- clarifai/datasets/upload/loaders/README.md +49 -0
- clarifai/{data_upload/datasets/zoo → datasets/upload/loaders}/coco_captions.py +24 -21
- {clarifai_utils/data_upload/datasets/zoo → clarifai/datasets/upload/loaders}/coco_detection.py +46 -42
- clarifai/datasets/upload/loaders/coco_segmentation.py +166 -0
- clarifai/{data_upload/datasets/zoo → datasets/upload/loaders}/imagenet_classification.py +22 -12
- clarifai/{data_upload/datasets/zoo → datasets/upload/loaders}/xview_detection.py +44 -53
- clarifai/datasets/upload/text.py +50 -0
- clarifai/datasets/upload/utils.py +62 -0
- clarifai/errors.py +90 -0
- clarifai/urls/helper.py +16 -17
- clarifai/utils/logging.py +40 -0
- clarifai/utils/misc.py +33 -0
- clarifai/versions.py +6 -0
- {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/LICENSE +1 -1
- clarifai-9.7.2.dist-info/METADATA +179 -0
- clarifai-9.7.2.dist-info/RECORD +350 -0
- clarifai_utils/auth/__init__.py +6 -0
- clarifai_utils/auth/helper.py +35 -36
- clarifai_utils/auth/register.py +23 -0
- clarifai_utils/auth/stub.py +127 -0
- clarifai_utils/client/__init__.py +1 -4
- clarifai_utils/client/app.py +483 -0
- clarifai_utils/client/auth/__init__.py +4 -0
- clarifai_utils/client/{abc.py → auth/abc.py} +2 -2
- clarifai_utils/client/auth/helper.py +377 -0
- clarifai_utils/client/auth/register.py +23 -0
- clarifai_utils/client/auth/stub.py +127 -0
- clarifai_utils/client/base.py +112 -0
- clarifai_utils/client/dataset.py +290 -0
- clarifai_utils/client/input.py +730 -0
- clarifai_utils/client/lister.py +41 -0
- clarifai_utils/client/model.py +218 -0
- clarifai_utils/client/module.py +82 -0
- clarifai_utils/client/user.py +125 -0
- clarifai_utils/client/workflow.py +194 -0
- clarifai_utils/datasets/upload/base.py +66 -0
- clarifai_utils/datasets/upload/examples/README.md +31 -0
- clarifai_utils/datasets/upload/examples/image_classification/cifar10/dataset.py +42 -0
- clarifai_utils/datasets/upload/examples/image_classification/food-101/dataset.py +39 -0
- clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +37 -0
- clarifai_utils/{data_upload/datasets → datasets/upload}/features.py +4 -12
- clarifai_utils/datasets/upload/image.py +156 -0
- clarifai_utils/datasets/upload/loaders/README.md +49 -0
- clarifai_utils/{data_upload/datasets/zoo → datasets/upload/loaders}/coco_captions.py +24 -21
- {clarifai/data_upload/datasets/zoo → clarifai_utils/datasets/upload/loaders}/coco_detection.py +46 -42
- clarifai_utils/datasets/upload/loaders/coco_segmentation.py +166 -0
- clarifai_utils/{data_upload/datasets/zoo → datasets/upload/loaders}/imagenet_classification.py +22 -12
- clarifai_utils/{data_upload/datasets/zoo → datasets/upload/loaders}/xview_detection.py +44 -53
- clarifai_utils/datasets/upload/text.py +50 -0
- clarifai_utils/datasets/upload/utils.py +62 -0
- clarifai_utils/errors.py +90 -0
- clarifai_utils/urls/helper.py +16 -17
- clarifai_utils/utils/logging.py +40 -0
- clarifai_utils/utils/misc.py +33 -0
- clarifai_utils/versions.py +6 -0
- clarifai/data_upload/README.md +0 -63
- clarifai/data_upload/convert_csv.py +0 -182
- clarifai/data_upload/datasets/base.py +0 -87
- clarifai/data_upload/datasets/image.py +0 -253
- clarifai/data_upload/datasets/text.py +0 -60
- clarifai/data_upload/datasets/zoo/README.md +0 -55
- clarifai/data_upload/datasets/zoo/coco_segmentation.py +0 -160
- clarifai/data_upload/examples/README.md +0 -5
- clarifai/data_upload/examples/image_classification/cifar10/dataset.py +0 -40
- clarifai/data_upload/examples/image_classification/food-101/dataset.py +0 -39
- clarifai/data_upload/examples/image_classification/food-101/images/beignets/1036242.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/beignets/1114182.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/beignets/2012944.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/beignets/2464389.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/beignets/478632.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/hamburger/1061270.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/hamburger/1202261.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/hamburger/1381751.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/hamburger/3289634.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/hamburger/862025.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/102197.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/2749372.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/2938268.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/3590861.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/746716.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/ramen/2955110.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/ramen/3208966.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/ramen/3270629.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/ramen/3424562.jpg +0 -0
- clarifai/data_upload/examples/image_classification/food-101/images/ramen/544680.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/annotations/2007_000464.xml +0 -39
- clarifai/data_upload/examples/image_detection/voc/annotations/2008_000853.xml +0 -28
- clarifai/data_upload/examples/image_detection/voc/annotations/2008_003182.xml +0 -54
- clarifai/data_upload/examples/image_detection/voc/annotations/2008_008526.xml +0 -67
- clarifai/data_upload/examples/image_detection/voc/annotations/2009_004315.xml +0 -28
- clarifai/data_upload/examples/image_detection/voc/annotations/2009_004382.xml +0 -28
- clarifai/data_upload/examples/image_detection/voc/annotations/2011_000430.xml +0 -28
- clarifai/data_upload/examples/image_detection/voc/annotations/2011_001610.xml +0 -46
- clarifai/data_upload/examples/image_detection/voc/annotations/2011_006412.xml +0 -99
- clarifai/data_upload/examples/image_detection/voc/annotations/2012_000690.xml +0 -43
- clarifai/data_upload/examples/image_detection/voc/dataset.py +0 -76
- clarifai/data_upload/examples/image_detection/voc/images/2007_000464.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2008_000853.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2008_003182.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2008_008526.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2009_004315.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2009_004382.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2011_000430.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2011_001610.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2011_006412.jpg +0 -0
- clarifai/data_upload/examples/image_detection/voc/images/2012_000690.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/annotations/instances_val2017_subset.json +0 -5342
- clarifai/data_upload/examples/image_segmentation/coco/dataset.py +0 -107
- clarifai/data_upload/examples/image_segmentation/coco/images/000000074646.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000086956.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000166563.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000176857.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000182202.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000193245.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000384850.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000409630.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000424349.jpg +0 -0
- clarifai/data_upload/examples/image_segmentation/coco/images/000000573008.jpg +0 -0
- clarifai/data_upload/examples/text_classification/imdb_dataset/dataset.py +0 -40
- clarifai/data_upload/examples.py +0 -17
- clarifai/data_upload/upload.py +0 -356
- clarifai/dataset_export/dataset_export_inputs.py +0 -205
- clarifai/listing/concepts.py +0 -37
- clarifai/listing/datasets.py +0 -37
- clarifai/listing/inputs.py +0 -111
- clarifai/listing/installed_module_versions.py +0 -40
- clarifai/listing/lister.py +0 -200
- clarifai/listing/models.py +0 -46
- clarifai/listing/module_versions.py +0 -42
- clarifai/listing/modules.py +0 -36
- clarifai/runners/base.py +0 -140
- clarifai/runners/example.py +0 -36
- clarifai-9.7.0.dist-info/METADATA +0 -99
- clarifai-9.7.0.dist-info/RECORD +0 -456
- clarifai_utils/data_upload/README.md +0 -63
- clarifai_utils/data_upload/convert_csv.py +0 -182
- clarifai_utils/data_upload/datasets/base.py +0 -87
- clarifai_utils/data_upload/datasets/image.py +0 -253
- clarifai_utils/data_upload/datasets/text.py +0 -60
- clarifai_utils/data_upload/datasets/zoo/README.md +0 -55
- clarifai_utils/data_upload/datasets/zoo/coco_segmentation.py +0 -160
- clarifai_utils/data_upload/examples/README.md +0 -5
- clarifai_utils/data_upload/examples/image_classification/cifar10/dataset.py +0 -40
- clarifai_utils/data_upload/examples/image_classification/food-101/dataset.py +0 -39
- clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/1036242.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/1114182.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/2012944.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/2464389.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/478632.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/1061270.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/1202261.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/1381751.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/3289634.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/862025.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/102197.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/2749372.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/2938268.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/3590861.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/746716.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/2955110.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/3208966.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/3270629.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/3424562.jpg +0 -0
- clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/544680.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/__init__.py +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/__init__.py +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2007_000464.xml +0 -39
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2008_000853.xml +0 -28
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2008_003182.xml +0 -54
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2008_008526.xml +0 -67
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2009_004315.xml +0 -28
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2009_004382.xml +0 -28
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2011_000430.xml +0 -28
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2011_001610.xml +0 -46
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2011_006412.xml +0 -99
- clarifai_utils/data_upload/examples/image_detection/voc/annotations/2012_000690.xml +0 -43
- clarifai_utils/data_upload/examples/image_detection/voc/dataset.py +0 -76
- clarifai_utils/data_upload/examples/image_detection/voc/images/2007_000464.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2008_000853.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2008_003182.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2008_008526.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2009_004315.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2009_004382.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2011_000430.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2011_001610.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2011_006412.jpg +0 -0
- clarifai_utils/data_upload/examples/image_detection/voc/images/2012_000690.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/__init__.py +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/__init__.py +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/annotations/instances_val2017_subset.json +0 -5342
- clarifai_utils/data_upload/examples/image_segmentation/coco/dataset.py +0 -107
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000074646.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000086956.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000166563.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000176857.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000182202.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000193245.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000384850.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000409630.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000424349.jpg +0 -0
- clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000573008.jpg +0 -0
- clarifai_utils/data_upload/examples/text_classification/__init__.py +0 -0
- clarifai_utils/data_upload/examples/text_classification/imdb_dataset/__init__.py +0 -0
- clarifai_utils/data_upload/examples/text_classification/imdb_dataset/dataset.py +0 -40
- clarifai_utils/data_upload/examples.py +0 -17
- clarifai_utils/data_upload/upload.py +0 -356
- clarifai_utils/dataset_export/dataset_export_inputs.py +0 -205
- clarifai_utils/listing/__init__.py +0 -0
- clarifai_utils/listing/concepts.py +0 -37
- clarifai_utils/listing/datasets.py +0 -37
- clarifai_utils/listing/inputs.py +0 -111
- clarifai_utils/listing/installed_module_versions.py +0 -40
- clarifai_utils/listing/lister.py +0 -200
- clarifai_utils/listing/models.py +0 -46
- clarifai_utils/listing/module_versions.py +0 -42
- clarifai_utils/listing/modules.py +0 -36
- clarifai_utils/runners/__init__.py +0 -0
- clarifai_utils/runners/base.py +0 -140
- clarifai_utils/runners/example.py +0 -36
- /clarifai/{data_upload/__init__.py → cli.py} +0 -0
- /clarifai/{data_upload/datasets → datasets}/__init__.py +0 -0
- /clarifai/{data_upload/datasets/zoo → datasets/upload}/__init__.py +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/__init__.py +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/__init__.py +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_test.csv +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_train.csv +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/__init__.py +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
- /clarifai/{data_upload/examples/image_detection → datasets/upload/examples/text_classification}/__init__.py +0 -0
- /clarifai/{data_upload/examples/image_detection/voc → datasets/upload/examples/text_classification/imdb_dataset}/__init__.py +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/test.csv +0 -0
- /clarifai/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/train.csv +0 -0
- /clarifai/{data_upload/examples/image_segmentation → datasets/upload/loaders}/__init__.py +0 -0
- /clarifai/{data_upload/examples/image_segmentation/coco → utils}/__init__.py +0 -0
- {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/WHEEL +0 -0
- {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/entry_points.txt +0 -0
- {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/top_level.txt +0 -0
- /clarifai/data_upload/examples/text_classification/__init__.py → /clarifai_utils/cli.py +0 -0
- {clarifai/data_upload/examples/text_classification/imdb_dataset → clarifai_utils/datasets}/__init__.py +0 -0
- {clarifai/listing → clarifai_utils/datasets/upload}/__init__.py +0 -0
- {clarifai/runners → clarifai_utils/datasets/upload/examples/image_classification}/__init__.py +0 -0
- /clarifai_utils/{data_upload → datasets/upload/examples/image_classification/cifar10}/__init__.py +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_test.csv +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_train.csv +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
- /clarifai_utils/{data_upload/datasets → datasets/upload/examples/image_classification/food-101}/__init__.py +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
- /clarifai_utils/{data_upload/datasets/zoo → datasets/upload/examples/text_classification}/__init__.py +0 -0
- /clarifai_utils/{data_upload/examples/image_classification → datasets/upload/examples/text_classification/imdb_dataset}/__init__.py +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/test.csv +0 -0
- /clarifai_utils/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/train.csv +0 -0
- /clarifai_utils/{data_upload/examples/image_classification/cifar10 → datasets/upload/loaders}/__init__.py +0 -0
- /clarifai_utils/{data_upload/examples/image_classification/food-101 → utils}/__init__.py +0 -0
clarifai_utils/errors.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import json
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
import requests # noqa
|
|
6
|
+
from google.protobuf.json_format import MessageToDict
|
|
7
|
+
|
|
8
|
+
from clarifai.versions import CLIENT_VERSION, OS_VER, PYTHON_VERSION
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class TokenError(Exception):
|
|
12
|
+
pass
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ApiError(Exception):
|
|
16
|
+
""" API Server error """
|
|
17
|
+
|
|
18
|
+
def __init__(self, resource: str, params: dict, method: str,
|
|
19
|
+
response: requests.Response = None) -> None:
|
|
20
|
+
self.resource = resource
|
|
21
|
+
self.params = params
|
|
22
|
+
self.method = method
|
|
23
|
+
self.response = response
|
|
24
|
+
|
|
25
|
+
self.error_code = 'N/A'
|
|
26
|
+
self.error_desc = 'N/A'
|
|
27
|
+
self.error_details = 'N/A'
|
|
28
|
+
response_json = 'N/A'
|
|
29
|
+
|
|
30
|
+
if response is not None:
|
|
31
|
+
response_json_dict = MessageToDict(response)
|
|
32
|
+
|
|
33
|
+
self.error_code = response_json_dict.get('status', {}).get('code', None)
|
|
34
|
+
self.error_desc = response_json_dict.get('status', {}).get('description', None)
|
|
35
|
+
self.error_details = response_json_dict.get('status', {}).get('details', None)
|
|
36
|
+
response_json = json.dumps(response_json_dict['status'], indent=2)
|
|
37
|
+
|
|
38
|
+
current_ts_str = str(time.time())
|
|
39
|
+
|
|
40
|
+
msg = """%(method)s %(resource)s FAILED(%(time_ts)s). error_code: %(error_code)s, error_description: %(error_desc)s, error_details: %(error_details)s
|
|
41
|
+
>> Python client %(client_version)s with Python %(python_version)s on %(os_version)s
|
|
42
|
+
>> %(method)s %(resource)s
|
|
43
|
+
>> REQUEST(%(time_ts)s) %(request)s
|
|
44
|
+
>> RESPONSE(%(time_ts)s) %(response)s""" % {
|
|
45
|
+
'baseurl': '%s/v2/' % _base_url(self.resource),
|
|
46
|
+
'method': method,
|
|
47
|
+
'resource': resource,
|
|
48
|
+
'error_code': self.error_code,
|
|
49
|
+
'error_desc': self.error_desc,
|
|
50
|
+
'error_details': self.error_details,
|
|
51
|
+
'request': json.dumps(params, indent=2),
|
|
52
|
+
'response': response_json,
|
|
53
|
+
'time_ts': current_ts_str,
|
|
54
|
+
'client_version': CLIENT_VERSION,
|
|
55
|
+
'python_version': PYTHON_VERSION,
|
|
56
|
+
'os_version': OS_VER
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
super(ApiError, self).__init__(msg)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ApiClientError(Exception):
|
|
63
|
+
""" API Client Error """
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class UserError(Exception):
|
|
67
|
+
""" User Error """
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class AuthError(Exception):
|
|
71
|
+
"""Raised when a client has missing or invalid authentication."""
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def _base_url(url: str) -> str:
|
|
75
|
+
"""
|
|
76
|
+
Extracts the base URL from the url, which is everything before the 4th slash character.
|
|
77
|
+
https://www.clarifai.com/v2/models/1/output -> https://www.clarifai.com/v2/
|
|
78
|
+
"""
|
|
79
|
+
try:
|
|
80
|
+
return url[:_find_nth(url, '/', 4) + 1]
|
|
81
|
+
except:
|
|
82
|
+
return ''
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def _find_nth(haystack: str, needle: str, n: int) -> int:
|
|
86
|
+
start = haystack.find(needle)
|
|
87
|
+
while start >= 0 and n > 1:
|
|
88
|
+
start = haystack.find(needle, start + len(needle))
|
|
89
|
+
n -= 1
|
|
90
|
+
return start
|
clarifai_utils/urls/helper.py
CHANGED
|
@@ -6,9 +6,9 @@ class ClarifaiUrlHelper(object):
|
|
|
6
6
|
|
|
7
7
|
def __init__(self, auth, module_manager_imv_id="module_manager_install"):
|
|
8
8
|
"""
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
Args:
|
|
10
|
+
auth: a ClarifaiAuthHelper object.
|
|
11
|
+
"""
|
|
12
12
|
self._auth = auth
|
|
13
13
|
self._module_manager_imv_id = module_manager_imv_id
|
|
14
14
|
|
|
@@ -39,12 +39,12 @@ class ClarifaiUrlHelper(object):
|
|
|
39
39
|
def clarifai_url(self, user_id, app_id, resource_type, resource_id, version_id: str = None):
|
|
40
40
|
"""This is the path to the resource in community.
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
42
|
+
Args:
|
|
43
|
+
user_id: the author of the resource.
|
|
44
|
+
app_id: the author's app the resource was created in.
|
|
45
|
+
resource_type: the type of resource. One of "modules", "models", "concepts", "inputs", "workflows", "tasks", "installed_module_versions"
|
|
46
|
+
resource_id: the resource ID
|
|
47
|
+
version_id: the version of the resource.
|
|
48
48
|
"""
|
|
49
49
|
if resource_type not in [
|
|
50
50
|
"modules", "models", "concepts", "inputs", "workflows", "tasks",
|
|
@@ -85,15 +85,14 @@ class ClarifaiUrlHelper(object):
|
|
|
85
85
|
|
|
86
86
|
@classmethod
|
|
87
87
|
def split_module_ui_url(cls, install):
|
|
88
|
-
"""Takes in a path like https://clarifai.com/zeiler/app/modules/module1/versions/2
|
|
89
|
-
to split it apart into it's IDs.
|
|
88
|
+
"""Takes in a path like https://clarifai.com/zeiler/app/modules/module1/versions/2 to split it apart into it's IDs.
|
|
90
89
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
Returns:
|
|
91
|
+
user_id: the author of the module.
|
|
92
|
+
app_id: the author's app the module was created in.
|
|
93
|
+
module_id: the module ID
|
|
94
|
+
module_version_id: the version of the module.
|
|
95
|
+
"""
|
|
97
96
|
user_id, app_id, resource_type, resource_id, resource_version_id = cls.split_clarifai_url(
|
|
98
97
|
install)
|
|
99
98
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from rich.logging import RichHandler
|
|
5
|
+
from rich.table import Table
|
|
6
|
+
from rich.traceback import install
|
|
7
|
+
|
|
8
|
+
install()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def table_from_dict(data, column_names, title="") -> Table:
|
|
12
|
+
"""Use this function for printing tables from a list of dicts."""
|
|
13
|
+
table = Table(title=title, show_header=True, header_style="bold blue")
|
|
14
|
+
for column_name in column_names:
|
|
15
|
+
table.add_column(column_name)
|
|
16
|
+
for row in data:
|
|
17
|
+
req_row = [row.get(column_name, "") for column_name in column_names]
|
|
18
|
+
table.add_row(*req_row)
|
|
19
|
+
return table
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _get_library_name() -> str:
|
|
23
|
+
return __name__.split(".")[0]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _configure_logger(logger_level: str = "ERROR") -> None:
|
|
27
|
+
logging.basicConfig(
|
|
28
|
+
level=logger_level,
|
|
29
|
+
datefmt='%Y-%m-%d %H:%M:%S',
|
|
30
|
+
handlers=[RichHandler(rich_tracebacks=True)])
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def get_logger(logger_level: str = "ERROR", name: Optional[str] = None) -> logging.Logger:
|
|
34
|
+
"""Return a logger with the specified name."""
|
|
35
|
+
|
|
36
|
+
if name is None:
|
|
37
|
+
name = _get_library_name()
|
|
38
|
+
|
|
39
|
+
_configure_logger(logger_level)
|
|
40
|
+
return logging.getLogger(name)
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class Chunker:
|
|
5
|
+
"""Split an input sequence into small chunks."""
|
|
6
|
+
|
|
7
|
+
def __init__(self, seq: List, size: int) -> None:
|
|
8
|
+
self.seq = seq
|
|
9
|
+
self.size = size
|
|
10
|
+
|
|
11
|
+
def chunk(self) -> List[List]:
|
|
12
|
+
"""Chunk input sequence."""
|
|
13
|
+
return [self.seq[pos:pos + self.size] for pos in range(0, len(self.seq), self.size)]
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class BackoffIterator:
|
|
17
|
+
"""Iterator that returns a sequence of backoff values."""
|
|
18
|
+
|
|
19
|
+
def __init__(self):
|
|
20
|
+
self.count = 0
|
|
21
|
+
|
|
22
|
+
def __iter__(self):
|
|
23
|
+
return self
|
|
24
|
+
|
|
25
|
+
def __next__(self):
|
|
26
|
+
if self.count < 1:
|
|
27
|
+
self.count += 1
|
|
28
|
+
return 0.1
|
|
29
|
+
elif self.count < 7:
|
|
30
|
+
self.count += 1
|
|
31
|
+
return 0.01 * (2**(self.count + 4))
|
|
32
|
+
else:
|
|
33
|
+
return 0.01 * (2**10) # 10 seconds
|
clarifai/data_upload/README.md
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
## Data Upload into your app dataset in the Clarifai platform
|
|
2
|
-
|
|
3
|
-
The functionality here allows a user to upload datasets of the specified types and all sizes from a local directory to the Clarifai platform datasets
|
|
4
|
-
|
|
5
|
-
Supported dataset types currently are:
|
|
6
|
-
* Image classification
|
|
7
|
-
* Object detection
|
|
8
|
-
* Text classification
|
|
9
|
-
* Image segmentation
|
|
10
|
-
|
|
11
|
-
The `datasets` package holds methods to preprocess input data and generate input protos that are then sent as request objects in `upload.py` to the Clarifai api to upload into a particular dataset.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
* Create a dataset under any of your apps in the Clarifai platform.
|
|
16
|
-
|
|
17
|
-
#### Upload dataset from dataset package
|
|
18
|
-
* To upload the dataset from a (python)package, create a folder with the structure and files as below.
|
|
19
|
-
|
|
20
|
-
- Package Structure:
|
|
21
|
-
---------------------------
|
|
22
|
-
<folder_name>/
|
|
23
|
-
├──__init__.py
|
|
24
|
-
├── <Your local dir dataset>/
|
|
25
|
-
└──<Your local dir dataset>/dataset.py
|
|
26
|
-
`dataset.py` must implement a class named following the convention, `<dataset_name>Dataset`. This class must accept `split` as the only argument in the `__init__` method and must have a `dataloader()` generator method that formats your local dir dataset and yields either of `VisualClassificationFeatures()`, `VisualDetectionFeatures()`, `VisualSegmentationFeatures()` or `TextFeatures()` as defined in [clarifai/data_upload/datasets/features.py](datasets/features.py). Other methods can be added in the class as seen fit but `dataloader()` is the main method and must be named dataloader.
|
|
27
|
-
|
|
28
|
-
- In a python script (or in the commandline), import the `UploadConfig` class from upload module and then specify the dataset module path in the `from_module` parameter of the `UploadConfig` .i.e.
|
|
29
|
-
|
|
30
|
-
```python
|
|
31
|
-
from clarifai.data_upload.upload import UploadConfig
|
|
32
|
-
|
|
33
|
-
upload_obj = UploadConfig(
|
|
34
|
-
user_id="",
|
|
35
|
-
app_id="",
|
|
36
|
-
pat="", # Clarifai user PAT (not Clarifai app PAT)
|
|
37
|
-
dataset_id="",
|
|
38
|
-
task="<task-name>", # see supported tasks below
|
|
39
|
-
from_module="./path/to/dataset_package/<package-folder-name>",
|
|
40
|
-
split="val" # train, val or test depending on the dataset
|
|
41
|
-
)
|
|
42
|
-
# execute data upload to Clarifai app dataset
|
|
43
|
-
upload_obj.upload_to_clarifai()
|
|
44
|
-
```
|
|
45
|
-
See `examples/` and `examples.py` for reference.
|
|
46
|
-
|
|
47
|
-
For data upload from dataset zoo, see [clarifai/data_upload/datasets/zoo](datasets/zoo)
|
|
48
|
-
* Supported tasks:
|
|
49
|
-
* `text_clf` for text classification.
|
|
50
|
-
* `visual_clf` for image classification.
|
|
51
|
-
* `visual_detection` for object detection.
|
|
52
|
-
* `visual_segmentation` for image segmentation.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
**NOTE**: For text classification datasets, change the base workflow in your clarifai app settings to a Text workflow for a successful upload.
|
|
56
|
-
|
|
57
|
-
## Notes
|
|
58
|
-
|
|
59
|
-
* For datasets not available in the datasets zoo, the user has to handle the preprocessing for their local datasets to convert them into compatible upload formats.
|
|
60
|
-
|
|
61
|
-
* An individual image can have multiple bounding boxes for the same or different classes and so `VisualDetectionFeatures()` classes and bounding boxes lists must match in length with each element of bounding boxes being a list of bbox coordinates ([`x_min, y_min, x_max, y_max`]) corresponding to a single class name in class_names.
|
|
62
|
-
|
|
63
|
-
* For Segmentation tasks, a single image can have multiple masks corresponding to different or the same classes, hence `VisualSegmentationFeatures()` classes and polygons must be lists of the same length as well. Polygons in turn contain lists with each list in turn having an `[x, y]` list points.
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
import csv
|
|
2
|
-
import os
|
|
3
|
-
import sys
|
|
4
|
-
from itertools import chain
|
|
5
|
-
|
|
6
|
-
import pandas as pd
|
|
7
|
-
from sklearn.model_selection import train_test_split
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class DataPreprocessor:
|
|
11
|
-
|
|
12
|
-
def __init__(self, filename, multi_val, separator):
|
|
13
|
-
self.filename = filename
|
|
14
|
-
self.multi_val = multi_val
|
|
15
|
-
self.separator = separator
|
|
16
|
-
self.df = pd.read_csv(filename)
|
|
17
|
-
|
|
18
|
-
def process_data(self):
|
|
19
|
-
text_col = self.get_column("Enter the number of the column that contains the text: ")
|
|
20
|
-
label_col = self.get_column(
|
|
21
|
-
"Enter the number of the column that contains the labels: ", exclude=text_col)
|
|
22
|
-
|
|
23
|
-
self.split_values(label_col)
|
|
24
|
-
self.df[label_col] = self.df[label_col].apply(lambda x: [x] if isinstance(x, str) else x)
|
|
25
|
-
|
|
26
|
-
# Use chain.from_iterable to expand the multi-values if applicable
|
|
27
|
-
unique_labels = list(set(chain.from_iterable(self.df[label_col].values)))
|
|
28
|
-
|
|
29
|
-
print(
|
|
30
|
-
"\nThe following unqiue labels have been found in the '{}' column and will be used in the dataset:".
|
|
31
|
-
format(label_col))
|
|
32
|
-
for i, label in enumerate(unique_labels, start=1):
|
|
33
|
-
print('{}) {}'.format(i, label))
|
|
34
|
-
|
|
35
|
-
self.convert_for_classification(text_col, label_col, unique_labels)
|
|
36
|
-
|
|
37
|
-
def get_column(self, prompt, exclude=None):
|
|
38
|
-
available_columns = self.df.columns.drop(exclude) if exclude else self.df.columns
|
|
39
|
-
if len(available_columns) == 1:
|
|
40
|
-
print(f'\nThe column named \'{available_columns[0]}\' will be used as the labels column.')
|
|
41
|
-
return available_columns[0]
|
|
42
|
-
else:
|
|
43
|
-
for i, col in enumerate(available_columns):
|
|
44
|
-
print(f'{i+1}) {col}')
|
|
45
|
-
col_index = int(input(prompt)) - 1
|
|
46
|
-
return available_columns[col_index]
|
|
47
|
-
|
|
48
|
-
def split_values(self, label_col):
|
|
49
|
-
if self.multi_val.lower() == 'y':
|
|
50
|
-
self.df[label_col] = self.df[label_col].apply(
|
|
51
|
-
lambda x: str(x).split(self.separator) if not isinstance(x, float) else x)
|
|
52
|
-
|
|
53
|
-
def convert_for_classification(self, text_col, label_col, unique_labels):
|
|
54
|
-
# Binary classification
|
|
55
|
-
if len(unique_labels) == 2:
|
|
56
|
-
print("Converting the CSV to be used with binary classification")
|
|
57
|
-
self.df['input.data.text.raw'] = self.df[text_col]
|
|
58
|
-
self.df['input.data.concepts[0].id'] = label_col
|
|
59
|
-
self.df['input.data.concepts[0].value'] = self.df[label_col].apply(
|
|
60
|
-
lambda x: 1 if unique_labels[0] in x else 0)
|
|
61
|
-
self.df = self.df[[
|
|
62
|
-
'input.data.text.raw', 'input.data.concepts[0].id', 'input.data.concepts[0].value'
|
|
63
|
-
]]
|
|
64
|
-
|
|
65
|
-
# Multi-class classification
|
|
66
|
-
else:
|
|
67
|
-
print("Converting the CSV to be used with multi-class classification")
|
|
68
|
-
self.df['input.data.text.raw'] = self.df[text_col].apply(
|
|
69
|
-
lambda x: x[0] if isinstance(x, list) else x)
|
|
70
|
-
for i in range(len(unique_labels)):
|
|
71
|
-
self.df[f'input.data.concepts[{i}].id'] = self.df[label_col].apply(
|
|
72
|
-
lambda x: unique_labels[i] if unique_labels[i] in x else '')
|
|
73
|
-
self.df[f'input.data.concepts[{i}].value'] = self.df[label_col].apply(
|
|
74
|
-
lambda x: 1 if unique_labels[i] in x else '')
|
|
75
|
-
|
|
76
|
-
self.df = self.df[['input.data.text.raw'] +
|
|
77
|
-
[f'input.data.concepts[{i}].id' for i in range(len(unique_labels))] +
|
|
78
|
-
[f'input.data.concepts[{i}].value' for i in range(len(unique_labels))]]
|
|
79
|
-
|
|
80
|
-
# Reorder the columns
|
|
81
|
-
cols = self.df.columns.tolist()
|
|
82
|
-
new_cols = cols[:1] # The first column 'input.data.text.raw'
|
|
83
|
-
pairs = [[cols[i], cols[i + len(unique_labels)]] for i in range(1, len(unique_labels) + 1)]
|
|
84
|
-
for pair in pairs:
|
|
85
|
-
new_cols.extend(pair)
|
|
86
|
-
self.df = self.df[new_cols]
|
|
87
|
-
|
|
88
|
-
# Remove special characters from column names
|
|
89
|
-
self.df.columns = self.df.columns.str.replace("^[\[]|[\]]$", "", regex=True)
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
class DatasetSplitter:
|
|
93
|
-
|
|
94
|
-
def __init__(self, df, split_dataset, shuffle_dataset, seed=555):
|
|
95
|
-
self.df = df
|
|
96
|
-
self.split_dataset = split_dataset
|
|
97
|
-
self.shuffle_dataset = shuffle_dataset
|
|
98
|
-
self.seed = seed if seed != '' else 555
|
|
99
|
-
|
|
100
|
-
def split_and_save(self, filename_base):
|
|
101
|
-
if self.split_dataset.lower() == 'y':
|
|
102
|
-
split_type = self.get_split_type()
|
|
103
|
-
|
|
104
|
-
if split_type == 1:
|
|
105
|
-
train_pct = self.get_percentage(
|
|
106
|
-
'What percentage of the dataset should be used for training? Enter a number between 1 and 99: ',
|
|
107
|
-
99)
|
|
108
|
-
test_pct = 100 - train_pct
|
|
109
|
-
print(f'Data will be split {train_pct}% train, {test_pct}% test') # Added print statement
|
|
110
|
-
elif split_type == 2:
|
|
111
|
-
train_pct = self.get_percentage(
|
|
112
|
-
'What percentage of the dataset should be used for training? Enter a number between 1 and 98: ',
|
|
113
|
-
98)
|
|
114
|
-
max_val_pct = 99 - train_pct # Max percentage for validation is now reduced by 1
|
|
115
|
-
val_pct = self.get_percentage(
|
|
116
|
-
f'What percentage of the dataset should be used for validation? Enter a number between 1 and {max_val_pct}: ',
|
|
117
|
-
max_val_pct)
|
|
118
|
-
test_pct = 100 - train_pct - val_pct
|
|
119
|
-
print(f'Data will be split {train_pct}% train, {val_pct}% validation, {test_pct}% test'
|
|
120
|
-
) # Added print statement
|
|
121
|
-
|
|
122
|
-
train_df, test_df = train_test_split(
|
|
123
|
-
self.df,
|
|
124
|
-
test_size=test_pct / 100,
|
|
125
|
-
random_state=self.seed,
|
|
126
|
-
shuffle=self.shuffle_dataset.lower() == 'y')
|
|
127
|
-
train_df.to_csv(filename_base + '-train.csv', index=False, quoting=csv.QUOTE_MINIMAL)
|
|
128
|
-
test_df.to_csv(filename_base + '-test.csv', index=False, quoting=csv.QUOTE_MINIMAL)
|
|
129
|
-
|
|
130
|
-
if split_type == 2:
|
|
131
|
-
train_df, val_df = train_test_split(
|
|
132
|
-
train_df,
|
|
133
|
-
test_size=val_pct / 100,
|
|
134
|
-
random_state=self.seed,
|
|
135
|
-
shuffle=self.shuffle_dataset.lower() == 'y')
|
|
136
|
-
val_df.to_csv(filename_base + '-validation.csv', index=False, quoting=csv.QUOTE_MINIMAL)
|
|
137
|
-
else:
|
|
138
|
-
self.df.to_csv(filename_base + '.csv', index=False, quoting=csv.QUOTE_MINIMAL)
|
|
139
|
-
|
|
140
|
-
def get_split_type(self):
|
|
141
|
-
split_type = int(
|
|
142
|
-
input(
|
|
143
|
-
'How would you like to split the dataset?\n1) Train and test datasets\n2) Train, validate, and test datasets\n'
|
|
144
|
-
))
|
|
145
|
-
while split_type not in [1, 2]:
|
|
146
|
-
split_type = int(
|
|
147
|
-
input(
|
|
148
|
-
'Invalid option. Enter 1 for "Train and test" or 2 for "Train, validate, and test": '
|
|
149
|
-
))
|
|
150
|
-
return split_type
|
|
151
|
-
|
|
152
|
-
def get_percentage(self, prompt, max_pct):
|
|
153
|
-
pct = int(input(prompt))
|
|
154
|
-
while not 1 <= pct <= max_pct:
|
|
155
|
-
pct = int(input(f'Invalid input. Please enter a number between 1 and {max_pct}: '))
|
|
156
|
-
return pct
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
def main():
|
|
160
|
-
filename = sys.argv[1]
|
|
161
|
-
multi_val = input('Do any columns have multiple values? (y/[n]) ')
|
|
162
|
-
separator = input('Enter the separator: ') if multi_val.lower() == 'y' else None
|
|
163
|
-
|
|
164
|
-
preprocessor = DataPreprocessor(filename, multi_val, separator)
|
|
165
|
-
preprocessor.process_data()
|
|
166
|
-
|
|
167
|
-
split_dataset = input('Would you like to split this dataset? (y/[n]) ')
|
|
168
|
-
shuffle_dataset = 'n'
|
|
169
|
-
seed = '555'
|
|
170
|
-
|
|
171
|
-
if split_dataset.lower() == 'y':
|
|
172
|
-
shuffle_dataset = input('Would you like to shuffle the dataset before splitting? (y/[n]) ')
|
|
173
|
-
if shuffle_dataset.lower() == 'y':
|
|
174
|
-
seed = input('Enter a seed integer or hit enter to use the default [555]: ')
|
|
175
|
-
|
|
176
|
-
splitter = DatasetSplitter(preprocessor.df, split_dataset, shuffle_dataset, seed)
|
|
177
|
-
splitter.split_and_save(os.path.splitext(filename)[0] + '-clarifai')
|
|
178
|
-
print("Done!")
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if __name__ == "__main__":
|
|
182
|
-
main()
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
from collections import defaultdict
|
|
2
|
-
from typing import Iterator, List, Tuple
|
|
3
|
-
|
|
4
|
-
from clarifai_grpc.grpc.api import resources_pb2
|
|
5
|
-
from google.protobuf.struct_pb2 import Struct
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class ClarifaiDataset:
|
|
9
|
-
"""
|
|
10
|
-
Clarifai datasets base class.
|
|
11
|
-
"""
|
|
12
|
-
|
|
13
|
-
def __init__(self, datagen_object: Iterator, dataset_id: str, split: str) -> None:
|
|
14
|
-
self.datagen_object = datagen_object
|
|
15
|
-
self.dataset_id = dataset_id
|
|
16
|
-
self.split = split
|
|
17
|
-
self.input_ids = []
|
|
18
|
-
self._all_input_protos = {}
|
|
19
|
-
self._all_annotation_protos = defaultdict(list)
|
|
20
|
-
|
|
21
|
-
def __len__(self) -> int:
|
|
22
|
-
"""
|
|
23
|
-
Get size of all input protos
|
|
24
|
-
"""
|
|
25
|
-
return len(self._all_input_protos)
|
|
26
|
-
|
|
27
|
-
def _to_list(self, input_protos: Iterator) -> List:
|
|
28
|
-
"""
|
|
29
|
-
Parse protos iterator to list.
|
|
30
|
-
"""
|
|
31
|
-
return list(input_protos)
|
|
32
|
-
|
|
33
|
-
def create_input_protos(self, image_path: str, label: str, input_id: str, dataset_id: str,
|
|
34
|
-
metadata: Struct) -> resources_pb2.Input:
|
|
35
|
-
"""
|
|
36
|
-
Create input protos for each image, label input pair.
|
|
37
|
-
Args:
|
|
38
|
-
`image_path`: path to image.
|
|
39
|
-
`label`: image label
|
|
40
|
-
`input_id: unique input id
|
|
41
|
-
`dataset_id`: Clarifai dataset id
|
|
42
|
-
`metadata`: input metadata
|
|
43
|
-
Returns:
|
|
44
|
-
An input proto representing a single row input
|
|
45
|
-
"""
|
|
46
|
-
raise NotImplementedError()
|
|
47
|
-
|
|
48
|
-
def _extract_protos(self) -> None:
|
|
49
|
-
"""
|
|
50
|
-
Create input image protos for each data generator item.
|
|
51
|
-
"""
|
|
52
|
-
raise NotImplementedError()
|
|
53
|
-
|
|
54
|
-
def get_protos(self, input_ids: List[str]
|
|
55
|
-
) -> Tuple[List[resources_pb2.Input], List[resources_pb2.Annotation]]:
|
|
56
|
-
"""
|
|
57
|
-
Get input and annotation protos based on input_ids.
|
|
58
|
-
Args:
|
|
59
|
-
`input_ids`: List of input IDs to retrieve the protos for.
|
|
60
|
-
Returns:
|
|
61
|
-
Input and Annotation proto iterators for the specified input IDs.
|
|
62
|
-
"""
|
|
63
|
-
input_protos = [self._all_input_protos.get(input_id) for input_id in input_ids]
|
|
64
|
-
annotation_protos = []
|
|
65
|
-
if len(self._all_annotation_protos) > 0:
|
|
66
|
-
annotation_protos = [self._annotation_protos.get(input_id) for input_id in input_ids]
|
|
67
|
-
annotation_protos = [
|
|
68
|
-
ann_proto for ann_protos in annotation_protos for ann_proto in ann_protos
|
|
69
|
-
]
|
|
70
|
-
|
|
71
|
-
return input_protos, annotation_protos
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
class Chunker:
|
|
75
|
-
"""
|
|
76
|
-
Split an input sequence into small chunks.
|
|
77
|
-
"""
|
|
78
|
-
|
|
79
|
-
def __init__(self, seq: List, size: int) -> None:
|
|
80
|
-
self.seq = seq
|
|
81
|
-
self.size = size
|
|
82
|
-
|
|
83
|
-
def chunk(self) -> List[List]:
|
|
84
|
-
"""
|
|
85
|
-
Chunk input sequence.
|
|
86
|
-
"""
|
|
87
|
-
return [self.seq[pos:pos + self.size] for pos in range(0, len(self.seq), self.size)]
|