網頁

顯示具有 pytorch 標籤的文章。 顯示所有文章
顯示具有 pytorch 標籤的文章。 顯示所有文章

2024年9月26日 星期四

MMTracking 學習紀錄

參考 https://mmtracking.readthedocs.io/en/latest/index.html
參考 https://github.com/open-mmlab/mmtracking

$ git clone https://github.com/open-mmlab/mmtracking.git

$ docker run --gpus all -it --rm nvcr.io/nvidia/pytorch:21.05-py3
$ docker run --gpus all -it --name MMTracking nvcr.io/nvidia/pytorch:21.05-py3
$ docker start MMTracking
$ docker attach MMTracking
# <ctrl+p><ctrl+q>
$ docker attach MMTracking
$ docker stop MMTracking
$ docker rm MMTracking

$ echo $DISPLAY
$ export DISPLAY=:0
$ xhost +
$ docker run --gpus all -it --name MMTracking --shm-size=8G \
  --net=host -e DISPLAY=$DISPLAY -e XAUTHORITY=/tmp/xauth \
  -e QT_X11_NO_MITSHM=1 \
  -v /tmp/.X11-unix/:/tmp/.X11-unix \
  -v ~/.Xauthority:/tmp/xauth \
  -v /etc/localtime:/etc/localtime \
  -v /mnt/Data/MMTracking/mmtracking:/workspace/mmtracking \
  nvcr.io/nvidia/pytorch:21.05-py3

# pip install git+https://github.com/votchallenge/toolkit.git
# nvidia-smi
CUDA Version: 12.2
# pip list
opencv-python                    4.10.0.84
torch                            1.9.0a0+2ecb2c7

# pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu122/torch1.9.0/index.html
#### 出現下列錯誤
####    cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
####AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import)
#### 解決
# pip install opencv-python==4.5.1.48

# pip install mmdet==2.28.2
# pip install mmengine==0.10.4
# pip list
mmcv-full                        1.7.2
mmdet                            2.28.2
mmengine                         0.10.4
pillow                           10.4.0
# cd /workspace/mmtracking/
# pip install -r requirements/build.txt
# pip install -v -e .
# pip install git+https://github.com/JonathonLuiten/TrackEval.git
# pip install git+https://github.com/lvis-dataset/lvis-api.git
# pip install git+https://github.com/TAO-Dataset/tao.git

# python demo/demo_mot_vis.py configs/mot/deepsort/deepsort_faster-rcnn_fpn_4e_mot17-private-half.py \
  --input demo/demo.mp4 --output mot.mp4 --show
#### 出現下列錯誤
####    from .cv2 import *
####ImportError: libGL.so.1: cannot open shared object file: No such file or directory
#### 解決
# apt-get update
# apt-get install libgl1
#### 出現下列錯誤
####    NumpyArray = npt.NDArray[Any]
####AttributeError: module 'numpy.typing' has no attribute 'NDArray'
#### 解決
# pip install Pillow==9.5.0
#### 出現下列錯誤
#### Could not load the Qt platform plugin "xcb" in "/opt/conda/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
####This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
#### 查詢錯誤所在
# export QT_DEBUG_PLUGINS=1
####Cannot load library /opt/conda/lib/python3.8/site-packages/cv2/qt/plugins/platforms/libqxcb.so: (libSM.so.6: cannot open shared object file: No such file or directory)
#### 解決
# apt-get install -y libsm6 libxext6 libxrender-dev
# pip install opencv-contrib-python==4.5.1.48

# wget https://download.openmmlab.com/mmtracking/mot/ocsort/mot_dataset/ocsort_yolox_x_crowdhuman_mot17-private-half_20220813_101618-fe150582.pth
# python demo/demo_mot_vis.py configs/mot/ocsort/ocsort_yolox_x_crowdhuman_mot17-private-half.py \
  --checkpoint ocsort_yolox_x_crowdhuman_mot17-private-half_20220813_101618-fe150582.pth \
  --input demo/demo.mp4 --output mot.mp4 --show

