All Projects → Kazuhito00 → Tensorflow2-ObjectDetectionAPI-Colab-Hands-On

Kazuhito00 / Tensorflow2-ObjectDetectionAPI-Colab-Hands-On

Licence: MIT license
Tensorflow2 Object Detection APIのハンズオン用資料です(Hands-on documentation for the Tensorflow2 Object Detection API)

Programming Languages

Jupyter Notebook
11667 projects

Projects that are alternatives of or similar to Tensorflow2-ObjectDetectionAPI-Colab-Hands-On

TFLite-ModelMaker-EfficientDet-Colab-Hands-On
TensorFlow Lite Model Makerで物体検出を行うハンズオン用資料です(Hands-on for object detection with TensorFlow Lite Model Maker)
Stars: ✭ 15 (-54.55%)
Mutual labels:  handson, colab, colaboratory, colab-notebook, tensorflow2
steam-stylegan2
Train a StyleGAN2 model on Colaboratory to generate Steam banners.
Stars: ✭ 30 (-9.09%)
Mutual labels:  colab, colaboratory, colab-notebook
Torrent-To-Google-Drive-Downloader
Simple notebook to stream torrent files to Google Drive using Google Colab and python3.
Stars: ✭ 256 (+675.76%)
Mutual labels:  colab, colaboratory, colab-notebook
keras-buoy
Keras wrapper that autosaves what ModelCheckpoint cannot.
Stars: ✭ 22 (-33.33%)
Mutual labels:  colab, colaboratory, colab-notebook
QuantumSpeech-QCNN
IEEE ICASSP 21 - Quantum Convolution Neural Networks for Speech Processing and Automatic Speech Recognition
Stars: ✭ 71 (+115.15%)
Mutual labels:  colab-notebook, tensorflow2
NARUTO-HandSignDetection
物体検出を用いてNARUTOの印(子~亥、壬、合掌)を検出するモデルとサンプルプログラムです。このリポジトリでは、YOLOXを使用しています(This is a model and sample program that detects NARUTO's hand sign using object detection. This repository use YOLOX.)
Stars: ✭ 186 (+463.64%)
Mutual labels:  tensorflow2, efficientdet
Google-Colab-Tutorial
Google Colab Tutorial
Stars: ✭ 61 (+84.85%)
Mutual labels:  colab, colab-tutorial
video coloriser
Pytorch Convolutional Neural Net and GAN based video coloriser that converts black and white video to colorised video.
Stars: ✭ 29 (-12.12%)
Mutual labels:  colab, colab-notebook
ALPS 2021
XAI Tutorial for the Explainable AI track in the ALPS winter school 2021
Stars: ✭ 55 (+66.67%)
Mutual labels:  colab, colab-notebook
MineColab
Run Minecraft Server on Google Colab.
Stars: ✭ 135 (+309.09%)
Mutual labels:  colab, colab-notebook
Adaptive-Gradient-Clipping
Minimal implementation of adaptive gradient clipping (https://arxiv.org/abs/2102.06171) in TensorFlow 2.
Stars: ✭ 74 (+124.24%)
Mutual labels:  colab-notebook, tensorflow2
MiXLab
MiXLab is a mix of multiple amazing Colab Notebooks found on the internet such as rcloneLab, RLabClone, Torrent to Google Drive Downloader and some more.
Stars: ✭ 143 (+333.33%)
Mutual labels:  colab
Computational-Intelligence-Tutorials
This is the repository of codes written in class.
Stars: ✭ 36 (+9.09%)
Mutual labels:  hands-on
picatrix
Picatrix is a library designed to help security analysts in a notebook environment, such as colab or jupyter.
Stars: ✭ 35 (+6.06%)
Mutual labels:  colab
UnitBox
UnitBox: An Advanced Object Detection Network
Stars: ✭ 23 (-30.3%)
Mutual labels:  tensorflow2
datascienv
datascienv is package that helps you to setup your environment in single line of code with all dependency and it is also include pyforest that provide single line of import all required ml libraries
Stars: ✭ 53 (+60.61%)
Mutual labels:  tensorflow2
pollinations
Generate Art
Stars: ✭ 100 (+203.03%)
Mutual labels:  colaboratory
face-mask-detection-tf2
A face mask detection using ssd with simplified Mobilenet and RFB or Pelee in Tensorflow 2.1. Training on your own dataset. Can be converted to kmodel and run on the edge device of k210
Stars: ✭ 72 (+118.18%)
Mutual labels:  tensorflow2
AnimeGANv2-ONNX-Sample
「PyTorch Implementation of AnimeGANv2」のPythonでのONNX推論サンプル
Stars: ✭ 54 (+63.64%)
Mutual labels:  colaboratory
muzero
A clean implementation of MuZero and AlphaZero following the AlphaZero General framework. Train and Pit both algorithms against each other, and investigate reliability of learned MuZero MDP models.
Stars: ✭ 126 (+281.82%)
Mutual labels:  tensorflow2

[Japanese/English]

Tensorflow2-ObjectDetectionAPI-Colab-Hands-On

mkv4t-6ilnu

Tensorflow2 Object Detection APIのハンズオン用資料です。
VoTTでのアノテーションをローカルPCで実施し、学習~推論はColaboratory上で実施します。

以下の内容を含みます。

  • 学習用データセット ※アノテーション未実施
  • テスト用データセット
  • ファインチューニング用モデル(EffientDet D0)
  • Colaboratory用スクリプト(環境設定、モデル訓練、推論結果確認)
ディレクトリ構成
│ [Colaboratory]Tensorflow2_ObjectDetectionAPI_Colab_Hands_On.ipynb
|
├─01_train_data─┬─000000.jpg
│               │     :
│               └─000049.jpg
│      
├─02_tfrecord
│      
├─03_pretrained_model─efficientdet_d0_coco17_tpu-32─┬─pipeline.config
│                                                   ├─checkpoint──┬─checkpoint
│                                                   │             ├─ckpt-0.data-00000-of-00001
│                                                   │             └─ckpt-0.index
│                                                   └─saved_model─┬─saved_model.pb
│                                                                 └─variables─┬─variables.data-00000-of-00001
│                                                                             └─variables.index
│
└─04_test_data─┬─000050.jpg
               │     :
               └─000099.jpg

[Colaboratory]Tensorflow2_ObjectDetectionAPI_Colab_Hands_On.ipynb

Colaboratory用スクリプト(環境設定、モデル訓練、推論結果確認)

01_train_data

学習用データセット ※アノテーション未実施

02_tfrecord

アノテーション実施済みTFRecord格納先

03_pretrained_mode

ファインチューニング用モデル(EffientDet D0)

04_test_data

テスト用データセット

Requirement

Tensorflow 2.3.0

Overview

2時間程度のボリュームの想定です。

  1. VoTT:アノテーション(約30~60分)
  2. Colaboratory:Object Detection API設定
  3. パイプラインコンフィグ修正
  4. Colaboratory:モデル訓練(約25分)
  5. Colaboratory:推論

Preparations

事前準備として以下が必要です。

  • このリポジトリのローカル環境へのクローン
  • VoTTのインストール
  • Googleアカウント(Google Colaboratory、Googleドライブで使用)

1. VoTT:アノテーション

VoTTを使用してアノテーションを行い、TFRecord形式で出力します。

VoTTのプロジェクト設定

「新規プロジェクト」を選択する

2020-09-19 (3)

プロジェクト設定を行う

表示名:Tensorflow2-ObjectDetectionAPI-Colab-Hands-On
セキュリティトークン:Generate New Security Token
ソース接続:「Add Connection」を押下
2020-09-19 (4)

ソース接続の接続設定を行う

表示名:Tensorflow2-ObjectDetectionAPI-Colab-Hands-On-TrainData 2020-09-19 (6) プロバイダー:ローカルファイルシステム 2020-09-19 (7) フォルダーパス:クローンしたリポジトリの「01_train_data」ディレクトリを指定 2020-09-19 (8)

ターゲット接続の接続設定を行う

ターゲット接続:Add Connection 2020-09-19 (9) 表示名:Tensorflow2-ObjectDetectionAPI-Colab-Hands-On-TFRecord
プロバイダー:ローカルファイルシステム
フォルダーパス:クローンしたリポジトリの「02_tfrecord」ディレクトリを指定
2020-09-19 (10)

タグを追加し設定を保存する

タグ:「Fish」を追加
「プロジェクトを保存」を押下 94047577-3d9dc080-fe0d-11ea-9f4f-b5fe7727fc12

VoTTを使用してアノテーションを実施

マウス左ドラッグで魚を選択する

2020-09-19 (13)

TAGSから「Fish」を選択する

南京錠のマークを選択しておくことでタグを使用するタグを固定することが可能 2020-09-19 (14)

TFRecordエクスポート

エクスポート設定

プロバイダー:Tensorflow レコード
アセットの状態:タグ付きアセットのみ
「エクスポート設定を保存」を押下する 2020-09-19 (16) アノテーション画面からエクスポートマークを押下し、TFRecordをエクスポートする。 2020-09-19 (14)

注意事項(詳細確認中)

画像の端の対象をアノテーションする際に、以下のように端から少し隙間を設けてください。 2020-09-19 (17)
問題の詳細は確認中ですが、隙間を開けずにアノテーションをすると、
VoTTの問題かTensorflowの問題か、モデル学習時に以下のエラーが発生します。

W0921 13:29:32.965700 140050120722176 optimizer_v2.py:1275] Gradients do not exist for variables ['top_bn/gamma:0', 'top_bn/beta:0'] when minimizing the loss.
Traceback (most recent call last):
  File "object_detection/model_main_tf2.py", line 113, in 
    tf.compat.v1.app.run()
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/platform/app.py", line 40, in run
    _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/usr/local/lib/python3.6/dist-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "object_detection/model_main_tf2.py", line 110, in main
    record_summaries=FLAGS.record_summaries)
  File "/usr/local/lib/python3.6/dist-packages/object_detection/model_lib_v2.py", line 639, in train_loop
    loss = _dist_train_step(train_input_iter)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py", line 780, in __call__
    result = self._call(*args, **kwds)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/def_function.py", line 807, in _call
    return self._stateless_fn(*args, **kwds)  # pylint: disable=not-callable
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 2829, in __call__
    return graph_function._filtered_call(args, kwargs)  # pylint: disable=protected-access
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 1848, in _filtered_call
    cancellation_manager=cancellation_manager)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 1924, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager))
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/function.py", line 550, in call
    ctx=ctx)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/eager/execute.py", line 60, in quick_execute
    inputs, attrs, num_outputs)
