Retraining faster rcnn from object detection 2 api on a custom dataste
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 20/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python, tensorflow
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Bắt đầu với cấu hình pipeline Faster R-CNN được tham chiếu cùng các entry point model_builder và config_util. Kiểm tra cách checkpoint được khôi phục và classification head được thay thế, sau đó chạy phần khởi tạo bằng ảnh giả và thiết lập huấn luyện được minh họa để xác định các điểm không nhất quán trong các biến đã khôi phục, kích thước của head hoặc hành vi của loss.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 77.6k
- Fork
- 44.8k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tensorflow/models
-
Verify evals on Papers with CodeĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
tensorflow/models#13653 ·
-
object_detection_tutorial.ipynb pretrained model "resnet50 imagenet"Có thể làm lại được @laxmareddyp đã nhận 202 ngày trước và không có pull request nào đang mở. Đang mởtype:support
tensorflow/models#13634 · 2 bình luận · 1 reaction · 1 người được giao ·
-
Tag version compatible with Tensorflow 2.20Có thể làm lại được @bharatjetti đã nhận 276 ngày trước và không có pull request nào đang mở. Đang mởmodels:official type:bug
tensorflow/models#13607 · 1 bình luận · 1 người được giao ·
-
models:research type:feature
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 10/100
tensorflow/models#13600 ·
-
Installation Issues on Python 3.13Có thể làm lại được @bharatjetti đã nhận 245 ngày trước và không có pull request nào đang mở. Đang mởmodels:official type:bug
tensorflow/models#13587 · 9 bình luận · 1 người được giao ·
Tất cả issue của tensorflow/models
Issue tương tự
-
`destroy` sans terminal répond « Aborted. » au lieu de réclamer `--yes` comme `clean` et `reset`Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
stephrobert/dsoxlab#354 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
hardware help wanted testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
jasonacox/pypowerwall#472 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: DoubleMLRDDData accepts a score_col that is no data column (as in its docstring example); the running variable then becomes a covariate and RDFlex failsCó thể đã có người làm @vrjdev đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
DoubleML/doubleml-for-py#455 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Python mod.Box[T] annotation gets a false generic_arg edge that replaces the parameter_type one ('is' on tree-sitter nodes)Có thể đã có người làm @rohit-jsfreaky đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
Graphify-Labs/graphify#5110 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày