Giter Site home page Giter Site logo

og31330 / custom-movinet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from naseemap47/custom-movinet

0.0 0.0 0.0 36 KB

Create your own custom MoViNet model using your custom data. You can train and inference from "a single of code".

License: MIT License

Python 97.56% Dockerfile 2.44%

custom-movinet's Introduction

Custom-MoViNet

Create your own custom MoViNet model using your custom data. You can train and inference from "a single of code"๐Ÿฅณ.
Currently only added MoViNet Stream A1, moving forward we will add all other types of MoViNet models.

Available MoViNet Models:

  • MoViNet Base A0
  • MoViNet Base A1
  • MoViNet Base A2
  • MoViNet Base A3
  • MoViNet Base A4
  • MoViNet Base A5
  • MoViNet Base A6
  • MoViNet Stream A0
  • MoViNet Stream A1
  • MoViNet Stream A2
  • MoViNet Stream A3
  • MoViNet Stream A4
  • MoViNet Stream A5

Table of Contents:

  • About MoViNet
  • Prepare Dataset
  • Train MoViNet Model
  • Inference MoViNet Model

๐Ÿ“– About MoViNet

The MoViNet model family has been published in March 2021 by Google research. It tries to solve the recurring problem with video classification models, which is how resource hungry the models are. Figure below shows how MoViNet compares in resource usage to other SOTA video classification models such as X3D.

ezgif-2-166afa34a2

๐ŸŽ’ Prepare Dataset

Your custom dataset should be in Kinetics data format.
Kinetics Data Format:

โ”œโ”€โ”€ Dataset
โ”‚   โ”œโ”€โ”€ Classname1
โ”‚   โ”‚   โ”œโ”€โ”€ 1.mp4
โ”‚   โ”‚   โ”œโ”€โ”€ abc.avi
โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ Classname2
โ”‚   โ”‚   โ”œโ”€โ”€ example.mp4
โ”‚   โ”‚   โ”œโ”€โ”€ 2.avi
โ”‚   โ”‚   โ”œโ”€โ”€ ...
.   .
.   .

But to train MoViNet Model need a slightly different dataset format.But its need all videos in AVI format
MoViNet Training Data Format:

โ”œโ”€โ”€ Dataset
โ”‚   โ”œโ”€โ”€ train
โ”‚   โ”‚   โ”œโ”€โ”€ classname1
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ 1.avi
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ abc.avi
โ”‚   โ”‚   โ”œโ”€โ”€ classname2
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ example.avi
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ 2.avi
โ”‚   โ”‚   โ”œโ”€โ”€ ...
โ”‚   โ”œโ”€โ”€ test
โ”‚   โ”‚   โ”œโ”€โ”€ classname1
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ 1.avi
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ abc.avi
โ”‚   โ”‚   โ”œโ”€โ”€ classname2
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ example.avi
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ 2.avi
โ”‚   โ”‚   โ”œโ”€โ”€ ...
.   .
.   .

๐Ÿ’ผ Convert Dataset into MoViNet Training Data Format

But you don't worry you can convert your dataset into this format by runing single of code ๐Ÿฅณ. If data is not in AVI format, it will convert MP4 into AVI format ๐Ÿ˜Ž.

Args

-i, --data_dir: path to data dir
-o, --save: path to save dir
-r, --ratio: test ratio 0<ratio<1

Example

python3 data_split.py --data_dir data/ --save train_data_dir --ratio 0.2

๐Ÿค– Train

Args

-i, --data: path to data dir
-b, --batch_size: Training batch size
-n, --num_frames: Number of frame need to take to train the model from each video.
-s, --resolution: Video resolution to train the model.
-e, --num_epochs: number of training epochs.
--pre_ckpt: path to pre-trained checkpoint dir.
--save_ckpt: path to save trained checkpoint eg: checkpoints/ckpt-1.
--export: path to export model.
-id, --model_id: model type, eg: a2
-o, --save: path to export tflite model.
-f, --float: model quantization, choices: 32 & 16

Example:

python3 train.py --data train_data_dir --batch_size 8 --num_frames 32 --resolution 172 --num_epochs 100 \
                 --pre_ckpt movinet_a1_stream/ --save_ckpt checkpoints/ckpt-1 --export my_model/custom_model1 \
                 --model_id a1 --save my_model.tflite --float 16

โš  Error while Training!!!

When training, on the time of loading data.
If we getting this ERROR:
" ValueError: Attempt to convert a value (None) with an unsupported type (<class 'NoneType'>) to a Tensor "

This is due to Frames missing from some of the video data.
For that you need to clean your data. Don't worry from a single line of code will help you to do that ๐Ÿฅณ.

Args

-i, --data_dir: path to data dir
-o, --save: path to save dir

Example

python3 clean_data.py --data_dir data/ --save good_data

After cleaning again run the code for training with data directory path to cleaned data.

๐Ÿ“บ Inference

Args

--tflite: path to tflite model
-i, --source: path to video or cam-id or RTSP link
-s, --resolution: Video resolution to train the model.
-n, --num_frames: Number of frame need to take to train the model from each video.

-d, --data: path to data/test or data/train dir
--save: to save inferenced video, it save as ouput.mp4

Example

python3 inference.py --tflite my_model.tflite --source 'videos/sample.mp4' --num_frames 32 \
                     --data data/test --save

custom-movinet's People

Contributors

naseemap47 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.