Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Project] support SAM inferencer #2897

Merged
merged 8 commits into from Apr 19, 2023
Merged

Conversation

xiexinch
Copy link
Collaborator

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@xiexinch xiexinch changed the title [Feature] support SAM inferencer [Project] support SAM inferencer Apr 17, 2023

- Python 3.10
- PyTorch 1.13

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add prerequisites for mmengine mmcv mmseg?

```shell
pip install openmim
mim install mmengine
mim install 'mmcv>=1.0.0'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmpretrain require mmcv>=2.0.0?

@xiexinch xiexinch merged commit 20f80f9 into open-mmlab:dev-1.x Apr 19, 2023
7 checks passed
@xiexinch xiexinch deleted the sam-inferencer branch April 24, 2023 03:09
@xiaowuwqg
Copy link

一、首先非常感谢您的贡献,看了您在mmsegmentation上面写的SAM推理器,自己部署运行了,模型可以跑起来,但是不知道为什么每次到模型评估保存点就会断开,出现如下错误:
Traceback (most recent call last):
File "E:\ShenDuXueXi\mmsegmentation-1.1.2\tools\train.py", line 104, in
main()
File "E:\ShenDuXueXi\mmsegmentation-1.1.2\tools\train.py", line 100, in main
runner.train()
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\runner.py", line 1777, in train
model = self.train_loop.run() # type: ignore
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\loops.py", line 292, in run
self.runner.val_loop.run()
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\loops.py", line 371, in run
self.run_iter(idx, data_batch)
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\torch\utils_contextlib.py", line 115, in decorate_context
return func(*args, **kwargs)
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\runner\loops.py", line 391, in run_iter
outputs = self.runner.model.val_step(data_batch)
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\model\base_model\base_model.py", line 133, in val_step
return self._run_forward(data, mode='predict') # type: ignore
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\mmengine\model\base_model\base_model.py", line 361, in _run_forward
results = self(**data, mode=mode)
File "E:\ShenDuXueXi\Anaconda\envs\mmseg-1.1.2\lib\site-packages\torch\nn\modules\module.py", line 1501, in _call_impl
return forward_call(*args, **kwargs)
File "E:\ShenDuXueXi\mmsegmentation-1.1.2\mmseg\models\segmentors\base.py", line 96, in forward
return self.predict(inputs, data_samples)
File "E:\ShenDuXueXi\mmsegmentation-1.1.2\mmseg\models\segmentors\encoder_decoder.py", line 220, in predict
seg_logits = self.inference(inputs, batch_img_metas)
File "E:\ShenDuXueXi\mmsegmentation-1.1.2\mmseg\models\segmentors\encoder_decoder.py", line 331, in inference
assert self.test_cfg.get('mode', 'whole') in ['slide', 'whole'],
AttributeError: 'NoneType' object has no attribute 'get'
请问大家是否遇到相同的问题?
版本如下:拉取的mmsegmentation-dev_1.x(具体安装为1.2.2),pytorch-2.0.0,mmengine-0.10.3,mmcv-2.0.0
二、配置文件如下:
Pretrained = 'https://download.openmmlab.com/mmclassification/v1/vit_sam/vit-base-p16_sam-pre_3rdparty_sa1b-1024px_20230411-2320f9cc.pth'
checkpoint_path = 'https://download.openmmlab.com/mmclassification/v1/vit_sam/vit-base-p16_sam-pre_3rdparty_sa1b-1024px_20230411-2320f9cc.pth'
crop_size = (
512,
512,
)
data_preprocessor = dict(
bgr_to_rgb=True,
mean=[
123.675,
116.28,
103.53,
],
pad_val=0,
seg_pad_val=255,
size=(
512,
512,
),
std=[
58.395,
57.12,
57.375,
],
test_cfg=dict(size=(
512,
512,
)),
type='SegDataPreProcessor')
data_root = 'E:\ShenDuXueXi\mmsegmentation-dev-1.x\data'
dataset_type = 'ZihaoDataset'
default_hooks = dict(
checkpoint=dict(by_epoch=False, interval=100, type='CheckpointHook'),
logger=dict(interval=50, log_metric_by_epoch=False, type='LoggerHook'),
param_scheduler=dict(type='ParamSchedulerHook'),
sampler_seed=dict(type='DistSamplerSeedHook'),
timer=dict(type='IterTimerHook'),
visualization=dict(type='SegVisualizationHook'))
default_scope = 'mmseg'
env_cfg = dict(
cudnn_benchmark=True,
dist_cfg=dict(backend='nccl'),
mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0))
img_ratios = [
0.5,
0.75,
1.0,
1.25,
1.5,
1.75,
]
launcher = 'none'
load_from = None
log_level = 'INFO'
log_processor = dict(by_epoch=False)
model = dict(
backbone=dict(
arch='base',
img_size=512,
init_cfg=dict(
checkpoint=
'https://download.openmmlab.com/mmclassification/v1/vit_sam/vit-base-p16_sam-pre_3rdparty_sa1b-1024px_20230411-2320f9cc.pth',
prefix='backbone',
type='Pretrained'),
out_channels=256,
patch_size=16,
type='ViTSAM',
use_abs_pos=True,
use_rel_pos=True,
window_size=14),
decode_head=dict(
align_corners=False,
channels=128,
concat_input=True,
dropout_ratio=0.1,
in_channels=256,
in_index=0,
loss_decode=dict(
loss_weight=1.0, type='CrossEntropyLoss', use_sigmoid=False),
norm_cfg=dict(requires_grad=True, type='BN'),
num_classes=2,
num_convs=2,
type='FCNHead'),
type='EncoderDecoder')
norm_cfg = dict(requires_grad=True, type='BN')
optim_wrapper = dict(
clip_grad=None,
optimizer=dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0005),
type='OptimWrapper')
optimizer = dict(lr=0.01, momentum=0.9, type='SGD', weight_decay=0.0005)
param_scheduler = [
dict(
begin=0,
by_epoch=False,
end=20000,
eta_min=0.0001,
power=0.9,
type='PolyLR'),
]
resume = False
test_cfg = dict(type='TestLoop')
test_dataloader = dict(
batch_size=1,
dataset=dict(
data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'),
data_root='E:\ShenDuXueXi\mmsegmentation-dev-1.x\data',
pipeline=[
dict(type='LoadImageFromFile'),
dict(keep_ratio=True, scale=(
2048,
1024,
), type='Resize'),
dict(type='LoadAnnotations'),
dict(type='PackSegInputs'),
],
type='ZihaoDataset'),
num_workers=4,
persistent_workers=True,
sampler=dict(shuffle=False, type='DefaultSampler'))
test_evaluator = dict(
iou_metrics=[
'mIoU',
'mDice',
'mFscore',
], type='IoUMetric')
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(keep_ratio=True, scale=(
2048,
1024,
), type='Resize'),
dict(type='LoadAnnotations'),
dict(type='PackSegInputs'),
]
train_cfg = dict(max_iters=20000, type='IterBasedTrainLoop', val_interval=100)
train_dataloader = dict(
batch_size=2,
dataset=dict(
data_prefix=dict(
img_path='img_dir/train', seg_map_path='ann_dir/train'),
data_root='E:\ShenDuXueXi\mmsegmentation-dev-1.x\data',
pipeline=[
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations'),
dict(
keep_ratio=True,
ratio_range=(
0.5,
2.0,
),
scale=(
2048,
1024,
),
type='RandomResize'),
dict(
cat_max_ratio=0.75, crop_size=(
512,
512,
), type='RandomCrop'),
dict(prob=0.5, type='RandomFlip'),
dict(type='PhotoMetricDistortion'),
dict(type='PackSegInputs'),
],
type='ZihaoDataset'),
num_workers=2,
persistent_workers=True,
sampler=dict(shuffle=True, type='InfiniteSampler'))
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations'),
dict(
keep_ratio=True,
ratio_range=(
0.5,
2.0,
),
scale=(
2048,
1024,
),
type='RandomResize'),
dict(cat_max_ratio=0.75, crop_size=(
512,
512,
), type='RandomCrop'),
dict(prob=0.5, type='RandomFlip'),
dict(type='PhotoMetricDistortion'),
dict(type='PackSegInputs'),
]
tta_model = dict(type='SegTTAModel')
tta_pipeline = [
dict(file_client_args=dict(backend='disk'), type='LoadImageFromFile'),
dict(
transforms=[
[
dict(keep_ratio=True, scale_factor=0.5, type='Resize'),
dict(keep_ratio=True, scale_factor=0.75, type='Resize'),
dict(keep_ratio=True, scale_factor=1.0, type='Resize'),
dict(keep_ratio=True, scale_factor=1.25, type='Resize'),
dict(keep_ratio=True, scale_factor=1.5, type='Resize'),
dict(keep_ratio=True, scale_factor=1.75, type='Resize'),
],
[
dict(direction='horizontal', prob=0.0, type='RandomFlip'),
dict(direction='horizontal', prob=1.0, type='RandomFlip'),
],
[
dict(type='LoadAnnotations'),
],
[
dict(type='PackSegInputs'),
],
],
type='TestTimeAug'),
]
val_cfg = dict(type='ValLoop')
val_dataloader = dict(
batch_size=1,
dataset=dict(
data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'),
data_root='E:\ShenDuXueXi\mmsegmentation-dev-1.x\data',
pipeline=[
dict(type='LoadImageFromFile'),
dict(keep_ratio=True, scale=(
2048,
1024,
), type='Resize'),
dict(type='LoadAnnotations'),
dict(type='PackSegInputs'),
],
type='ZihaoDataset'),
num_workers=4,
persistent_workers=True,
sampler=dict(shuffle=False, type='DefaultSampler'))
val_evaluator = dict(
iou_metrics=[
'mIoU',
'mDice',
'mFscore',
], type='IoUMetric')
vis_backends = [
dict(type='LocalVisBackend'),
]
visualizer = dict(
name='visualizer',
type='SegLocalVisualizer',
vis_backends=[
dict(type='LocalVisBackend'),
])
work_dir = './work_dirs\sam_vit-b_fcn_8xb2-40k_cityscapes-512x1024'

nahidnazifi87 pushed a commit to nahidnazifi87/mmsegmentation_playground that referenced this pull request Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants