This repository contains the code for B2Q-Net: Bidirectional Branch Query Network for Surgical Phase Recognition.
We're thrilled to announce that B2Q-Net secured 2nd place in the prestigious 2025 APTOS Big Data Competition! 🎉
Check out the Competition Ranking to see our achievement! 🔝
Check out the solution to learn about our specific solution! 💡
The project was modified from BNpitfalls, thanks to their wonderful work!
- Python 3.9
- Cuda 11.6
- PyTorch 1.12.0
To install the required dependencies, simply run:
pip install -r requirements.txtDownload Cholec80, M2CAI16 and AutoLaparo datasets
- Access can be requested Cholec80, M2CAI16, AutoLaparo.
- Download the videos for each datasets and extract frames at 1fps. E.g. for
video01.mp4with ffmpeg, run:
mkdir /<PATH_TO_THIS_FOLDER>/data/frames_1fps/01/
ffmpeg -hide_banner -i /<PATH_TO_VIDEOS>/video01.mp4 -r 1 -start_number 0 /<PATH_TO_THIS_FOLDER>/data/frames_1fps/01/%08d.jpg- The final dataset structure should look like this:
B2Q-Net/
data/
frames_1fps/
01/
00000001.jpg
00000002.jpg
00000003.jpg
00000004.jpg
...
02/
...
...
80/
...
phase_annotations/
video01-phase.txt
video02-phase.txt
...
video80-phase.txt
tool_annotations/
video01-tool.txt
video02-tool.txt
...
video80-tool.txt
output/
train_scripts/
Download pretrained model (ConvNeXt V2-T)
- download ConvNeXt V2-T weights and place here:
train_scripts/convnext/convnextv2_tiny_1k_224_ema.pt
Training and Evaluation
- Train our B2Q-Net on the Cholec80 dataset as an example. This will create an experiment folder under ./output to store training configurations, logs, and checkpoints.
python3 train.py phase --split cuhk4040 --bn_off --backbone convnextv2 --workers 4 --freeze --seq_len 256 --lr 1e-4 --random_seed --trial_name TRIAL_NAME --cfg configs/config.yaml- Evaluate the trained model.
python3 save_predictions.py phase --split cuhk4040 --backbone convnextv2 --seq_len 256 --resume ../output/checkpoints/phase/[TRIAL_NAME]/models/checkpoint_best_acc.pth.tar --cfg configs/config.yamlWenjie Zhang (zwjie@mail.sdu.edu.cn)
