Autodl复现Swin-Transformer

Swin_T是VMamba、MLLA模型的Baseline,在CV中是经典模型,它在目标检测任务(Object Detection)上有一个专属的名字(MMdetection),也有专属的库(mmdet)。Git网址如下:

GitHub - SwinTransformer/Swin-Transformer-Object-Detection: This is an official implementation for "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows" on Object Detection and Instance Segmentation.This is an official implementation for "Swin Transformer: Hierarchical Vision Transformer using Shifted Windows" on Object Detection and Instance Segmentation. - SwinTransformer/Swin-Transformer-Object-Detectionicon-default.png?t=O83Ahttps://github.com/SwinTransformer/Swin-Transformer-Object-Detection.git本文主要使用Swin的与训练好的模型,实现COCO数据集的验证

基本环境

镜像选择

coco数据下载

使用autodl的云端(足够快,推荐

sudo apt-get install unzip  
mkdir -p /root/autodl-tmp/coco/
unzip /root/autodl-pub/COCO2017/annotations_trainval2017.zip -d /root/autodl-tmp/coco/
unzip /root/autodl-pub/COCO2017/val2017.zip -d /root/autodl-tmp/coco/
unzip /root/autodl-pub/COCO2017/train2017.zip -d /root/autodl-tmp/coco/
unzip /root/autodl-pub/COCO2017/test2017.zip -d /root/autodl-tmp/coco/

环境设置 

pip install mmcv-full==1.3.9 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
pip install -U openmim
mim install mmengine
​​​​​​​pip install timm
​​​​​​​pip install Cython==0.29.33
pip install apex





 

克隆Swin-T

cd
git clone https://github.com/SwinTransformer/Swin-Transformer-Object-Detection.git
cd Swin-Transformer-Object-Detection
pip install -e.
pip install yapf==0.31

下载预训练数据

cd
wget https://github.com/SwinTransformer/storage/releases/download/v1.0.3/mask_rcnn_swin_tiny_patch4_window7_1x.pth

测试部分

修改路径

把Swin-Transformer-Object-Detection/tools/test.py得test.py文件进行插入自己的路径

 插入代码如下

# 修改数据路径
new_data_root = '/root/autodl-tmp/coco/'

# 修改 data_root
cfg.data_root = new_data_root

# 更新数据加载器中引用的路径
if hasattr(cfg.data, 'train'):
    cfg.data.train.ann_file = cfg.data.train.ann_file.replace('data/coco/', new_data_root)
    cfg.data.train.img_prefix = cfg.data.train.img_prefix.replace('data/coco/', new_data_root)

if hasattr(cfg.data, 'val'):
    cfg.data.val.ann_file = cfg.data.val.ann_file.replace('data/coco/', new_data_root)
    cfg.data.val.img_prefix = cfg.data.val.img_prefix.replace('data/coco/', new_data_root)

if hasattr(cfg.data, 'test'):
    cfg.data.test.ann_file = cfg.data.test.ann_file.replace('data/coco/', new_data_root)
    cfg.data.test.img_prefix = cfg.data.test.img_prefix.replace('data/coco/', new_data_root)

开始测试

python /root/Swin-Transformer-Object-Detection/tools/test.py /root/Swin-Transformer-Object-Detection/configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.py /root/mask_rcnn_swin_tiny_patch4_window7_1x.pth  --eval bbox segm

训练部分

把Swin-Transformer-Object-Detection/tools/train.py得train.py文件进行插入自己的路径

 代码如下

new_data_root = '/root/autodl-tmp/coco/'

# 更新数据集路径中的相关部分
cfg.data_root = new_data_root

# 训练集、验证集和测试集路径
if 'train' in cfg.data:
    cfg.data['train']['img_prefix'] = cfg.data['train']['img_prefix'].replace('data/coco/', new_data_root)
    cfg.data['train']['ann_file'] = cfg.data['train']['ann_file'].replace('data/coco/', new_data_root)

if 'val' in cfg.data:
    cfg.data['val']['img_prefix'] = cfg.data['val']['img_prefix'].replace('data/coco/', new_data_root)
    cfg.data['val']['ann_file'] = cfg.data['val']['ann_file'].replace('data/coco/', new_data_root)

if 'test' in cfg.data:
    cfg.data['test']['img_prefix'] = cfg.data['test']['img_prefix'].replace('data/coco/', new_data_root)
    cfg.data['test']['ann_file'] = cfg.data['test']['ann_file'].replace('data/coco/', new_data_root)

# 更新评估器路径中的 ann_file
if 'val_evaluator' in cfg and 'ann_file' in cfg.val_evaluator:
    cfg.val_evaluator['ann_file'] = cfg.val_evaluator['ann_file'].replace('data/coco/', new_data_root)

if 'test_evaluator' in cfg and 'ann_file' in cfg.test_evaluator:
    cfg.test_evaluator['ann_file'] = cfg.test_evaluator['ann_file'].replace('data/coco/', new_data_root)

if 'train_evaluator' in cfg and 'ann_file' in cfg.train_evaluator:
    cfg.train_evaluator['ann_file'] = cfg.train_evaluator['ann_file'].replace('data/coco/', new_data_root)

开始训练

python /root/Swin-Transformer-Object-Detection/tools/train.py /root/Swin-Transformer-Object-Detection/configs/swin/mask_rcnn_swin_tiny_patch4_window7_mstrain_480-800_adamw_1x_coco.py

<think>好的,我现在需要帮助用户解决在Autodl环境中缺失autodl-fs文件的问题。首先,我得理解autodl-fs是什么。根据名称猜测,这可能与文件系统或自动下载有关。但用户提到的引用中,引用[1]提到在user2陪过的v5.0环境下训练时,Arial.ttf无法下载导致报错,解决方法可能需要手动下载字体。这可能与文件下载问题有关,但不确定是否直接相关。 接下来,我需要确认用户的具体情况。用户没有提供错误信息的具体内容,所以可能需要先建议他们检查错误日志,确认是否确实是autodl-fs缺失引起的。比如,是否是“ModuleNotFoundError: No module named 'autodl_fs'”或者文件路径错误。 然后,考虑可能的原因。autodl-fs可能是一个自定义模块或依赖库,未正确安装。解决方法可能包括使用pip安装,或者从GitHub等源手动安装。如果autodl-fs是Autodl平台特定的工具,可能需要查阅官方文档或联系支持团队。 另外,引用[4]中提到处理图像填充和裁剪的代码,可能与文件系统操作无关,但用户的问题是关于文件缺失,可能需要检查文件路径是否正确,或者是否有权限问题。 可能的解决步骤: 1. 检查错误信息,确认缺失的具体文件或模块。 2. 如果是Python模块缺失,尝试使用pip安装。 3. 查找autodl-fs的官方文档或GitHub仓库,获取安装指南。 4. 检查文件路径是否正确,确保文件存在于指定位置。 5. 如果涉及平台特定问题,联系Autodl技术支持。 需要提醒用户提供更多错误细节,以便更准确地诊断问题。同时,根据引用[1]中的情况,手动下载所需文件可能是一个解决方法,但需要确认autodl-fs是否属于类似情况。 最后,生成相关问题,帮助用户扩展解决思路,比如环境配置、依赖安装等常见问题。</think>### 解决Autodl环境中缺失autodl-fs文件的方法 #### 步骤分析 1. **确认错误类型** 首先需明确错误提示内容。若报错信息为`ModuleNotFoundError: No module named 'autodl_fs'`,则表明缺少Python模块;若提示文件路径缺失(如`autodl-fs: command not found`),则可能是系统工具未安装。 2. **安装Python模块** 如果是Python模块缺失,尝试通过以下命令安装: ```bash pip install autodl-fs ``` 若官方源不存在此包,可能需要从GitHub仓库手动安装: ```bash pip install git+https://github.com/autodl-community/autodl-fs.git ``` 3. **检查平台工具** Autodl平台可能提供特定工具(如文件同步或管理工具)。查阅官方文档确认`autodl-fs`是否为内置工具。若需手动配置,可通过以下方式解决: ```bash # 示例:从平台指定位置下载工具 wget https://autodl.example.com/tools/autodl-fs chmod +x autodl-fs mv autodl-fs /usr/local/bin/ ``` 4. **文件路径修复** 若错误涉及文件路径(如`/path/to/autodl-fs`不存在),需检查代码中路径配置,或通过软链接修复: ```bash ln -s /actual/path/autodl-fs /expected/path/autodl-fs ``` 5. **联系技术支持** 若上述方法无效,建议提供完整错误日志并联系Autodl官方支持,引用类似文件下载问题的解决方法(如引用[1]中手动下载字体的思路)[^1]。 #### 示例操作 假设`autodl-fs`是自定义模块,修复流程如下: ```bash # 克隆仓库并安装 git clone https://github.com/autodl-community/autodl-fs.git cd autodl-fs python setup.py install ``` #### 相关问题 1. 如何排查Python模块导入失败的问题? 2. Autodl环境中如何手动安装第三方依赖? 3. 文件路径错误导致程序崩溃应如何调试? 4. 多任务学习中参数共享如何避免误差传播(如引用[2]中的场景)[^2]? 5. 生成式预训练模型如何适配分类任务(参考引用[3]的填空策略)[^3]? #### 引用说明 - 引用[1]的解决思路适用于文件下载失败场景[^1] - 多任务学习的参数共享机制与模块依赖问题有相似性[^2] - 预训练模型适配方法可类比环境配置的调整策略[^3]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值