{"id":20301239,"url":"https://github.com/aniketmaurya/chitra","last_synced_at":"2025-05-15T17:04:53.499Z","repository":{"id":40357238,"uuid":"235809577","full_name":"aniketmaurya/chitra","owner":"aniketmaurya","description":"A multi-functional library for full-stack Deep Learning. Simplifies Model Building, API development, and Model Deployment.","archived":false,"fork":false,"pushed_at":"2025-04-07T20:34:53.000Z","size":23410,"stargazers_count":227,"open_issues_count":1,"forks_count":37,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-05-15T14:55:12.452Z","etag":null,"topics":["bounding-boxes","deep-learning","fastapi","gradcam","hacktoberfest","image-classification","image-dataset","image-processing","machine-learning","mlops","model-deployment","model-interpretation","model-serving","model-visualization","object-detection","python","pytorch","tensorflow","visualization"],"latest_commit_sha":null,"homepage":"https://chitra.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aniketmaurya.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["aniketmaurya"],"patreon":null,"open_collective":null,"ko_fi":"aniketmaurya","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null}},"created_at":"2020-01-23T14:17:54.000Z","updated_at":"2025-04-12T00:48:51.000Z","dependencies_parsed_at":"2022-08-09T18:11:10.325Z","dependency_job_id":"2b82b736-5f30-44c4-a980-6b70e3a792a9","html_url":"https://github.com/aniketmaurya/chitra","commit_stats":{"total_commits":350,"total_committers":15,"mean_commits":"23.333333333333332","dds":0.5914285714285714,"last_synced_commit":"097754efbb55b0a9a7f2f691e941cdbc2fbbb581"},"previous_names":["aniketmaurya/chitra","gradsflow/chitra"],"tags_count":16,"template":false,"template_full_name":"fastai/nbdev_template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketmaurya%2Fchitra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketmaurya%2Fchitra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketmaurya%2Fchitra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketmaurya%2Fchitra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aniketmaurya","download_url":"https://codeload.github.com/aniketmaurya/chitra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254384987,"owners_count":22062422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bounding-boxes","deep-learning","fastapi","gradcam","hacktoberfest","image-classification","image-dataset","image-processing","machine-learning","mlops","model-deployment","model-interpretation","model-serving","model-visualization","object-detection","python","pytorch","tensorflow","visualization"],"created_at":"2024-11-14T16:24:53.028Z","updated_at":"2025-05-15T17:04:53.480Z","avatar_url":"https://github.com/aniketmaurya.png","language":"Python","funding_links":["https://github.com/sponsors/aniketmaurya","https://ko-fi.com/aniketmaurya"],"categories":[],"sub_categories":[],"readme":"# chitra\n\n[![CodeFactor](https://www.codefactor.io/repository/github/gradsflow/chitra/badge)](https://www.codefactor.io/repository/github/gradsflow/chitra)\n[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=aniketmaurya_chitra\u0026metric=coverage)](https://sonarcloud.io/dashboard?id=aniketmaurya_chitra)\n![GitHub issues](https://img.shields.io/github/issues/aniketmaurya/chitra?style=flat)\n[![Documentation Status](https://readthedocs.org/projects/chitra/badge/?version=latest)](https://chitra.readthedocs.io/en/latest/?badge=latest)\n\n## What is chitra?\n\n**chitra** (**चित्र**) is a multi-functional library for full-stack Deep Learning. It simplifies Model Building, API development, and Model Deployment.\n\n### Components\n\n\u003cimg src=\"https://ik.imagekit.io/aniket/chitra/chitra-arch_Vw9AdA4aC.svg\" alt=\"arch\" style=\"width: 80%\"\u003e\n\n\nLoad Image from Internet url, filepath or `numpy` array and plot Bounding Boxes on the images easily.\nModel Training and Explainable AI.\nEasily create UI for Machine Learning models or Rest API backend that can be deployed for serving ML Models in Production.\n\n### 📌 Highlights:\n- [New] [Auto Dockerization of Models](https://chitra.readthedocs.io/en/latest/source/cli/builder/builder-create/) 🐳\n- [New] [Framework Agnostic Model Serving \u0026 Interactive UI prototype app](https://chitra.readthedocs.io/en/latest/source/api/serve/model_server/) ✨🌟\n- [New] [Data Visualization, Bounding Box Visualization](https://chitra.readthedocs.io/en/latest/source/api/image/chitra-class/) 🐶🎨\n- Model interpretation using GradCAM/GradCAM++ with no extra code 🔥\n- Faster data loading without any boilerplate 🤺\n- Progressive resizing of images 🎨\n- Rapid experiments with different models using `chitra.trainer` module 🚀\n\n### 🚘 Implementation Roadmap\n\n- One click deployment to `serverless` platform.\n\n\u003e If you have more use case please [**raise an issue/PR**](https://github.com/aniketmaurya/chitra/issues/new/choose) with the feature you want.\n\u003e If you want to contribute, feel free to raise a PR. It doesn't need to be perfect.\n\u003e We will help you get there.\n\n## 📀 Installation\n\n[![Downloads](https://pepy.tech/badge/chitra)](https://pepy.tech/project/chitra)\n[![Downloads](https://pepy.tech/badge/chitra/month)](https://pepy.tech/project/chitra)\n![GitHub License](https://img.shields.io/github/license/aniketmaurya/chitra?style=flat)\n\n### Using pip (recommended)\n1. Minimum installation\n`pip install -U chitra`\n\n1. Full Installation\n`pip install -U 'chitra[all]'`\n\n1. Install for Training\n`pip install -U 'chitra[nn]'`\n\n1. Install for Serving\n`pip install -U 'chitra[serve]'`\n\n### From source\n\n```\npip install git+https://github.com/aniketmaurya/chitra@master\n```\n\nOr,\n\n```\ngit clone https://github.com/aniketmaurya/chitra.git\ncd chitra\npip install .\n```\n\n## 🧑‍💻 Usage\n\n### Loading data for image classification\n\nChitra `dataloader` and `datagenerator` modules for loading data. `dataloader` is a minimal dataloader that\nreturns `tf.data.Dataset` object. `datagenerator` provides flexibility to users on how they want to load and manipulate\nthe data.\n\n```python\nimport numpy as np\nimport chitra\nfrom chitra.dataloader import Clf\nimport matplotlib.pyplot as plt\n\n\nclf_dl = Clf()\ndata = clf_dl.from_folder(cat_dog_path, target_shape=(224, 224))\nclf_dl.show_batch(8, figsize=(8, 8))\n```\n\n![Show Batch](https://raw.githubusercontent.com/aniketmaurya/chitra/master/docs/assets/images/output_3_1.png)\n\n## Image datagenerator\n\nDataset class provides the flexibility to load image dataset by updating components of the class.\n\nComponents of Dataset class are:\n\n- image file generator\n- resizer\n- label generator\n- image loader\n\nThese components can be updated with custom function by the user according to their dataset structure. For example the\nTiny Imagenet dataset is organized as-\n\n```\ntrain_folder/\n.....folder1/\n    .....file.txt\n    .....folder2/\n           .....image1.jpg\n           .....image2.jpg\n                     .\n                     .\n                     .\n           ......imageN.jpg\n```\n\nThe inbuilt file generator search for images on the `folder1`, now we can just update the `image file generator` and\nrest of the functionality will remain same.\n\n**Dataset also support progressive resizing of images.**\n\n### Updating component\n\n```python\nfrom chitra.datagenerator import Dataset\n\nds = Dataset(data_path)\n# it will load the folders and NOT images\nds.filenames[:3]\n```\n\n\u003cdetails\u003e\u003csummary\u003eOutput\u003c/summary\u003e\n\n    No item present in the image size list\n\n    ['/Users/aniket/Pictures/data/tiny-imagenet-200/train/n02795169/n02795169_boxes.txt',\n     '/Users/aniket/Pictures/data/tiny-imagenet-200/train/n02795169/images',\n     '/Users/aniket/Pictures/data/tiny-imagenet-200/train/n02769748/images']\n\n\u003c/details\u003e\n\n```python\ndef load_files(path):\n    return glob(f'{path}/*/images/*')\n\n\ndef get_label(path):\n    return path.split('/')[-3]\n\n\nds.update_component('get_filenames', load_files)\nds.filenames[:3]\n```\n\n\u003cdetails\u003e\u003csummary\u003eOutput\u003c/summary\u003e\n\n    get_filenames updated with \u003cfunction load_files at 0x7fad6916d0e0\u003e\n    No item present in the image size list\n\n    ['/Users/aniket/Pictures/data/tiny-imagenet-200/train/n02795169/images/n02795169_369.JPEG',\n     '/Users/aniket/Pictures/data/tiny-imagenet-200/train/n02795169/images/n02795169_386.JPEG',\n     '/Users/aniket/Pictures/data/tiny-imagenet-200/train/n02795169/images/n02795169_105.JPEG']\n\n\u003c/details\u003e\n\n### Progressive resizing\n\n\u003e It is the technique to sequentially resize all the images while training the CNNs on smaller to bigger image sizes. Progressive Resizing is described briefly in his terrific fastai course, “Practical Deep Learning for Coders”. A great way to use this technique is to train a model with smaller image size say 64x64, then use the weights of this model to train another model on images of size 128x128 and so on. Each larger-scale model incorporates the previous smaller-scale model layers and weights in its architecture.\n~[KDnuggets](https://www.kdnuggets.com/2019/05/boost-your-image-classification-model.html)\n\n```python\nimage_sz_list = [(28, 28), (32, 32), (64, 64)]\n\nds = Dataset(data_path, image_size=image_sz_list)\nds.update_component('get_filenames', load_files)\nds.update_component('get_label', get_label)\n\n# first call to generator\nfor img, label in ds.generator():\n    print('first call to generator:', img.shape)\n    break\n\n# seconds call to generator\nfor img, label in ds.generator():\n    print('seconds call to generator:', img.shape)\n    break\n\n# third call to generator\nfor img, label in ds.generator():\n    print('third call to generator:', img.shape)\n    break\n```\n\n\u003cdetails\u003e\u003csummary\u003eOutput\u003c/summary\u003e\n\n    get_filenames updated with \u003cfunction load_files at 0x7fad6916d0e0\u003e\n    get_label updated with \u003cfunction get_label at 0x7fad6916d8c0\u003e\n\n    first call to generator: (28, 28, 3)\n    seconds call to generator: (32, 32, 3)\n    third call to generator: (64, 64, 3)\n\n\u003c/details\u003e\n\n### tf.data support\n\nCreating a `tf.data` dataloader was never as easy as this one liner. It converts the Python generator\ninto `tf.data.Dataset` for a faster data loading, prefetching, caching and everything provided by tf.data.\n\n```python\nimage_sz_list = [(28, 28), (32, 32), (64, 64)]\n\nds = Dataset(data_path, image_size=image_sz_list)\nds.update_component('get_filenames', load_files)\nds.update_component('get_label', get_label)\n\ndl = ds.get_tf_dataset()\n\nfor e in dl.take(1):\n    print(e[0].shape)\n\nfor e in dl.take(1):\n    print(e[0].shape)\n\nfor e in dl.take(1):\n    print(e[0].shape)\n```\n\n\u003cdetails\u003e\u003csummary\u003eOutput\u003c/summary\u003e\n\n    get_filenames updated with \u003cfunction load_files at 0x7fad6916d0e0\u003e\n    get_label updated with \u003cdetn get_label at 0x7fad6916d8c0\u003e\n    (28, 28, 3)\n    (32, 32, 3)\n    (64, 64, 3)\n\n\u003c/details\u003e\n\n## Trainer\n\nThe Trainer class inherits from `tf.keras.Model`, it contains everything that is required for training. It exposes\ntrainer.cyclic_fit method which trains the model using Cyclic Learning rate discovered\nby [Leslie Smith](https://arxiv.org/abs/1506.01186).\n\n```python\nfrom chitra.trainer import Trainer, create_cnn\nfrom chitra.datagenerator import Dataset\n\n\nds = Dataset(cat_dog_path, image_size=(224, 224))\nmodel = create_cnn('mobilenetv2', num_classes=2, name='Cat_Dog_Model')\ntrainer = Trainer(ds, model)\n# trainer.summary()\n```\n\n```python\ntrainer.compile2(batch_size=8,\n    optimizer=tf.keras.optimizers.SGD(1e-3, momentum=0.9, nesterov=True),\n    lr_range=(1e-6, 1e-3),\n    loss='binary_crossentropy',\n    metrics=['binary_accuracy'])\n\ntrainer.cyclic_fit(epochs=5,\n    batch_size=8,\n    lr_range=(0.00001, 0.0001),\n)\n```\n\n\u003cdetails\u003e\u003csummary\u003eTraining Loop...\u003c/summary\u003e\n    cyclic learning rate already set!\n\n    Epoch 1/5\n    1/1 [==============================] - 0s 14ms/step - loss: 6.4702 - binary_accuracy: 0.2500\n    Epoch 2/5\n    Returning the last set size which is: (224, 224)\n    1/1 [==============================] - 0s 965us/step - loss: 5.9033 - binary_accuracy: 0.5000\n    Epoch 3/5\n    Returning the last set size which is: (224, 224)\n    1/1 [==============================] - 0s 977us/step - loss: 5.9233 - binary_accuracy: 0.5000\n    Epoch 4/5\n    Returning the last set size which is: (224, 224)\n    1/1 [==============================] - 0s 979us/step - loss: 2.1408 - binary_accuracy: 0.7500\n    Epoch 5/5\n    Returning the last set size which is: (224, 224)\n    1/1 [==============================] - 0s 982us/step - loss: 1.9062 - binary_accuracy: 0.8750\n\n    \u003ctensorflow.python.keras.callbacks.History at 0x7f8b1c3f2410\u003e\n\n\u003c/details\u003e\n\n## ✨ Model Interpretability\n\nIt is important to understand what is going inside the model. Techniques like GradCam and Saliency Maps can visualize\nwhat the Network is learning. `trainer` module has InterpretModel class which creates GradCam and GradCam++\nvisualization with almost no additional code.\n\n```python\nfrom chitra.trainer import InterpretModel\n\ntrainer = Trainer(ds, create_cnn('mobilenetv2', num_classes=1000, keras_applications=False))\nmodel_interpret = InterpretModel(True, trainer)\n\nimage = ds[1][0].numpy().astype('uint8')\nimage = Image.fromarray(image)\nmodel_interpret(image)\nprint(IMAGENET_LABELS[285])\n```\n\n    Returning the last set size which is: (224, 224)\n    index: 282\n    Egyptian Mau\n\n![png](https://raw.githubusercontent.com/aniketmaurya/chitra/master/docs/assets/images/output_22_1.png)\n\n## 🎨 Data Visualization\n\n### Image annotation\n\nBounding Box creation is based on top of `imgaug` library.\n\n```python\nfrom chitra.image import Chitra\nimport matplotlib.pyplot as plt\n\nbbox = [70, 25, 190, 210]\nlabel = 'Dog'\n\nimage = Chitra(image_path, bboxes=bbox, labels=label)\nplt.imshow(image.draw_boxes())\n```\n\n![png](https://raw.githubusercontent.com/aniketmaurya/chitra/master/docs/assets/images/preview-bounding-box.png)\n\nSee [Play with Images](https://chitra.readthedocs.io/en/latest/examples/chitra-class/chitra-class.html) for detailed\nexample!\n\n## 🚀 Model Serving (Framework Agnostic)\n\nChitra can Create Rest API or Interactive UI app for Any Learning Model -\nML, DL, Image Classification, NLP, Tensorflow, PyTorch or SKLearn.\nIt provides `chitra.serve.GradioApp` for building Interactive UI app for ML/DL models\nand `chitra.serve.API` for building Rest API endpoint.\n\n```python\nfrom chitra.serve import create_api\nfrom chitra.trainer import create_cnn\n\nmodel = create_cnn('mobilenetv2', num_classes=2)\ncreate_api(model, run=True, api_type='image-classification')\n```\n\n\u003cdetails\u003e\u003csummary\u003eAPI Docs Preview\u003c/summary\u003e\n\n![Preview Model Server](https://raw.githubusercontent.com/aniketmaurya/chitra/master/docs/examples/model-server/preview.png)\n\n\u003c/details\u003e\n\nSee [Example Section](https://chitra.readthedocs.io/en/latest/source/api/serve/model_server/) for detailed\nexplanation!\n\n## 🛠 Utility\n\nLimit GPU memory or enable dynamic GPU memory growth for Tensorflow.\n\n```python\nfrom chitra.utility.tf_utils import limit_gpu, gpu_dynamic_mem_growth\n\n# limit the amount of GPU required for your training\nlimit_gpu(gpu_id=0, memory_limit=1024 * 2)\n```\n\n    No GPU:0 found in your system!\n\n```python\ngpu_dynamic_mem_growth()\n```\n\n    No GPU found on the machine!\n\n## 🤗 Contribute\n\nContributions of any kind are welcome. Please check the [**Contributing\nGuidelines**](https://github.com/aniketmaurya/chitra/blob/master/CONTRIBUTING.md) before contributing.\n\n## Code Of Conduct\n\nWe pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.\n\nRead full [**Contributor Covenant Code of Conduct**](https://github.com/aniketmaurya/chitra/blob/master/CODE_OF_CONDUCT.md)\n\n## Acknowledgement\n\n*chitra* is built with help of awesome libraries like [Tensorflow 2.x](https://github.com/tensorflow/tensorflow),\n[imgaug](https://github.com/aleju/imgaug), [FastAPI](https://github.com/tiangolo/fastapi) and [Gradio](https://gradio.app).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faniketmaurya%2Fchitra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faniketmaurya%2Fchitra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faniketmaurya%2Fchitra/lists"}