Spaces:
Sleeping
Sleeping
make the image rescale
Browse files
app.py
CHANGED
|
@@ -19,7 +19,7 @@ from cubercnn.modeling.backbone import build_dla_from_vision_fpn_backbone # this
|
|
| 19 |
from cubercnn import util, vis
|
| 20 |
|
| 21 |
|
| 22 |
-
def do_test(im, threshold
|
| 23 |
if im is None:
|
| 24 |
return None, None
|
| 25 |
model = load_model_config()
|
|
@@ -28,8 +28,8 @@ def do_test(im, threshold, model_str):
|
|
| 28 |
|
| 29 |
thres = threshold
|
| 30 |
|
| 31 |
-
min_size =
|
| 32 |
-
max_size =
|
| 33 |
augmentations = T.AugmentationList([T.ResizeShortestEdge(min_size, max_size, "choice")])
|
| 34 |
|
| 35 |
category_path = 'configs/category_meta.json'
|
|
@@ -40,9 +40,11 @@ def do_test(im, threshold, model_str):
|
|
| 40 |
|
| 41 |
metadata = util.load_json(category_path)
|
| 42 |
cats = metadata['thing_classes']
|
| 43 |
-
|
| 44 |
-
|
|
|
|
| 45 |
|
|
|
|
| 46 |
h, w = image_shape
|
| 47 |
|
| 48 |
focal_length_ndc = 4.0
|
|
@@ -56,13 +58,9 @@ def do_test(im, threshold, model_str):
|
|
| 56 |
[0.0, 0.0, 1.0]
|
| 57 |
])
|
| 58 |
|
| 59 |
-
# dummy
|
| 60 |
-
aug_input = T.AugInput(im)
|
| 61 |
-
tfms = augmentations(aug_input)
|
| 62 |
-
image = aug_input.image
|
| 63 |
# model.to(device)
|
| 64 |
batched = [{
|
| 65 |
-
'image': torch.as_tensor(np.ascontiguousarray(
|
| 66 |
'height': image_shape[0], 'width': image_shape[1], 'K': K
|
| 67 |
}]
|
| 68 |
with torch.no_grad():
|
|
@@ -133,7 +131,7 @@ if __name__ == "__main__":
|
|
| 133 |
return model
|
| 134 |
|
| 135 |
title = 'Weak Cube R-CNN'
|
| 136 |
-
description = "This showcases the different our model [`Weak Cube RCNN`](https://arxiv.org/abs/2504.13297). To create Weak Cube RCNN, we modify the framework by replacing its 3D loss functions with ones based solely on 2D annotations. Our methods rely heavily on external, strong generalised deep learning models to infer spatial information in scenes. Experimental results show that all models perform comparably to an annotation time-equalised Cube R-CNN, whereof the pseudo ground truth method achieves the highest accuracy. The results show the methods' ability to understand scenes in 3D, providing satisfactory visual results. Although not precise enough for centimetre accurate measurements, the method provide a solid foundation for further research. \n Check out the code on [GitHub](https://github.com/AndreasLH/Weak-Cube-R-CNN)"
|
| 137 |
|
| 138 |
|
| 139 |
demo = gr.Interface(
|
|
@@ -141,15 +139,14 @@ if __name__ == "__main__":
|
|
| 141 |
fn=do_test,
|
| 142 |
inputs=[
|
| 143 |
gr.Image(label="Input Image"),
|
| 144 |
-
gr.Slider(0, 1, value=0.
|
| 145 |
-
gr.Textbox(value="Weak Cube R-CNN", visible=False, render=False)
|
| 146 |
],
|
| 147 |
outputs=[gr.Image(label="Predictions"), gr.Image(label="Top view")],
|
| 148 |
description=description,
|
| 149 |
-
|
| 150 |
-
examples=[["examples/ex2.jpg"],[
|
| 151 |
)
|
| 152 |
|
| 153 |
|
| 154 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 155 |
-
|
|
|
|
| 19 |
from cubercnn import util, vis
|
| 20 |
|
| 21 |
|
| 22 |
+
def do_test(im, threshold):
|
| 23 |
if im is None:
|
| 24 |
return None, None
|
| 25 |
model = load_model_config()
|
|
|
|
| 28 |
|
| 29 |
thres = threshold
|
| 30 |
|
| 31 |
+
min_size = 500
|
| 32 |
+
max_size = 1000
|
| 33 |
augmentations = T.AugmentationList([T.ResizeShortestEdge(min_size, max_size, "choice")])
|
| 34 |
|
| 35 |
category_path = 'configs/category_meta.json'
|
|
|
|
| 40 |
|
| 41 |
metadata = util.load_json(category_path)
|
| 42 |
cats = metadata['thing_classes']
|
| 43 |
+
aug_input = T.AugInput(im)
|
| 44 |
+
tfms = augmentations(aug_input)
|
| 45 |
+
im = tfms.apply_image(im)
|
| 46 |
|
| 47 |
+
image_shape = im.shape[:2] # h, w'
|
| 48 |
h, w = image_shape
|
| 49 |
|
| 50 |
focal_length_ndc = 4.0
|
|
|
|
| 58 |
[0.0, 0.0, 1.0]
|
| 59 |
])
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
# model.to(device)
|
| 62 |
batched = [{
|
| 63 |
+
'image': torch.as_tensor(np.ascontiguousarray(im.transpose(2, 0, 1))),
|
| 64 |
'height': image_shape[0], 'width': image_shape[1], 'K': K
|
| 65 |
}]
|
| 66 |
with torch.no_grad():
|
|
|
|
| 131 |
return model
|
| 132 |
|
| 133 |
title = 'Weak Cube R-CNN'
|
| 134 |
+
description = "This showcases the different our model [`Weak Cube RCNN`](https://arxiv.org/abs/2504.13297). To create Weak Cube RCNN, we modify the framework by replacing its 3D loss functions with ones based solely on 2D annotations. Our methods rely heavily on external, strong generalised deep learning models to infer spatial information in scenes. Experimental results show that all models perform comparably to an annotation time-equalised Cube R-CNN, whereof the pseudo ground truth method achieves the highest accuracy. The results show the methods' ability to understand scenes in 3D, providing satisfactory visual results. Although not precise enough for centimetre accurate measurements, the method provide a solid foundation for further research. \n Check out the code on [`GitHub`](https://github.com/AndreasLH/Weak-Cube-R-CNN)"
|
| 135 |
|
| 136 |
|
| 137 |
demo = gr.Interface(
|
|
|
|
| 139 |
fn=do_test,
|
| 140 |
inputs=[
|
| 141 |
gr.Image(label="Input Image"),
|
| 142 |
+
gr.Slider(0, 1, value=0.5, label="Threshold", info="Only show predictions with a confidence above this threshold"),
|
|
|
|
| 143 |
],
|
| 144 |
outputs=[gr.Image(label="Predictions"), gr.Image(label="Top view")],
|
| 145 |
description=description,
|
| 146 |
+
flagging_mode="never",
|
| 147 |
+
examples=[["examples/ex2.jpg"],["examples/ex1.jpg"]],
|
| 148 |
)
|
| 149 |
|
| 150 |
|
| 151 |
+
# demo.launch(server_name="0.0.0.0", server_port=7860)
|
| 152 |
+
demo.launch()
|