An open API service indexing awesome lists of open source software.

https://github.com/udaylunawat/whats-this-rock

Telegram Rock Classification Bot!
https://github.com/udaylunawat/whats-this-rock

deep-learning docker image-classification image-processing keras machine-learning nbdev python telegram-bot tensorflow

Last synced: 16 days ago
JSON representation

Telegram Rock Classification Bot!

Awesome Lists containing this project

README

          

Whats-this-rock
================


This project deploys a telegram bot that classifies rock images into 1
of 7 types.
What's my name?

[![CI](https://github.com/udaylunawat/Whats-this-rock/actions/workflows/test.yaml/badge.svg)](https://github.com/udaylunawat/Whats-this-rock/actions/workflows/test.yaml) ![GitHub
issues](https://img.shields.io/github/issues-raw/udaylunawat/Whats-this-rock.png)

![code-size](https://img.shields.io/github/languages/code-size/udaylunawat/Whats-this-rock.png)
![repo-size](https://img.shields.io/github/repo-size/udaylunawat/Whats-this-rock.png)
![top-language](https://img.shields.io/github/languages/top/udaylunawat/Whats-this-rock.png)

![Python](https://img.shields.io/badge/python-v3.8.0+-success.svg)
![Tensorflow](https://img.shields.io/badge/tensorflow-v2.9.0+-success.svg)

[![contributions
welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues)
[![HitCount](https://hits.dwyl.com/udaylunawat/Whats-this-rock.svg?style=flat)](http://hits.dwyl.com/udaylunawat/Whats-this-rock)

![](https://img.shields.io/twitter/follow/udaylunawat?style=social.png)

This package uses [tensorflow](https://github.com/tensorflow/tensorflow)
to accelerate deep learning experimentation.

MLOps workflow like

- Experiment Tracking
- Model Management
- Hyperparameter Tuning

was all done using [Weights & Biases](https://wandb.ai)

Additionally, [nbdev](https://github.com/fastai/nbdev) was used to

- develop the package
- produce documentation based on a series of notebooks.
- CI
- publishing to [PyPi](https://pypi.org/project/rocks-classifier/)

## Inspiration

> [The common complaint that you need massive amounts of data to do deep
> learning  can be a very long way from the
> truth!](https://youtu.be/J6XcP4JOHmk?t=2029)

> You very often don’t need much data at all, a lot of people are
> looking for ways to share data and aggregate data, but that’s
> unnecessary.They assume they need more data than they do, cause
> they’re not familiar with the basics of transfer learning which is
> this critical technique for needing orders of magnitudes less data.

> [Jeremy
> Howards](https://en.wikipedia.org/wiki/Jeremy_Howard_(entrepreneur))

## Documentation

Documentation for the project has been created using
[`nbdev`](https://nbdev.fast.ai/getting_started.html), and is available
at
[udaylunawat.github.io/Whats-this-rock](https://udaylunawat.github.io/Whats-this-rock/).

[`nbdev`](https://nbdev.fast.ai/getting_started.html) is a
notebook-driven development platform. Simply write notebooks with
lightweight markup and get high-quality documentation, tests, continuous
integration, and packaging for free!

Once I discovered nbdev, I couldn’t help myself but redo the whole
project from scratch.

It’s just makes me 10x more productive and makes the whole process
streamlined and more enjoyable.

## Installation

You can directly install using pip

``` bash
pip install rocks_classifier
```

Install - Directly from Github (latest beta version)

``` bash
pip install git+https://github.com/udaylunawat/Whats-this-rock.git
```

### Download and process data

``` bash
%%bash
rocks_process_data --config-dir configs \
remove_bad= True \
remove_misclassified= True \
remove_duplicates= True \
remove_corrupted= True \
remove_unsupported= True \
sampling=None \
train_split=0.8 \
```

### Train Model

Train model using default parameters in `configs/config.yaml`.

``` bash
rocks_train_model --config-dir configs
```

You can try different models and parameters by editing
`configs/config.yaml`, or you can override it by passing arguments like
this:-

By using Hydra it’s now much more easier to override parameters like
this:-

``` bash
rocks_train_model --config-dir configs \
wandb.project=Whats-this-rock \
wandb.mode=offline \
wandb.use=False \
dataset_id=[1,2] \
epochs=30 \
lr=0.005 \
augmentation=None \
monitor=val_loss \
loss=categorical_crossentropy \
backbone=resnet \
lr_schedule=cosine_decay_restarts \
lr_decay_steps=300 \
trainable=False \
```



result

### Wandb Sweeps (Hyperparameter Tuning)

Edit `configs/sweep.yaml`

``` bash
wandb sweep \
--project Whats-this-rock \
--entity udaylunawat \
configs/sweep.yaml
```

This will return a command with \$sweepid, run it to start running
sweeps!

``` bash
wandb agent udaylunawat/Whats-this-rock/$sweepid
```

### Telegram Bot

You can try the bot [here](https://t.me/test7385_bot) on Telegram.

> Type `/help` to get instructions in chat.

Or deploy it yourself

``` bash
rocks_deploy_bot
```

## Demo

| Colab | GitHub | Download |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ![alt colab](https://www.tensorflow.org/images/colab_logo_32px.png)[Run in Colab](https://colab.research.google.com/drive/1N1CIqdOKlJSJla5PU53Yn9KWSao47eMv?usp=sharing) | ![alt Source](https://www.tensorflow.org/images/GitHub-Mark-32px.png)[View Source on GitHub](https://github.com/udaylunawat/Whats-this-rock) | ![alt noteboook](https://www.tensorflow.org/images/download_logo_32px.png)[Download Notebook](https://github.com/udaylunawat/Whats-this-rock/blob/main/notebooks/03_training.ipynb) |

## Features

& Things I’ve Experimented with

| `Feature` | | `Feature` | |
|-----------------|--------------------------------------------------------------------------------------------|----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Wandb` | \- Experiment Tracking
- System Tracking
- Model Tracking
- Hyperparameter Tuning | `Datasets` | \- [Dataset 1](https://www.kaggle.com/datasets/mahmoudalforawi/igneous-metamorphic-sedimentary-rocks-and-minerals)
- [Dataset 2](https://www.kaggle.com/datasets/salmaneunus/rock-classification) |
| `Augmentation` | \- Keras-CV
- MixUp
- CutMix
- Normal | `Models` | \- ConvNextTiny
- Efficientnet
- Resnet101
- MobileNetv1
- MobileNetv2
- Xception |
| `Optimisers` | \- Adam
- Adamax
- SGD
- RMSProp | `LR Scheduler` | \- [CosineDecay](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/CosineDecay)
- [ExponentialDecay](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/ExponentialDecay)
- [CosineDecayRestarts](https://www.tensorflow.org/api_docs/python/tf/keras/optimizers/schedules/CosineDecayRestarts) |
| `Remove Images` | \- Duplicate Images
- Corrupt Images
- Bad Images
- Misclassified | `Configuration Management` | \- hydra
- ml-collections
- argparse
-google-fire |
| `Generators` | \- tf.data.DataSet
- ImageDataGenerator | `Deployment` | \- Heroku
- Railway |
| `Evaluation` | \- Classification Report
- Confusion Matrix | `GitHub Actions` (CICD) | \- GitHub Super Linter
- Deploy to Telegram
- Deploy to Railway
- nbdev tests CI
- GitHub Pages(Documentation) |
| `Linting` | \- Flake8
- Pydocstyle | `Telegram Bot` | \- Greet
- Info
- Predict Image |
| `Formatting` | \- Black
- yapf | `Documentation` | \- Code Description
- Code comments
- Source link
- Doclinks |
| `Badges` | \- Build
- Issues
- Lint Codebase | `Docker` | |
| `Publishing` | \- PyPi | | |

## Planned Features

| Feature | | Feature | |
|----------------|------------------------------------------------------------------------------------------------------------------------------|------------|--------------|
| `Deploy` | \- HuggingFaces | `Backend` | \- FastAPI |
| `Coding Style` | \- Object Oriented | `Frontend` | \- Streamlit |
| `WandB` | \- Group Runs
- [WandB Tables](https://twitter.com/ayushthakur0/status/1508962184357113856?s=21&t=VRL-ZXzznXV_Hg2h7QnjuA) | `Badges` | \- Railway |

## Technologies Used

| | | |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [![Google Colab](https://img.shields.io/badge/Compute-Google%20Colab-F9AB00?logo=googlecolab&logoColor=fff&style=for-the-badge.png)](https://colab.research.google.com/drive/1N1CIqdOKlJSJla5PU53Yn9KWSao47eMv?usp=sharing "Google collaboratory") | [![python-telegram-bot](https://img.shields.io/badge/ChatBot-Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=black.png)](https://github.com/python-telegram-bot/python-telegram-bot "Telegram Bot") | [![Railway](https://img.shields.io/badge/Deployment-Railway-131415?style=for-the-badge&logo=railway&logoColor=black.png)](https://railway.app "Railway") |
| [![Jupyter Notebook](https://img.shields.io/badge/Coding-jupyter-%23FA0F00.svg?style=for-the-badge&logo=jupyter&logoColor=black)](https://jupyter.org "Jupyter") | [![Python](https://img.shields.io/badge/Language-python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54.png)](https://www.python.org/ "Python") | [![GitHub Actions](https://img.shields.io/badge/CI-github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=black)](https://github.com/features/actions "Github Actions") |
| [![Weights & Biases](https://img.shields.io/badge/MLOps-Weights%20%26%20Biases-FFBE00?logo=weightsandbiases&logoColor=000&style=for-the-badge.png)](http://wandb.ai "Weights & Biases") | [![TensorFlow](https://img.shields.io/badge/ML_Framework-TensorFlow-%23FF6F00.svg?style=for-the-badge&logo=TensorFlow&logoColor=black)](https://www.tensorflow.org/ "Tensorflow") | [![macOS](https://img.shields.io/badge/OS-mac%20os-000000?style=for-the-badge&logo=macos&logoColor=F0F0F0.png)](https://apple.com/macos "macOS") |
| [![Docker](https://img.shields.io/badge/Container-docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=black)](http://docker.com "Docker") | [![Git](https://img.shields.io/badge/Version_Control-git-%23F05033.svg?style=for-the-badge&logo=git&logoColor=black)](https://git-scm.com "Git") | [![Hydra](https://img.shields.io/badge/config-hydra1.1-89b8cd?style=for-the-badge&labelColor=gray)](http://hydra.cc "Hydra") |
| [![Black](https://img.shields.io/badge/code%20style-black-black.svg?style=for-the-badge&labelColor=gray)](http://github.com/psf/black "Black") | | |

## Directory Tree

├── imgs <- Images for skill banner, project banner and other images

├── configs <- Configuration files
│   ├── configs.yaml <- config for single run
│   └── sweeps.yaml <- confguration file for sweeps hyperparameter tuning

├── data
│ ├── corrupted_images <- corrupted images will be moved to this directory
│   ├── misclassified_images <- misclassified images will be moved to this directory
│   ├── bad_images <- Bad images will be moved to this directory
│   ├── duplicate_images <- Duplicate images will be moved to this directory
│   ├── sample_images <- Sample images for inference
│   ├── 0_raw <- The original, immutable data dump.
│   ├── 1_extracted <- Extracted data.
│   ├── 2_processed <- Intermediate data that has been transformed.
│   └── 3_tfds_dataset <- The final, canonical data sets for modeling.

├── notebooks <- Jupyter notebooks. Used to create the source code.

├── rocks_classifier <- Source code used in this project.
│ │
│   ├── data <- Scripts to download or generate data
│   │   ├── download.py
│   │   ├── preprocess.py
│   │   └── utils.py
│ │
│   ├── callbacks <- functions that are executed during training at given stages of the training procedure
│   │   └── callbacks.py
│ │
│   ├── models <- Scripts to train models and then use trained models to make
│ │ │ predictions
│   │   ├── evaluate.py
│   │   ├── models.py
│   │   ├── predict.py
│   │   ├── train.py
│   │   └── utils.py
│ │
│ └── visualization <- Scripts for visualizations

├── .dockerignore <- Docker ignore
├── .gitignore <- GitHub's excellent Python .gitignore customized for this project
├── LICENSE <- Your project's license.
├── README.md <- The top-level README for developers using this project.
├── CHANGELOG.md <- Release changes.
├── CODE_OF_CONDUCT.md <- Code of conduct.
├── CONTRIBUTING.md <- Contributing Guidelines.
├── settings.ini <- configuration.
├── README.md <- The top-level README for developers using this project.
├── requirements.txt <- The requirements file for reproducing the analysis environment, e.g.
│ generated with `pip freeze > requirements.txt`
└── setup.py <- makes project pip installable (pip install -e .) so src can be imported

# Learnings

- [“Better data is better than better
models!”](https://youtu.be/yrtAoBr3iuQ?t=306)

## Bug / Feature Request

If you find a bug (the site couldn’t handle the query and / or gave
undesired results), kindly open an issue
[here](https://github.com/udaylunawat/Whats-this-rock/issues) by
including your search query and the expected result.

If you’d like to request a new function, feel free to do so by opening
an issue [here](https://github.com/udaylunawat/Whats-this-rock/issues).
Please include sample queries and their corresponding results.

## Contributing

- Contributions make the open source community such an amazing place to
learn, inspire, and create.
- Any contributions you make are **greatly appreciated**.
- Check out our [contribution guidelines](../CONTRIBUTING.md) for more
information.

## License

Whats-this-rock! is licensed under the MIT License - see the
[LICENSE](LICENSE) file for details.

## Credits

- [Jeremy Howard & Lex Fridman
Podcast](https://www.youtube.com/watch?v=J6XcP4JOHmk&t=3883s&ab_channel=LexFridman)
- [Underfitted](https://youtu.be/yrtAoBr3iuQ?t=306) -
[Twitter](https://twitter.com/svpino)
- nbdev inspiration - [tmabraham](https://github.com/tmabraham/UPIT)
- [Dataset 1 - by Mahmoud
Alforawi](https://www.kaggle.com/datasets/mahmoudalforawi/igneous-metamorphic-sedimentary-rocks-and-minerals)
- [Dataset 2 - by
salmaneunus](https://www.kaggle.com/datasets/salmaneunus/rock-classification)

## Support

This project needs a ⭐️ from you. Don’t forget to leave a star ⭐️




Walt might be the one who knocks
but Hank is the one who rocks.