# wget https://download.openmmlab.com/mmtracking/vid/selsa/selsa_faster_rcnn_r101_dc5_1x_imagenetvid/selsa_faster_rcnn_r101_dc5_1x_imagenetvid_20201218_172724-aa961bcc.pth
# python demo/demo_vid.py configs/vid/selsa/selsa_faster_rcnn_r101_dc5_1x_imagenetvid.py \
  --checkpoint selsa_faster_rcnn_r101_dc5_1x_imagenetvid_20201218_172724-aa961bcc.pth \
  --input demo/demo.mp4 --show

# python demo/demo_sot.py configs/sot/siamese_rpn/siamese_rpn_r50_20e_lasot.py \
  --input demo/demo.mp4 --output sot.mp4 --show
#### 用滑鼠框出要追蹤的物件,按空白鍵

MMOCR 學習紀錄

參考 https://mmocr.readthedocs.io/en/dev-1.x/
參考 https://github.com/open-mmlab/mmocr

$ docker run --gpus all -it --rm nvcr.io/nvidia/pytorch:21.05-py3
$ docker run --gpus all -it --name MMOCR nvcr.io/nvidia/pytorch:21.05-py3
$ docker start MMOCR
$ docker attach MMOCR
# <ctrl+p><ctrl+q>
$ docker attach MMOCR
$ docker stop MMOCR
$ docker rm MMOCR
$ docker run --gpus all -it --name MMOCR --shm-size=8G \
  -v /mnt/Data/MMOCR/mmocr:/workspace/mmocr \
  -v /mnt/QNAP_A/ImageData/ICDAR:/mmocr/data \
  nvcr.io/nvidia/pytorch:21.05-py3

# pip install -U openmim
#### 出現下列錯誤
####ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
####We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
#### 不用擔心

確認 https://mmocr.readthedocs.io/en/dev-1.x/get_started/install.html 底部的版本資訊
安裝正確版本套件
# mim list
# mim install mmengine==
# mim install mmengine
# mim install mmcv==2.0.1
#### 出現下列錯誤
####    cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
####AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import)
#### 解決
#### 因為目前 opencv-python 版本為 4.10.0.84, 降版本
# pip install opencv-python==4.5.1.48
# mim install mmcv==2.0.1
# mim install mmdet==3.1.0
# cd /workspace/mmocr/
# pip install -v -e .
# pip install opencv-python-headless==4.5.1.48
# pip install -r requirements/albu.txt
# pip install -r requirements.txt
# python tools/infer.py demo/images --det DBNet --rec CRNN --print-result \
  --save_pred --save_vis --out-dir='results/' --batch-size=2

2024年8月28日 星期三

SwinTransformer 學習紀錄

參考 https://github.com/microsoft/Swin-Transformer?tab=readme-ov-file
參考 https://github.com/SwinTransformer/Swin-Transformer-Object-Detection
參考 https://mmdetection.readthedocs.io/en/latest/get_started.html
參考 https://github.com/open-mmlab/mmdetection/blob/master/docs/en/get_started.md
參考 https://github.com/open-mmlab/mmcv
參考 https://github.com/open-mmlab/mim?tab=readme-ov-file

Swin-Transformer 是原始版本,主要針對圖片分類
Swin-Transformer-Object-Detection 主要針對物件偵測(基於 mmdetection)
mmdetection 主要針對物件偵測,其中不只是 Swin-Transformer, 包含各式各樣先進的演算法
mmdetection 可在 mmdet/__init__.py 可以查詢到 mmcv 所需要的版本
Swin-Transformer-Object-Detection 要求使用 mmcv(1.4.0)
但 mmdetection 最後對應到 mmcv(1.4.0) 的版本為(v2.18.1)
所以以下放棄使用 Swin-Transformer-Object-Detection, 直接使用 mmdetection 的最新版本

$ docker run --gpus all -it --rm nvcr.io/nvidia/pytorch:21.05-py3
$ docker run --gpus all -it --name SwinTransformer nvcr.io/nvidia/pytorch:21.05-py3
$ docker start SwinTransformer
$ docker attach SwinTransformer
# <ctrl+p><ctrl+q>
$ docker attach SwinTransformer
$ docker stop SwinTransformer
$ docker rm SwinTransformer
$ git clone https://github.com/microsoft/Swin-Transformer.git
$ git clone https://github.com/SwinTransformer/Swin-Transformer-Object-Detection.git
$ git clone https://github.com/open-mmlab/mmdetection.git
$ docker run --gpus all -it --name SwinTransformer --shm-size=8G \
  -v /mnt/Data/SwinTransformer/Swin-Transformer:/workspace/Swin-Transformer \
  -v /mnt/Data/SwinTransformer/mmdetection:/workspace/mmdetection \
  -v /mnt/Data/SwinTransformer/Swin-Transformer-Object-Detection:/workspace/Swin-Transformer-Object-Detection \
  -v /mnt/QNAP_A/ImageData/ImageNet:/workspace/ImageNet \
  nvcr.io/nvidia/pytorch:21.05-py3