tensorflow.python.framework.errors_impl.InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument:  assertion failed: [[0.15956609][0.103383526][0.109880842]...] [[0.23180081][0.133959055][0.132812485]...]
	 [[{{node Assert_1/AssertGuard/else/_35/Assert_1/AssertGuard/Assert}}]]
	 [[MultiDeviceIteratorGetNextFromShard]]
	 [[RemoteCall]]
	 [[IteratorGetNext]]
	 [[Loss/localization_loss_1/write_summary/summary_cond/pivot_t/_4/_111]]
  (1) Invalid argument:  assertion failed: [[0.15956609][0.103383526][0.109880842]...] [[0.23180081][0.133959055][0.132812485]...]
	 [[{{node Assert_1/AssertGuard/else/_35/Assert_1/AssertGuard/Assert}}]]
	 [[MultiDeviceIteratorGetNextFromShard]]
	 [[RemoteCall]]
	 [[IteratorGetNext]]

2. Colaboratory:Object Detection API設定

Open In Colab
以降の作業はGoogle Colaboratory上で実施します。※パイプラインコンフィグ修正をのぞく
[Open In Colab]リンクからノートブックを開き、以下の順に実行してください。

  • Google Driveマウント
  • Tensorflow Object Detection API設定
  • Tensorflow2-ObjectDetectionAPI-Colab-Hands-Onリポジトリクローン

