Spaces:
Runtime error
Runtime error
Add sigmoid_focal_loss, deform_conv2d, get_onnxruntime_op_path to shim
Browse filesThese are imported by mmdet during module loading and must be
available even if not used at inference time.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- setup_mmcv_shim.py +22 -0
setup_mmcv_shim.py
CHANGED
|
@@ -106,6 +106,28 @@ def rel_roi_point_to_rel_img_point(*args, **kwargs):
|
|
| 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:
|
|
|
|
| 106 |
|
| 107 |
def nms_match(*args, **kwargs):
|
| 108 |
raise NotImplementedError("nms_match not available in CPU shim")
|
| 109 |
+
|
| 110 |
+
def sigmoid_focal_loss(input, target, gamma=2.0, alpha=0.25, weight=None, reduction="mean"):
|
| 111 |
+
p = torch.sigmoid(input)
|
| 112 |
+
ce_loss = torch.nn.functional.binary_cross_entropy_with_logits(input, target, reduction="none")
|
| 113 |
+
p_t = p * target + (1 - p) * (1 - target)
|
| 114 |
+
loss = ce_loss * ((1 - p_t) ** gamma)
|
| 115 |
+
if alpha >= 0:
|
| 116 |
+
alpha_t = alpha * target + (1 - alpha) * (1 - target)
|
| 117 |
+
loss = alpha_t * loss
|
| 118 |
+
if weight is not None:
|
| 119 |
+
loss = loss * weight
|
| 120 |
+
if reduction == "mean":
|
| 121 |
+
return loss.mean()
|
| 122 |
+
elif reduction == "sum":
|
| 123 |
+
return loss.sum()
|
| 124 |
+
return loss
|
| 125 |
+
|
| 126 |
+
def deform_conv2d(*args, **kwargs):
|
| 127 |
+
raise NotImplementedError("deform_conv2d not available in CPU shim")
|
| 128 |
+
|
| 129 |
+
def get_onnxruntime_op_path():
|
| 130 |
+
return ""
|
| 131 |
'''
|
| 132 |
|
| 133 |
with open(os.path.join(ops_dir, '__init__.py'), 'w') as f:
|