Update app.py
Browse files
app.py
CHANGED
|
@@ -24,8 +24,7 @@ import torchvision.transforms.functional as F
|
|
| 24 |
from torchvision.io import read_video
|
| 25 |
from torchvision.models.optical_flow import Raft_Large_Weights
|
| 26 |
from torchvision.models.optical_flow import raft_large
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
import tempfile
|
| 31 |
from pathlib import Path
|
|
@@ -115,12 +114,16 @@ def infer():
|
|
| 115 |
|
| 116 |
from torchvision.utils import flow_to_image
|
| 117 |
|
| 118 |
-
flow_imgs = flow_to_image(predicted_flows)
|
| 119 |
|
| 120 |
-
print(flow_imgs)
|
| 121 |
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
| 123 |
|
|
|
|
| 124 |
####################################
|
| 125 |
# Bonus: Creating GIFs of predicted flows
|
| 126 |
# ---------------------------------------
|
|
@@ -166,4 +169,4 @@ def write_flo(filename, flow):
|
|
| 166 |
flow.tofile(f)
|
| 167 |
f.close()
|
| 168 |
|
| 169 |
-
gr.Interface(fn=infer, inputs=[], outputs=gr.Textbox()).launch()
|
|
|
|
| 24 |
from torchvision.io import read_video
|
| 25 |
from torchvision.models.optical_flow import Raft_Large_Weights
|
| 26 |
from torchvision.models.optical_flow import raft_large
|
| 27 |
+
from torchvision.io import write_jpeg
|
|
|
|
| 28 |
|
| 29 |
import tempfile
|
| 30 |
from pathlib import Path
|
|
|
|
| 114 |
|
| 115 |
from torchvision.utils import flow_to_image
|
| 116 |
|
| 117 |
+
#flow_imgs = flow_to_image(predicted_flows)
|
| 118 |
|
| 119 |
+
#print(flow_imgs)
|
| 120 |
|
| 121 |
+
predicted_flow = list_of_flows[-1][0]
|
| 122 |
+
flow_img = flow_to_image(predicted_flow).to("cpu")
|
| 123 |
+
# output_folder = "/tmp/" # Update this to the folder of your choice
|
| 124 |
+
write_jpeg(flow_img, f"predicted_flow_{i}.jpg")
|
| 125 |
|
| 126 |
+
return "done", "predicted_flow_{i}.jpg"
|
| 127 |
####################################
|
| 128 |
# Bonus: Creating GIFs of predicted flows
|
| 129 |
# ---------------------------------------
|
|
|
|
| 169 |
flow.tofile(f)
|
| 170 |
f.close()
|
| 171 |
|
| 172 |
+
gr.Interface(fn=infer, inputs=[], outputs=[gr.Textbox(), gr.Image()]).launch()
|