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.
Files changed (336) hide show
  1. clarifai/auth/__init__.py +6 -0
  2. clarifai/auth/helper.py +35 -36
  3. clarifai/auth/register.py +23 -0
  4. clarifai/{client → auth}/stub.py +10 -10
  5. clarifai/client/__init__.py +1 -4
  6. clarifai/client/app.py +483 -0
  7. clarifai/client/auth/__init__.py +4 -0
  8. clarifai/client/{abc.py → auth/abc.py} +2 -2
  9. clarifai/client/auth/helper.py +377 -0
  10. clarifai/client/auth/register.py +23 -0
  11. {clarifai_utils/client → clarifai/client/auth}/stub.py +10 -10
  12. clarifai/client/base.py +112 -0
  13. clarifai/client/dataset.py +290 -0
  14. clarifai/client/input.py +730 -0
  15. clarifai/client/lister.py +41 -0
  16. clarifai/client/model.py +218 -0
  17. clarifai/client/module.py +82 -0
  18. clarifai/client/user.py +125 -0
  19. clarifai/client/workflow.py +194 -0
  20. clarifai/datasets/upload/base.py +66 -0
  21. clarifai/datasets/upload/examples/README.md +31 -0
  22. clarifai/datasets/upload/examples/image_classification/cifar10/dataset.py +42 -0
  23. clarifai/datasets/upload/examples/image_classification/food-101/dataset.py +39 -0
  24. clarifai/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +37 -0
  25. clarifai/{data_upload/datasets → datasets/upload}/features.py +4 -12
  26. clarifai/datasets/upload/image.py +156 -0
  27. clarifai/datasets/upload/loaders/README.md +49 -0
  28. clarifai/{data_upload/datasets/zoo → datasets/upload/loaders}/coco_captions.py +24 -21
  29. {clarifai_utils/data_upload/datasets/zoo → clarifai/datasets/upload/loaders}/coco_detection.py +46 -42
  30. clarifai/datasets/upload/loaders/coco_segmentation.py +166 -0
  31. clarifai/{data_upload/datasets/zoo → datasets/upload/loaders}/imagenet_classification.py +22 -12
  32. clarifai/{data_upload/datasets/zoo → datasets/upload/loaders}/xview_detection.py +44 -53
  33. clarifai/datasets/upload/text.py +50 -0
  34. clarifai/datasets/upload/utils.py +62 -0
  35. clarifai/errors.py +90 -0
  36. clarifai/urls/helper.py +16 -17
  37. clarifai/utils/logging.py +40 -0
  38. clarifai/utils/misc.py +33 -0
  39. clarifai/versions.py +6 -0
  40. {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/LICENSE +1 -1
  41. clarifai-9.7.2.dist-info/METADATA +179 -0
  42. clarifai-9.7.2.dist-info/RECORD +350 -0
  43. clarifai_utils/auth/__init__.py +6 -0
  44. clarifai_utils/auth/helper.py +35 -36
  45. clarifai_utils/auth/register.py +23 -0
  46. clarifai_utils/auth/stub.py +127 -0
  47. clarifai_utils/client/__init__.py +1 -4
  48. clarifai_utils/client/app.py +483 -0
  49. clarifai_utils/client/auth/__init__.py +4 -0
  50. clarifai_utils/client/{abc.py → auth/abc.py} +2 -2
  51. clarifai_utils/client/auth/helper.py +377 -0
  52. clarifai_utils/client/auth/register.py +23 -0
  53. clarifai_utils/client/auth/stub.py +127 -0
  54. clarifai_utils/client/base.py +112 -0
  55. clarifai_utils/client/dataset.py +290 -0
  56. clarifai_utils/client/input.py +730 -0
  57. clarifai_utils/client/lister.py +41 -0
  58. clarifai_utils/client/model.py +218 -0
  59. clarifai_utils/client/module.py +82 -0
  60. clarifai_utils/client/user.py +125 -0
  61. clarifai_utils/client/workflow.py +194 -0
  62. clarifai_utils/datasets/upload/base.py +66 -0
  63. clarifai_utils/datasets/upload/examples/README.md +31 -0
  64. clarifai_utils/datasets/upload/examples/image_classification/cifar10/dataset.py +42 -0
  65. clarifai_utils/datasets/upload/examples/image_classification/food-101/dataset.py +39 -0
  66. clarifai_utils/datasets/upload/examples/text_classification/imdb_dataset/dataset.py +37 -0
  67. clarifai_utils/{data_upload/datasets → datasets/upload}/features.py +4 -12
  68. clarifai_utils/datasets/upload/image.py +156 -0
  69. clarifai_utils/datasets/upload/loaders/README.md +49 -0
  70. clarifai_utils/{data_upload/datasets/zoo → datasets/upload/loaders}/coco_captions.py +24 -21
  71. {clarifai/data_upload/datasets/zoo → clarifai_utils/datasets/upload/loaders}/coco_detection.py +46 -42
  72. clarifai_utils/datasets/upload/loaders/coco_segmentation.py +166 -0
  73. clarifai_utils/{data_upload/datasets/zoo → datasets/upload/loaders}/imagenet_classification.py +22 -12
  74. clarifai_utils/{data_upload/datasets/zoo → datasets/upload/loaders}/xview_detection.py +44 -53
  75. clarifai_utils/datasets/upload/text.py +50 -0
  76. clarifai_utils/datasets/upload/utils.py +62 -0
  77. clarifai_utils/errors.py +90 -0
  78. clarifai_utils/urls/helper.py +16 -17
  79. clarifai_utils/utils/logging.py +40 -0
  80. clarifai_utils/utils/misc.py +33 -0
  81. clarifai_utils/versions.py +6 -0
  82. clarifai/data_upload/README.md +0 -63
  83. clarifai/data_upload/convert_csv.py +0 -182
  84. clarifai/data_upload/datasets/base.py +0 -87
  85. clarifai/data_upload/datasets/image.py +0 -253
  86. clarifai/data_upload/datasets/text.py +0 -60
  87. clarifai/data_upload/datasets/zoo/README.md +0 -55
  88. clarifai/data_upload/datasets/zoo/coco_segmentation.py +0 -160
  89. clarifai/data_upload/examples/README.md +0 -5
  90. clarifai/data_upload/examples/image_classification/cifar10/dataset.py +0 -40
  91. clarifai/data_upload/examples/image_classification/food-101/dataset.py +0 -39
  92. clarifai/data_upload/examples/image_classification/food-101/images/beignets/1036242.jpg +0 -0
  93. clarifai/data_upload/examples/image_classification/food-101/images/beignets/1114182.jpg +0 -0
  94. clarifai/data_upload/examples/image_classification/food-101/images/beignets/2012944.jpg +0 -0
  95. clarifai/data_upload/examples/image_classification/food-101/images/beignets/2464389.jpg +0 -0
  96. clarifai/data_upload/examples/image_classification/food-101/images/beignets/478632.jpg +0 -0
  97. clarifai/data_upload/examples/image_classification/food-101/images/hamburger/1061270.jpg +0 -0
  98. clarifai/data_upload/examples/image_classification/food-101/images/hamburger/1202261.jpg +0 -0
  99. clarifai/data_upload/examples/image_classification/food-101/images/hamburger/1381751.jpg +0 -0
  100. clarifai/data_upload/examples/image_classification/food-101/images/hamburger/3289634.jpg +0 -0
  101. clarifai/data_upload/examples/image_classification/food-101/images/hamburger/862025.jpg +0 -0
  102. clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/102197.jpg +0 -0
  103. clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/2749372.jpg +0 -0
  104. clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/2938268.jpg +0 -0
  105. clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/3590861.jpg +0 -0
  106. clarifai/data_upload/examples/image_classification/food-101/images/prime_rib/746716.jpg +0 -0
  107. clarifai/data_upload/examples/image_classification/food-101/images/ramen/2955110.jpg +0 -0
  108. clarifai/data_upload/examples/image_classification/food-101/images/ramen/3208966.jpg +0 -0
  109. clarifai/data_upload/examples/image_classification/food-101/images/ramen/3270629.jpg +0 -0
  110. clarifai/data_upload/examples/image_classification/food-101/images/ramen/3424562.jpg +0 -0
  111. clarifai/data_upload/examples/image_classification/food-101/images/ramen/544680.jpg +0 -0
  112. clarifai/data_upload/examples/image_detection/voc/annotations/2007_000464.xml +0 -39
  113. clarifai/data_upload/examples/image_detection/voc/annotations/2008_000853.xml +0 -28
  114. clarifai/data_upload/examples/image_detection/voc/annotations/2008_003182.xml +0 -54
  115. clarifai/data_upload/examples/image_detection/voc/annotations/2008_008526.xml +0 -67
  116. clarifai/data_upload/examples/image_detection/voc/annotations/2009_004315.xml +0 -28
  117. clarifai/data_upload/examples/image_detection/voc/annotations/2009_004382.xml +0 -28
  118. clarifai/data_upload/examples/image_detection/voc/annotations/2011_000430.xml +0 -28
  119. clarifai/data_upload/examples/image_detection/voc/annotations/2011_001610.xml +0 -46
  120. clarifai/data_upload/examples/image_detection/voc/annotations/2011_006412.xml +0 -99
  121. clarifai/data_upload/examples/image_detection/voc/annotations/2012_000690.xml +0 -43
  122. clarifai/data_upload/examples/image_detection/voc/dataset.py +0 -76
  123. clarifai/data_upload/examples/image_detection/voc/images/2007_000464.jpg +0 -0
  124. clarifai/data_upload/examples/image_detection/voc/images/2008_000853.jpg +0 -0
  125. clarifai/data_upload/examples/image_detection/voc/images/2008_003182.jpg +0 -0
  126. clarifai/data_upload/examples/image_detection/voc/images/2008_008526.jpg +0 -0
  127. clarifai/data_upload/examples/image_detection/voc/images/2009_004315.jpg +0 -0
  128. clarifai/data_upload/examples/image_detection/voc/images/2009_004382.jpg +0 -0
  129. clarifai/data_upload/examples/image_detection/voc/images/2011_000430.jpg +0 -0
  130. clarifai/data_upload/examples/image_detection/voc/images/2011_001610.jpg +0 -0
  131. clarifai/data_upload/examples/image_detection/voc/images/2011_006412.jpg +0 -0
  132. clarifai/data_upload/examples/image_detection/voc/images/2012_000690.jpg +0 -0
  133. clarifai/data_upload/examples/image_segmentation/coco/annotations/instances_val2017_subset.json +0 -5342
  134. clarifai/data_upload/examples/image_segmentation/coco/dataset.py +0 -107
  135. clarifai/data_upload/examples/image_segmentation/coco/images/000000074646.jpg +0 -0
  136. clarifai/data_upload/examples/image_segmentation/coco/images/000000086956.jpg +0 -0
  137. clarifai/data_upload/examples/image_segmentation/coco/images/000000166563.jpg +0 -0
  138. clarifai/data_upload/examples/image_segmentation/coco/images/000000176857.jpg +0 -0
  139. clarifai/data_upload/examples/image_segmentation/coco/images/000000182202.jpg +0 -0
  140. clarifai/data_upload/examples/image_segmentation/coco/images/000000193245.jpg +0 -0
  141. clarifai/data_upload/examples/image_segmentation/coco/images/000000384850.jpg +0 -0
  142. clarifai/data_upload/examples/image_segmentation/coco/images/000000409630.jpg +0 -0
  143. clarifai/data_upload/examples/image_segmentation/coco/images/000000424349.jpg +0 -0
  144. clarifai/data_upload/examples/image_segmentation/coco/images/000000573008.jpg +0 -0
  145. clarifai/data_upload/examples/text_classification/imdb_dataset/dataset.py +0 -40
  146. clarifai/data_upload/examples.py +0 -17
  147. clarifai/data_upload/upload.py +0 -356
  148. clarifai/dataset_export/dataset_export_inputs.py +0 -205
  149. clarifai/listing/concepts.py +0 -37
  150. clarifai/listing/datasets.py +0 -37
  151. clarifai/listing/inputs.py +0 -111
  152. clarifai/listing/installed_module_versions.py +0 -40
  153. clarifai/listing/lister.py +0 -200
  154. clarifai/listing/models.py +0 -46
  155. clarifai/listing/module_versions.py +0 -42
  156. clarifai/listing/modules.py +0 -36
  157. clarifai/runners/base.py +0 -140
  158. clarifai/runners/example.py +0 -36
  159. clarifai-9.7.0.dist-info/METADATA +0 -99
  160. clarifai-9.7.0.dist-info/RECORD +0 -456
  161. clarifai_utils/data_upload/README.md +0 -63
  162. clarifai_utils/data_upload/convert_csv.py +0 -182
  163. clarifai_utils/data_upload/datasets/base.py +0 -87
  164. clarifai_utils/data_upload/datasets/image.py +0 -253
  165. clarifai_utils/data_upload/datasets/text.py +0 -60
  166. clarifai_utils/data_upload/datasets/zoo/README.md +0 -55
  167. clarifai_utils/data_upload/datasets/zoo/coco_segmentation.py +0 -160
  168. clarifai_utils/data_upload/examples/README.md +0 -5
  169. clarifai_utils/data_upload/examples/image_classification/cifar10/dataset.py +0 -40
  170. clarifai_utils/data_upload/examples/image_classification/food-101/dataset.py +0 -39
  171. clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/1036242.jpg +0 -0
  172. clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/1114182.jpg +0 -0
  173. clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/2012944.jpg +0 -0
  174. clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/2464389.jpg +0 -0
  175. clarifai_utils/data_upload/examples/image_classification/food-101/images/beignets/478632.jpg +0 -0
  176. clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/1061270.jpg +0 -0
  177. clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/1202261.jpg +0 -0
  178. clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/1381751.jpg +0 -0
  179. clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/3289634.jpg +0 -0
  180. clarifai_utils/data_upload/examples/image_classification/food-101/images/hamburger/862025.jpg +0 -0
  181. clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/102197.jpg +0 -0
  182. clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/2749372.jpg +0 -0
  183. clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/2938268.jpg +0 -0
  184. clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/3590861.jpg +0 -0
  185. clarifai_utils/data_upload/examples/image_classification/food-101/images/prime_rib/746716.jpg +0 -0
  186. clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/2955110.jpg +0 -0
  187. clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/3208966.jpg +0 -0
  188. clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/3270629.jpg +0 -0
  189. clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/3424562.jpg +0 -0
  190. clarifai_utils/data_upload/examples/image_classification/food-101/images/ramen/544680.jpg +0 -0
  191. clarifai_utils/data_upload/examples/image_detection/__init__.py +0 -0
  192. clarifai_utils/data_upload/examples/image_detection/voc/__init__.py +0 -0
  193. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2007_000464.xml +0 -39
  194. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2008_000853.xml +0 -28
  195. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2008_003182.xml +0 -54
  196. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2008_008526.xml +0 -67
  197. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2009_004315.xml +0 -28
  198. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2009_004382.xml +0 -28
  199. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2011_000430.xml +0 -28
  200. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2011_001610.xml +0 -46
  201. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2011_006412.xml +0 -99
  202. clarifai_utils/data_upload/examples/image_detection/voc/annotations/2012_000690.xml +0 -43
  203. clarifai_utils/data_upload/examples/image_detection/voc/dataset.py +0 -76
  204. clarifai_utils/data_upload/examples/image_detection/voc/images/2007_000464.jpg +0 -0
  205. clarifai_utils/data_upload/examples/image_detection/voc/images/2008_000853.jpg +0 -0
  206. clarifai_utils/data_upload/examples/image_detection/voc/images/2008_003182.jpg +0 -0
  207. clarifai_utils/data_upload/examples/image_detection/voc/images/2008_008526.jpg +0 -0
  208. clarifai_utils/data_upload/examples/image_detection/voc/images/2009_004315.jpg +0 -0
  209. clarifai_utils/data_upload/examples/image_detection/voc/images/2009_004382.jpg +0 -0
  210. clarifai_utils/data_upload/examples/image_detection/voc/images/2011_000430.jpg +0 -0
  211. clarifai_utils/data_upload/examples/image_detection/voc/images/2011_001610.jpg +0 -0
  212. clarifai_utils/data_upload/examples/image_detection/voc/images/2011_006412.jpg +0 -0
  213. clarifai_utils/data_upload/examples/image_detection/voc/images/2012_000690.jpg +0 -0
  214. clarifai_utils/data_upload/examples/image_segmentation/__init__.py +0 -0
  215. clarifai_utils/data_upload/examples/image_segmentation/coco/__init__.py +0 -0
  216. clarifai_utils/data_upload/examples/image_segmentation/coco/annotations/instances_val2017_subset.json +0 -5342
  217. clarifai_utils/data_upload/examples/image_segmentation/coco/dataset.py +0 -107
  218. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000074646.jpg +0 -0
  219. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000086956.jpg +0 -0
  220. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000166563.jpg +0 -0
  221. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000176857.jpg +0 -0
  222. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000182202.jpg +0 -0
  223. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000193245.jpg +0 -0
  224. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000384850.jpg +0 -0
  225. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000409630.jpg +0 -0
  226. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000424349.jpg +0 -0
  227. clarifai_utils/data_upload/examples/image_segmentation/coco/images/000000573008.jpg +0 -0
  228. clarifai_utils/data_upload/examples/text_classification/__init__.py +0 -0
  229. clarifai_utils/data_upload/examples/text_classification/imdb_dataset/__init__.py +0 -0
  230. clarifai_utils/data_upload/examples/text_classification/imdb_dataset/dataset.py +0 -40
  231. clarifai_utils/data_upload/examples.py +0 -17
  232. clarifai_utils/data_upload/upload.py +0 -356
  233. clarifai_utils/dataset_export/dataset_export_inputs.py +0 -205
  234. clarifai_utils/listing/__init__.py +0 -0
  235. clarifai_utils/listing/concepts.py +0 -37
  236. clarifai_utils/listing/datasets.py +0 -37
  237. clarifai_utils/listing/inputs.py +0 -111
  238. clarifai_utils/listing/installed_module_versions.py +0 -40
  239. clarifai_utils/listing/lister.py +0 -200
  240. clarifai_utils/listing/models.py +0 -46
  241. clarifai_utils/listing/module_versions.py +0 -42
  242. clarifai_utils/listing/modules.py +0 -36
  243. clarifai_utils/runners/__init__.py +0 -0
  244. clarifai_utils/runners/base.py +0 -140
  245. clarifai_utils/runners/example.py +0 -36
  246. /clarifai/{data_upload/__init__.py → cli.py} +0 -0
  247. /clarifai/{data_upload/datasets → datasets}/__init__.py +0 -0
  248. /clarifai/{data_upload/datasets/zoo → datasets/upload}/__init__.py +0 -0
  249. /clarifai/{data_upload → datasets/upload}/examples/image_classification/__init__.py +0 -0
  250. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/__init__.py +0 -0
  251. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_test.csv +0 -0
  252. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_train.csv +0 -0
  253. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
  254. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
  255. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
  256. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
  257. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
  258. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
  259. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
  260. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
  261. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
  262. /clarifai/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
  263. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/__init__.py +0 -0
  264. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
  265. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
  266. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
  267. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
  268. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
  269. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
  270. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
  271. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
  272. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
  273. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
  274. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
  275. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
  276. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
  277. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
  278. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
  279. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
  280. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
  281. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
  282. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
  283. /clarifai/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
  284. /clarifai/{data_upload/examples/image_detection → datasets/upload/examples/text_classification}/__init__.py +0 -0
  285. /clarifai/{data_upload/examples/image_detection/voc → datasets/upload/examples/text_classification/imdb_dataset}/__init__.py +0 -0
  286. /clarifai/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/test.csv +0 -0
  287. /clarifai/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/train.csv +0 -0
  288. /clarifai/{data_upload/examples/image_segmentation → datasets/upload/loaders}/__init__.py +0 -0
  289. /clarifai/{data_upload/examples/image_segmentation/coco → utils}/__init__.py +0 -0
  290. {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/WHEEL +0 -0
  291. {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/entry_points.txt +0 -0
  292. {clarifai-9.7.0.dist-info → clarifai-9.7.2.dist-info}/top_level.txt +0 -0
  293. /clarifai/data_upload/examples/text_classification/__init__.py → /clarifai_utils/cli.py +0 -0
  294. {clarifai/data_upload/examples/text_classification/imdb_dataset → clarifai_utils/datasets}/__init__.py +0 -0
  295. {clarifai/listing → clarifai_utils/datasets/upload}/__init__.py +0 -0
  296. {clarifai/runners → clarifai_utils/datasets/upload/examples/image_classification}/__init__.py +0 -0
  297. /clarifai_utils/{data_upload → datasets/upload/examples/image_classification/cifar10}/__init__.py +0 -0
  298. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_test.csv +0 -0
  299. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/cifar_small_train.csv +0 -0
  300. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_700.jpg +0 -0
  301. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_701.jpg +0 -0
  302. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_702.jpg +0 -0
  303. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_703.jpg +0 -0
  304. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_704.jpg +0 -0
  305. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_705.jpg +0 -0
  306. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_706.jpg +0 -0
  307. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_707.jpg +0 -0
  308. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_708.jpg +0 -0
  309. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/cifar10/images/test_batch_709.jpg +0 -0
  310. /clarifai_utils/{data_upload/datasets → datasets/upload/examples/image_classification/food-101}/__init__.py +0 -0
  311. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/1420783.jpg +0 -0
  312. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3287885.jpg +0 -0
  313. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/3617075.jpg +0 -0
  314. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/38052.jpg +0 -0
  315. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/beignets/39147.jpg +0 -0
  316. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/139558.jpg +0 -0
  317. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/1636096.jpg +0 -0
  318. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/2480925.jpg +0 -0
  319. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3385808.jpg +0 -0
  320. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/hamburger/3647386.jpg +0 -0
  321. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/1826869.jpg +0 -0
  322. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2243245.jpg +0 -0
  323. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/259212.jpg +0 -0
  324. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/2842688.jpg +0 -0
  325. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/prime_rib/3035414.jpg +0 -0
  326. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/1545393.jpg +0 -0
  327. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/2427642.jpg +0 -0
  328. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/3520891.jpg +0 -0
  329. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/377566.jpg +0 -0
  330. /clarifai_utils/{data_upload → datasets/upload}/examples/image_classification/food-101/images/ramen/503504.jpg +0 -0
  331. /clarifai_utils/{data_upload/datasets/zoo → datasets/upload/examples/text_classification}/__init__.py +0 -0
  332. /clarifai_utils/{data_upload/examples/image_classification → datasets/upload/examples/text_classification/imdb_dataset}/__init__.py +0 -0
  333. /clarifai_utils/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/test.csv +0 -0
  334. /clarifai_utils/{data_upload → datasets/upload}/examples/text_classification/imdb_dataset/train.csv +0 -0
  335. /clarifai_utils/{data_upload/examples/image_classification/cifar10 → datasets/upload/loaders}/__init__.py +0 -0
  336. /clarifai_utils/{data_upload/examples/image_classification/food-101 → utils}/__init__.py +0 -0
@@ -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
@@ -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
- Args:
10
- auth: a ClarifaiAuthHelper object.
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
- 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.
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
- Returns:
92
- user_id: the author of the module.
93
- app_id: the author's app the module was created in.
94
- module_id: the module ID
95
- module_version_id: the version of the module.
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
@@ -0,0 +1,6 @@
1
+ import os
2
+
3
+ CLIENT_VERSION = '9.7.2'
4
+ OS_VER = os.sys.platform
5
+ PYTHON_VERSION = '.'.join(
6
+ map(str, [os.sys.version_info.major, os.sys.version_info.minor, os.sys.version_info.micro]))
@@ -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)]