Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import cv2 as cv
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
|
|
@@ -20,6 +25,32 @@ def get_nth_frame(vc, n):
|
|
| 20 |
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
|
| 21 |
return img
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
with gr.Blocks() as demo:
|
|
@@ -38,21 +69,17 @@ with gr.Blocks() as demo:
|
|
| 38 |
with gr.Accordion('Show Frame'):
|
| 39 |
input_n = gr.Slider(0, 9999, value=0, step=1, label="n")
|
| 40 |
btn = gr.Button(value="Submit")
|
| 41 |
-
|
| 42 |
input_video.change(
|
| 43 |
-
video_change,
|
| 44 |
-
inputs=[input_video, state_vc],
|
| 45 |
outputs=[output_fps, output_fms, output_w, output_h, input_n, state_vc]
|
| 46 |
)
|
| 47 |
btn.click(get_nth_frame, inputs=[state_vc, input_n], outputs=output_img)
|
| 48 |
-
|
| 49 |
gr.Markdown("*****")
|
| 50 |
|
| 51 |
-
|
| 52 |
-
path = os.path.dirname(__file__)
|
| 53 |
-
print("path:", path)
|
| 54 |
-
df.to_csv('label.csv')
|
| 55 |
-
return [ path+"/test.mp4", path+"/label.csv"]
|
| 56 |
with gr.Row():
|
| 57 |
df = gr.Dataframe(
|
| 58 |
headers=["start_index", "end_index", "label"],
|
|
@@ -62,11 +89,11 @@ with gr.Blocks() as demo:
|
|
| 62 |
)
|
| 63 |
file = gr.File(file_count='multiple')
|
| 64 |
btn_make_dataset = gr.Button(value="make dataset")
|
| 65 |
-
btn_make_dataset.click(make_dataset, inputs=df, outputs=file)
|
| 66 |
|
| 67 |
gr.Markdown("*****")
|
| 68 |
gr.Examples([os.path.join(os.path.dirname(__file__), "test.mp4")], inputs=input_video)
|
| 69 |
-
|
| 70 |
|
| 71 |
|
| 72 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
| 2 |
+
import uuid
|
| 3 |
import cv2 as cv
|
| 4 |
+
import pandas as pd
|
| 5 |
+
|
| 6 |
+
from zipfile import ZipFile
|
| 7 |
+
|
| 8 |
|
| 9 |
import gradio as gr
|
| 10 |
|
|
|
|
| 25 |
img = cv.cvtColor(img, cv.COLOR_BGR2RGB)
|
| 26 |
return img
|
| 27 |
|
| 28 |
+
def make_dataset(vc, df):
|
| 29 |
+
path = __file__+"/"+str(uuid.uuid1())
|
| 30 |
+
os.mkdir(path)
|
| 31 |
+
os.mkdir(path+"/train")
|
| 32 |
+
headers = ["image_name", "label"]
|
| 33 |
+
label_df = pd.DataFrame(columns=headers)
|
| 34 |
+
with ZipFile(path+"/train.zip", "w") as zf:
|
| 35 |
+
for line in df.itertuples():
|
| 36 |
+
start_idx = int(line[1])
|
| 37 |
+
end_idx = int(line[2])
|
| 38 |
+
label = int(line[3])
|
| 39 |
+
vc.set(cv.CAP_PROP_POS_FRAMES, start_idx)
|
| 40 |
+
for idx in range(start_idx, end_idx):
|
| 41 |
+
ok, img = vc.read()
|
| 42 |
+
if not ok:
|
| 43 |
+
break
|
| 44 |
+
name = "image_%08d.jpg"%(idx)
|
| 45 |
+
cv.imwrite(path+"/train/"+name, img)
|
| 46 |
+
zf.write(path+"/train/"+name, arcname="train/"+name)
|
| 47 |
+
os.remove(path+"/train/"+name)
|
| 48 |
+
label_df = pd.concat([label_df, pd.DataFrame([[name, label]], columns=headers)])
|
| 49 |
+
label_df.to_csv(path+'/label.csv')
|
| 50 |
+
return [path+"/label.csv", path+"/train.zip"]
|
| 51 |
+
#return [ path+"/test.mp4", path+"/label.csv"]
|
| 52 |
+
|
| 53 |
+
|
| 54 |
|
| 55 |
|
| 56 |
with gr.Blocks() as demo:
|
|
|
|
| 69 |
with gr.Accordion('Show Frame'):
|
| 70 |
input_n = gr.Slider(0, 9999, value=0, step=1, label="n")
|
| 71 |
btn = gr.Button(value="Submit")
|
| 72 |
+
|
| 73 |
input_video.change(
|
| 74 |
+
video_change,
|
| 75 |
+
inputs=[input_video, state_vc],
|
| 76 |
outputs=[output_fps, output_fms, output_w, output_h, input_n, state_vc]
|
| 77 |
)
|
| 78 |
btn.click(get_nth_frame, inputs=[state_vc, input_n], outputs=output_img)
|
| 79 |
+
|
| 80 |
gr.Markdown("*****")
|
| 81 |
|
| 82 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
with gr.Row():
|
| 84 |
df = gr.Dataframe(
|
| 85 |
headers=["start_index", "end_index", "label"],
|
|
|
|
| 89 |
)
|
| 90 |
file = gr.File(file_count='multiple')
|
| 91 |
btn_make_dataset = gr.Button(value="make dataset")
|
| 92 |
+
btn_make_dataset.click(make_dataset, inputs=[state_vc, df], outputs=file)
|
| 93 |
|
| 94 |
gr.Markdown("*****")
|
| 95 |
gr.Examples([os.path.join(os.path.dirname(__file__), "test.mp4")], inputs=input_video)
|
| 96 |
+
|
| 97 |
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|