# pip install timm==0.4.12
# pip install opencv-python==4.4.0.46 termcolor==1.1.0 yacs==0.1.8 pyyaml scipy

# cd /workspace/Swin-Transformer/kernels/window_process/
# python setup.py install

# cd /workspace/Swin-Transformer/
# wget https://github.com/SwinTransformer/storage/releases/download/v1.0.0/swin_tiny_patch4_window7_224.pth
# python -m torch.distributed.launch --nproc_per_node 1 --master_port 12345 main.py \
  --eval --cfg configs/swin/swin_tiny_patch4_window7_224.yaml \
  --resume swin_tiny_patch4_window7_224.pth --data-path /workspace/ImageNet \
  --batch_size=64
#### 出現下列錯誤
####  File "/opt/conda/lib/python3.8/site-packages/PIL/_typing.py", line 10, in <module>
####    NumpyArray = npt.NDArray[Any]
####AttributeError: module 'numpy.typing' has no attribute 'NDArray'
#### 解決
# pip install Pillow==9.5.0
#### 出現下列錯誤
####RuntimeError: Found 0 files in subfolders of: /workspace/ImageNet/val
####Supported extensions are: .jpg,.jpeg,.png,.ppm,.bmp,.pgm,.tif,.tiff,.webp
#### 解決
$ cd /mnt/QNAP_A/ImageData/ImageNet/
$ mv val val_a ;mkdir val; mv val_a val
#### 出現下列錯誤
ERROR: Unexpected bus error encountered in worker. This might be caused by insufficient shared memory (shm).
#### 解決 docker run 時須加上 --shm-size=8G

# cd /workspace/mmdetection
# pip install -U openmim
#### 出現下列錯誤
####ERROR: After October 2020 you may experience errors when installing or updating packages. This is because pip will change the way that it resolves dependency conflicts.
####We recommend you use --use-feature=2020-resolver to test your packages with the new resolver before it becomes the default.
#### 不用擔心

# mim list
# mim install mmengine
# mim install "mmcv>=2.0.0"
# pip install -v -e .
    # "-v" means verbose, or more output
    # "-e" means installing a project in editable mode,
    # thus any local modifications made to the code will take effect without reinstallation.
# mim download mmdet --config yolov3_mobilenetv2_8xb24-320-300e_coco --dest .
# mim list
# ls
# python demo/image_demo.py demo/demo.jpg yolov3_mobilenetv2_8xb24-320-300e_coco.py \
  --weights yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth
#### 出現下列錯誤
####    import cv2
####  File "/opt/conda/lib/python3.8/site-packages/cv2/__init__.py", line 5, in <module>
####    from .cv2 import *
####ImportError: libGL.so.1: cannot open shared object file: No such file or directory
#### 出現下列錯誤
####    cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
####AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import)
#### 解決
# pip install opencv-python-headless==4.4.0.46
#### 出現下列錯誤
####    assert (mmcv_version >= digit_version(mmcv_minimum_version)
####AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.
#### 解決
# mim install "mmcv==2.0.0rc4"

# mim download mmdet --config mask-rcnn_swin-t-p4-w7_fpn_1x_coco --dest .
# python demo/image_demo.py demo/demo.jpg mask-rcnn_swin-t-p4-w7_fpn_1x_coco.py \
  --weights mask_rcnn_swin-t-p4-w7_fpn_1x_coco_20210902_120937-9d6b7cfa.pth

2023年7月12日 星期三

install pytorch in ubuntu


$ python3 -m venv pytorch
$ source pytorch/bin/activate
$ pip3 install --upgrade --no-cache-dir pip
$ sudo update-alternatives --config cuda
$ pip3 install torch==1.10.2+cu113 torchvision==0.11.3+cu113 torchaudio==0.10.2+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html