Spaces:
Sleeping
Sleeping
working
Browse files- .gitignore +3 -0
- README.md +5 -5
- app.py β app/main.py +0 -0
- playgrounds/load_video.py +5 -6
- playgrounds/main.py +3 -0
- playgrounds/movinet.py +0 -4
- playgrounds/yolo.py +30 -26
.gitignore
CHANGED
@@ -5,3 +5,6 @@
|
|
5 |
# data
|
6 |
assets
|
7 |
out
|
|
|
|
|
|
|
|
5 |
# data
|
6 |
assets
|
7 |
out
|
8 |
+
|
9 |
+
# python
|
10 |
+
__pycache__
|
README.md
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
---
|
2 |
title: Aero Recognize
|
3 |
-
emoji:
|
4 |
colorFrom: gray
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.12.0
|
8 |
-
app_file: app.py
|
9 |
pinned: false
|
10 |
license: bsd-2-clause
|
11 |
---
|
12 |
-
|
13 |
-
|
|
|
1 |
---
|
2 |
title: Aero Recognize
|
3 |
+
emoji: π«
|
4 |
colorFrom: gray
|
5 |
+
colorTo: indigo
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.12.0
|
8 |
+
app_file: app/main.py
|
9 |
pinned: false
|
10 |
license: bsd-2-clause
|
11 |
---
|
12 |
+
# Aero Recognize
|
13 |
+
Aeroplane detector and action classifier.
|
app.py β app/main.py
RENAMED
File without changes
|
playgrounds/load_video.py
CHANGED
@@ -4,7 +4,6 @@ import numpy as np
|
|
4 |
import tensorflow as tf
|
5 |
import cv2
|
6 |
from pathlib import Path
|
7 |
-
print('Modules loaded.')
|
8 |
|
9 |
SPLIT_RATIO = 0.7
|
10 |
BATCH_SIZE = 8
|
@@ -64,13 +63,15 @@ def frames_from_video_file(video_path, n_frames, output_size=(224, 224), frame_s
|
|
64 |
|
65 |
src.set(cv2.CAP_PROP_POS_FRAMES, start)
|
66 |
# ret is a boolean indicating whether read was successful, frame is the image itself
|
67 |
-
|
|
|
|
|
68 |
result.append(format_frames(frame, output_size))
|
69 |
|
70 |
for _ in range(n_frames - 1):
|
71 |
for _ in range(frame_step):
|
72 |
-
|
73 |
-
if
|
74 |
frame = format_frames(frame, output_size)
|
75 |
result.append(frame)
|
76 |
else:
|
@@ -109,5 +110,3 @@ def frame_generator(data_dir: Path, n_frames: int, split: Literal['training', 'v
|
|
109 |
label = class_ids_for_name[name] # Encode labels
|
110 |
yield video_frames, label
|
111 |
return generator
|
112 |
-
|
113 |
-
main()
|
|
|
4 |
import tensorflow as tf
|
5 |
import cv2
|
6 |
from pathlib import Path
|
|
|
7 |
|
8 |
SPLIT_RATIO = 0.7
|
9 |
BATCH_SIZE = 8
|
|
|
63 |
|
64 |
src.set(cv2.CAP_PROP_POS_FRAMES, start)
|
65 |
# ret is a boolean indicating whether read was successful, frame is the image itself
|
66 |
+
ok, frame = src.read()
|
67 |
+
if not ok:
|
68 |
+
raise ValueError('read video not success')
|
69 |
result.append(format_frames(frame, output_size))
|
70 |
|
71 |
for _ in range(n_frames - 1):
|
72 |
for _ in range(frame_step):
|
73 |
+
ok, frame = src.read()
|
74 |
+
if ok:
|
75 |
frame = format_frames(frame, output_size)
|
76 |
result.append(frame)
|
77 |
else:
|
|
|
110 |
label = class_ids_for_name[name] # Encode labels
|
111 |
yield video_frames, label
|
112 |
return generator
|
|
|
|
playgrounds/main.py
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
from playgrounds.yolo import main
|
2 |
+
|
3 |
+
main()
|
playgrounds/movinet.py
CHANGED
@@ -2,7 +2,6 @@ import tensorflow as tf
|
|
2 |
import numpy as np
|
3 |
import tensorflow_hub as hub
|
4 |
import keras
|
5 |
-
print('Modules loaded.')
|
6 |
|
7 |
labels_path = keras.utils.get_file(
|
8 |
fname='labels.txt',
|
@@ -14,7 +13,6 @@ with open(labels_path, 'r', encoding='utf-8') as file:
|
|
14 |
|
15 |
KINETICS_600_LABELS = np.array([line.strip() for line in lines])
|
16 |
KINETICS_600_LABELS[:20]
|
17 |
-
print('Labels loaded.')
|
18 |
|
19 |
def main():
|
20 |
jumping_jack_path = 'assets/jumping_pack.gif'
|
@@ -80,5 +78,3 @@ def load_gif(file_path, image_size=(224, 224)):
|
|
80 |
# ref: https://www.tensorflow.org/hub/common_signatures/images#input
|
81 |
video = tf.cast(video, tf.float32) / 255.
|
82 |
return video
|
83 |
-
|
84 |
-
main()
|
|
|
2 |
import numpy as np
|
3 |
import tensorflow_hub as hub
|
4 |
import keras
|
|
|
5 |
|
6 |
labels_path = keras.utils.get_file(
|
7 |
fname='labels.txt',
|
|
|
13 |
|
14 |
KINETICS_600_LABELS = np.array([line.strip() for line in lines])
|
15 |
KINETICS_600_LABELS[:20]
|
|
|
16 |
|
17 |
def main():
|
18 |
jumping_jack_path = 'assets/jumping_pack.gif'
|
|
|
78 |
# ref: https://www.tensorflow.org/hub/common_signatures/images#input
|
79 |
video = tf.cast(video, tf.float32) / 255.
|
80 |
return video
|
|
|
|
playgrounds/yolo.py
CHANGED
@@ -2,35 +2,39 @@ import keras
|
|
2 |
import keras_cv
|
3 |
import numpy as np
|
4 |
import tensorflow as tf
|
5 |
-
print('Modules loaded.')
|
6 |
|
7 |
-
|
8 |
-
"yolo_v8_m_pascalvoc", bounding_box_format="xywh"
|
9 |
-
)
|
10 |
-
print('Model loaded.')
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
]
|
20 |
-
class_mapping = {i: c for (i, c) in enumerate(class_ids)}
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
# image = keras.utils.load_img('assets/nick-morales-BwYcH78rcpI-unsplash.jpg')
|
28 |
-
# image = np.array(image)
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
|
|
|
|
|
2 |
import keras_cv
|
3 |
import numpy as np
|
4 |
import tensorflow as tf
|
|
|
5 |
|
6 |
+
from playgrounds.load_video import frames_from_video_file
|
|
|
|
|
|
|
7 |
|
8 |
+
def main():
|
9 |
+
pretrained_model = keras_cv.models.YOLOV8Detector.from_preset(
|
10 |
+
"yolo_v8_m_pascalvoc", bounding_box_format="xywh"
|
11 |
+
)
|
12 |
+
print('Model loaded.')
|
13 |
|
14 |
+
inference_resizing = keras_cv.layers.Resizing(
|
15 |
+
640, 640, pad_to_aspect_ratio=True, bounding_box_format="xywh"
|
16 |
+
)
|
|
|
|
|
17 |
|
18 |
+
class_ids = [
|
19 |
+
"Aeroplane", "Bicycle", "Bird", "Boat", "Bottle", "Bus", "Car", "Cat", "Chair", "Cow", "Dining Table",
|
20 |
+
"Dog", "Horse", "Motorbike", "Person", "Potted Plant", "Sheep", "Sofa", "Train", "Tvmonitor", "Total",
|
21 |
+
]
|
22 |
+
class_mapping = {i: c for (i, c) in enumerate(class_ids)}
|
|
|
|
|
23 |
|
24 |
+
# raw = tf.io.read_file('assets/IMG_9528.gif')
|
25 |
+
# video = tf.io.decode_gif(raw)
|
26 |
+
video = frames_from_video_file('assets/dataset/Flying/2kNjmM8BnD0_230.0_238.0.mp4', 3, (640,640))
|
27 |
+
image = video[0]
|
28 |
+
image = (image*255).astype(np.uint8)
|
29 |
+
file = tf.io.encode_png(image)
|
30 |
+
tf.io.write_file('out/t.png', file)
|
31 |
+
# image = keras.utils.load_img('assets/nick-morales-BwYcH78rcpI-unsplash.jpg')
|
32 |
+
# image = np.array(image)
|
33 |
|
34 |
+
image_batch = inference_resizing([image])
|
35 |
+
|
36 |
+
y_pred = pretrained_model.predict(image_batch)
|
37 |
+
classes = y_pred['classes']
|
38 |
+
boxes = y_pred["boxes"]
|
39 |
+
print(f'Classes: {classes}')
|
40 |
+
print(f'Boxes: {boxes}')
|