3.TFRecordアップロード

「Tensorflow2-ObjectDetectionAPI-Colab-Hands-On/02_tfrecord」に
VoTTからエクスポートしたTFRecordとtf_label_map.pbtxtを格納してください。
格納後、以下を実行してください。

  • 学習データ/検証データ 分割

4. パイプラインコンフィグ修正

「03_pretrained_model\efficientdet_d0_coco17_tpu-32\pipeline.config」のパイプラインコンフィグを以下のように修正して、
Colaboratory上の「Tensorflow2-ObjectDetectionAPI-Colab-Hands-On/03_pretrained_model」にアップロードしてください。

パイプラインコンフィグ修正箇所
  • 3行目(Line 3):クラス数(num_classes)
    変更前(Before) : 90
    変更後(After) : 1
  • 134行目(Line 134):バッチサイズ(batch_size)
    変更前(Before) : 128
    変更後(After) : 16
  • 161行目(Line 161):ファインチューニング用のチェックポイント格納先(fine_tune_checkpoint)
    変更前(Before) : "PATH_TO_BE_CONFIGURED"
    変更後(After) : "/content/models/research/Tensorflow2-ObjectDetectionAPI-Colab-Hands-On/03_pretrained_model/efficientdet_d0_coco17_tpu-32/checkpoint/ckpt-0"
  • 167行目(Line 167):ファインチューニング方法(fine_tune_checkpoint_type)
    変更前(Before) : "classification"
    変更後(After) : "detection"
  • 168行目(Line 168):Googleカスタム 16ビットbrain浮動小数点の使用有無(use_bfloat16)
    変更前(Before) : true
    変更後(After) : false
  • 172行目(Line 172):ラベルマップファイルの格納先(label_map_path)
    変更前(Before) : "PATH_TO_BE_CONFIGURED/label_map.txt"
    変更後(After) : "/content/models/research/Tensorflow2-ObjectDetectionAPI-Colab-Hands-On/02_tfrecord/tf_label_map.pbtxt"
  • 174行目(Line 174):学習データの格納先(input_path)
    変更前(Before) : "PATH_TO_BE_CONFIGURED/train2017-?????-of-00256.tfrecord"
    変更後(After) : "/content/models/research/train_data/??????.tfrecord"
  • 185行目(Line 185):ラベルマップファイルの格納先(label_map_path)
    変更前(Before) : "PATH_TO_BE_CONFIGURED/label_map.txt"
    変更後(After) : "/content/models/research/Tensorflow2-ObjectDetectionAPI-Colab-Hands-On/02_tfrecord/tf_label_map.pbtxt"
  • 189行目(Line 189):バリデーションデータの格納先(input_path)
    変更前(Before) : "PATH_TO_BE_CONFIGURED/val2017-?????-of-00032.tfrecord"
    変更後(After) : "/content/models/research/val_data/??????.tfrecord"
パイプラインコンフィグ修正箇所 ※余裕のある方向け

パイプラインコンフィグにはデータ拡張設定も記載されています。
初期のパイプラインコンフィグには、以下の水平反転、ランダムスケールクロップのみのデータ拡張が設定されています。

  data_augmentation_options {
    random_horizontal_flip {
    }
  }
  data_augmentation_options {
    random_scale_crop_and_pad_to_square {
      output_size: 512
      scale_min: 0.10000000149011612
      scale_max: 2.0
    }
  }

使用可能なデータ拡張手法は、preprocessor.protopreprocessor.pyに記載されているため、
必要に応じて追加してみてください。

5. Colaboratory:モデル訓練

以下の順に実行してください。

  • Googleドライブに保存先ディレクトリを作成
  • TensorBoard
  • 学習
  • saved model形式へエクスポート

6. Colaboratory:推論

以下の順に実行してください。

  • モデルロード
  • 推論
  • 推論結果確認

ToDo

Author

高橋かずひと(https://twitter.com/KzhtTkhs)

License

Tensorflow2-ObjectDetectionAPI-Colab-Hands-On is under MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].