Retraining faster rcnn from object detection 2 api on a custom dataste
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 20/100
- issue の種類
- バグ
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 技術スタック
- python, tensorflow
調査の方向性
参照されている Faster R-CNN パイプラインの設定と、model_builder および config_util のエントリーポイントから始めます。checkpoint がどのように復元され、classification head がどのように置き換えられるかを確認し、その後、示されているダミー画像による初期化と学習設定を実行して、復元された変数、head の次元、または loss の挙動に不整合がないかを特定します。
索引モデルが issue の本文から書いたものです。
説明
Dear all,
I am trying to retrain the classification head of faster rcnn while keeping other branches, I defined this code:
import tensorflow as tf
from object_detection.builders import model_builder
from object_detection.utils import config_util
Clear the current TensorFlow session
tf.keras.backend.clear_session()
print('Building model and restoring weights for fine-tuning...', flush=True)
Settings
num_classes = 2
pipeline_config = '/MyPath/models/research/object_detection/configs/tf2/faster_rcnn_resnet50_v1_640x640_coco17_tpu-8.config'
checkpoint_path = 'MyPath/models/research/object_detection/test_data2/checkpoint/faster_rcnn_resnet50_v1_640x640_coco17_tpu-8/checkpoint/ckpt-0'
Load pipeline config and build a detection model
configs = config_util.get_configs_from_pipeline_file(pipeline_config)
model_config = configs['model']
Update the model config to reflect the number of classes
model_config.faster_rcnn.num_classes = num_classes
model_config.faster_rcnn.feature_extractor.batch_norm_trainable = False
Build the detection model
detection_model = model_builder.build(model_config=model_config, is_training=False)
Restore the model weights from the checkpoint, excluding the classification and mask heads
ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
ckpt.restore(checkpoint_path).expect_partial()
Reinitialize the class prediction head to match the new number of classes
class_prediction_head = detection_model._mask_rcnn_box_predictor._class_prediction_head
Access the Dense layer responsible for class prediction
dense_layer = class_prediction_head._class_predictor_layers[1]
num_units = num_classes + 1 # Add 1 for the background class
Create a new Dense layer with the correct number of classes
new_dense_layer = tf.keras.layers.Dense(
units=num_units,
activation=dense_layer.activation,
use_bias=dense_layer.use_bias,
kernel_initializer=tf.keras.initializers.RandomNormal(stddev=0.01), # Initialize new layer weights randomly
bias_initializer=dense_layer.bias_initializer,
kernel_regularizer=dense_layer.kernel_regularizer,
bias_regularizer=dense_layer.bias_regularizer,
activity_regularizer=dense_layer.activity_regularizer,
kernel_constraint=dense_layer.kernel_constraint,
bias_constraint=dense_layer.bias_constraint,
name=dense_layer.name # Keep the same name
)
Replace the old Dense layer with the new one in the class prediction head
class_prediction_head._class_predictor_layers[1] = new_dense_layer
Run the model through a dummy image to ensure all variables are properly initialized
image, shapes = detection_model.preprocess(tf.zeros([1, 640, 640, 3]))
prediction_dict = detection_model.predict(image, shapes)
_ = detection_model.postprocess(prediction_dict, shapes)
print('Weights restored for box predictor! Classification head initialized with the new number of classes.')
When establishing the training, my loss is around the 1. I choose the following optimizer:
learning_rate = 0.000001
optimizer = tf.keras.optimizers.SGD(learning_rate=learning_rate, momentum=0.9)
Is the restoration of checkpoint correct? Can Any help to detect any inconsistencies in the definition of model.
Thank you
- 主要言語
- Python
- スター
- 77.6k
- フォーク
- 44.8k
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tensorflow/models のほかの issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
tensorflow/models#13653 ·
-
object_detection_tutorial.ipynb pretrained model "resnet50 imagenet"再び着手できるかも @laxmareddyp が 202 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンtype:support
tensorflow/models#13634 · コメント 2 件 · リアクション 1 件 · 担当者 1 名 ·
-
Tag version compatible with Tensorflow 2.20再び着手できるかも @bharatjetti が 276 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンmodels:official type:bug
tensorflow/models#13607 · コメント 1 件 · 担当者 1 名 ·
-
models:research type:feature
難易度 5/5 1週間以上 初心者へのやさしさ 10/100
tensorflow/models#13600 ·
-
Installation Issues on Python 3.13再び着手できるかも @bharatjetti が 246 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンmodels:official type:bug
tensorflow/models#13587 · コメント 9 件 · 担当者 1 名 ·
tensorflow/models の issue をすべて見る
似ている issue
-
cli good first issue help wanted python up-for-grabs
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
andrewsiah/agentswarm-data-tasks#36 ·
メンテナーはふだん 1 日以内に返信
-
bug drawing-tools
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
cofade/open-garden-planner#827 ·
メンテナーはふだん 1 日以内に返信
-
Methodology pageオープンdocumentation site texts
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
Krasnopjorovs/temet#66 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信