t29mato Claude Opus 4.6 commited on
Commit
168a22c
·
1 Parent(s): c220d72

Add missing mmcv.ops stubs: RoIPool, DeformConv2d, etc.

Browse files

The shim was missing RoIPool (needed by mmdet.apis.inference)
and other ops imported at module load time. Add stubs for all
ops referenced by mmdet to prevent ImportError at startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. setup_mmcv_shim.py +64 -1
setup_mmcv_shim.py CHANGED
@@ -67,6 +67,45 @@ class RoIAlign(torch.nn.Module):
67
  self.aligned = aligned
68
  def forward(self, input, rois):
69
  return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, aligned=self.aligned)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  '''
71
 
72
  with open(os.path.join(ops_dir, '__init__.py'), 'w') as f:
@@ -81,6 +120,30 @@ with open(os.path.join(nms_dir, '__init__.py'), 'w') as f:
81
  # Create carafe stub
82
  carafe_path = os.path.join(ops_dir, 'carafe.py')
83
  with open(carafe_path, 'w') as f:
84
- f.write('# carafe stub - not needed for CPU inference\n')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
  print('mmcv.ops shim created successfully')
 
67
  self.aligned = aligned
68
  def forward(self, input, rois):
69
  return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, aligned=self.aligned)
70
+
71
+ class RoIPool(torch.nn.Module):
72
+ def __init__(self, output_size, spatial_scale=1.0):
73
+ super().__init__()
74
+ self.output_size = output_size
75
+ self.spatial_scale = spatial_scale
76
+ def forward(self, input, rois):
77
+ return tv_ops.roi_pool(input, rois, self.output_size, self.spatial_scale)
78
+
79
+ class DeformConv2d(torch.nn.Module):
80
+ def __init__(self, *args, **kwargs):
81
+ super().__init__()
82
+ raise NotImplementedError("DeformConv2d not available in CPU shim")
83
+
84
+ class ModulatedDeformConv2d(torch.nn.Module):
85
+ def __init__(self, *args, **kwargs):
86
+ super().__init__()
87
+ raise NotImplementedError("ModulatedDeformConv2d not available in CPU shim")
88
+
89
+ DeformConv2dPack = DeformConv2d
90
+ ModulatedDeformConv2dPack = ModulatedDeformConv2d
91
+
92
+ class MaskedConv2d(torch.nn.Conv2d):
93
+ def __init__(self, *args, **kwargs):
94
+ super().__init__(*args, **kwargs)
95
+
96
+ class CornerPool(torch.nn.Module):
97
+ def __init__(self, *args, **kwargs):
98
+ super().__init__()
99
+ raise NotImplementedError("CornerPool not available in CPU shim")
100
+
101
+ def point_sample(*args, **kwargs):
102
+ raise NotImplementedError("point_sample not available in CPU shim")
103
+
104
+ def rel_roi_point_to_rel_img_point(*args, **kwargs):
105
+ raise NotImplementedError("rel_roi_point_to_rel_img_point not available in CPU shim")
106
+
107
+ def nms_match(*args, **kwargs):
108
+ raise NotImplementedError("nms_match not available in CPU shim")
109
  '''
110
 
111
  with open(os.path.join(ops_dir, '__init__.py'), 'w') as f:
 
120
  # Create carafe stub
121
  carafe_path = os.path.join(ops_dir, 'carafe.py')
122
  with open(carafe_path, 'w') as f:
123
+ f.write('class CARAFEPack: pass\n')
124
+
125
+ # Create roi_align submodule
126
+ roi_align_dir = os.path.join(ops_dir, 'roi_align')
127
+ os.makedirs(roi_align_dir, exist_ok=True)
128
+ with open(os.path.join(roi_align_dir, '__init__.py'), 'w') as f:
129
+ f.write('from mmcv.ops import roi_align, RoIAlign\n')
130
+
131
+ # Create modulated_deform_conv stub
132
+ with open(os.path.join(ops_dir, 'modulated_deform_conv.py'), 'w') as f:
133
+ f.write('from mmcv.ops import ModulatedDeformConv2d, ModulatedDeformConv2dPack\n')
134
+
135
+ # Create merge_cells stub
136
+ with open(os.path.join(ops_dir, 'merge_cells.py'), 'w') as f:
137
+ f.write('''class GlobalPoolingCell:
138
+ def __init__(self, *args, **kwargs): raise NotImplementedError
139
+ class SumCell:
140
+ def __init__(self, *args, **kwargs): raise NotImplementedError
141
+ class ConcatCell:
142
+ def __init__(self, *args, **kwargs): raise NotImplementedError
143
+ ''')
144
+
145
+ # Create multi_scale_deform_attn stub
146
+ with open(os.path.join(ops_dir, 'multi_scale_deform_attn.py'), 'w') as f:
147
+ f.write('class MultiScaleDeformableAttention: pass\n')
148
 
149
  print('mmcv.ops shim created successfully')