Update app.py
Browse files
app.py
CHANGED
@@ -28,6 +28,7 @@ from torchvision.io import read_video
|
|
28 |
from torchvision.models.optical_flow import Raft_Large_Weights
|
29 |
from torchvision.models.optical_flow import raft_large
|
30 |
from torchvision.io import write_jpeg
|
|
|
31 |
|
32 |
import tempfile
|
33 |
from pathlib import Path
|
@@ -193,11 +194,21 @@ def infer():
|
|
193 |
# output_folder = "/tmp/" # Update this to the folder of your choice
|
194 |
write_jpeg(flow_img, f"predicted_flow.jpg")
|
195 |
flo_file = write_flo(predicted_flow, "flofile.flo")
|
196 |
-
write_jpeg(frames[100], f"input_image.jpg")
|
197 |
#res = warp_image(img1_batch, predicted_flow)
|
198 |
-
|
199 |
-
|
200 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
201 |
####################################
|
202 |
# Bonus: Creating GIFs of predicted flows
|
203 |
# ---------------------------------------
|
@@ -226,4 +237,4 @@ def infer():
|
|
226 |
# ffmpeg -f image2 -framerate 30 -i predicted_flow_%d.jpg -loop -1 flow.gif
|
227 |
|
228 |
|
229 |
-
gr.Interface(fn=infer, inputs=[], outputs=[gr.Textbox(), gr.Image(), gr.Files()]).launch()
|
|
|
28 |
from torchvision.models.optical_flow import Raft_Large_Weights
|
29 |
from torchvision.models.optical_flow import raft_large
|
30 |
from torchvision.io import write_jpeg
|
31 |
+
import torchvision.transforms as T
|
32 |
|
33 |
import tempfile
|
34 |
from pathlib import Path
|
|
|
194 |
# output_folder = "/tmp/" # Update this to the folder of your choice
|
195 |
write_jpeg(flow_img, f"predicted_flow.jpg")
|
196 |
flo_file = write_flo(predicted_flow, "flofile.flo")
|
197 |
+
#write_jpeg(frames[100], f"input_image.jpg")
|
198 |
#res = warp_image(img1_batch, predicted_flow)
|
199 |
+
|
200 |
+
# define a transform to convert a tensor to PIL image
|
201 |
+
transform = T.ToPILImage()
|
202 |
+
|
203 |
+
# convert the tensor to PIL image using above transform
|
204 |
+
img = transform(frames[100])
|
205 |
+
|
206 |
+
# display the PIL image
|
207 |
+
#img.show()
|
208 |
+
img.save('frame_input.jpg')
|
209 |
+
#res = get_warp_res("input_image.jpg", "flofile.flo", fname_output='warped.png')
|
210 |
+
#print(res)
|
211 |
+
return "done", "predicted_flow.jpg", ["flofile.flo"], 'frame_input.jpg'
|
212 |
####################################
|
213 |
# Bonus: Creating GIFs of predicted flows
|
214 |
# ---------------------------------------
|
|
|
237 |
# ffmpeg -f image2 -framerate 30 -i predicted_flow_%d.jpg -loop -1 flow.gif
|
238 |
|
239 |
|
240 |
+
gr.Interface(fn=infer, inputs=[], outputs=[gr.Textbox(), gr.Image(), gr.Files(), gr.Image()]).launch()
|