Spaces:
Sleeping
Sleeping
added files
Browse files- app.py +64 -0
- detection_training/F1_curve.png +0 -0
- detection_training/PR_curve.png +0 -0
- detection_training/P_curve.png +0 -0
- detection_training/R_curve.png +0 -0
- detection_training/args.yaml +98 -0
- detection_training/confusion_matrix.png +0 -0
- detection_training/confusion_matrix_normalized.png +0 -0
- detection_training/events.out.tfevents.1723263798.193db2adeb1d.880.0 +3 -0
- detection_training/labels.jpg +0 -0
- detection_training/labels_correlogram.jpg +0 -0
- detection_training/results.csv +11 -0
- detection_training/results.png +0 -0
- detection_training/train_batch0.jpg +0 -0
- detection_training/train_batch1.jpg +0 -0
- detection_training/train_batch2.jpg +0 -0
- detection_training/val_batch0_labels.jpg +0 -0
- detection_training/val_batch0_pred.jpg +0 -0
- detection_training/val_batch1_labels.jpg +0 -0
- detection_training/val_batch1_pred.jpg +0 -0
- detection_training/val_batch2_labels.jpg +0 -0
- detection_training/val_batch2_pred.jpg +0 -0
- detection_training/weights/detect.pt +3 -0
- detection_training/weights/last.pt +3 -0
- faces_classifier.ipynb +0 -0
- faces_detector.ipynb +0 -0
- faces_prediction.ipynb +0 -0
- models/detect.pt +3 -0
- models/mood.pkl +3 -0
- mood_data.zip +3 -0
- opensans.ttf +0 -0
- requirements.txt.txt +4 -0
- sample_images/angry.jpg +0 -0
- sample_images/friends.jpg +0 -0
- sample_images/office.jpg +0 -0
app.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import ultralytics
|
4 |
+
from ultralytics import YOLO
|
5 |
+
from PIL import Image, ImageDraw, ImageFont
|
6 |
+
|
7 |
+
# import os
|
8 |
+
# Load a pre-trained image classification model
|
9 |
+
import pathlib
|
10 |
+
plt = platform.system()
|
11 |
+
if plt == 'Windows': pathlib.PosixPath = pathlib.WindowsPath
|
12 |
+
if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath
|
13 |
+
|
14 |
+
root = os.path.dirname(__file__)
|
15 |
+
|
16 |
+
detect = YOLO('./models/detect.pt')
|
17 |
+
mood = load_learner("./models/mood.pkl")
|
18 |
+
|
19 |
+
|
20 |
+
# Function to make predictions from an image
|
21 |
+
def process(image):
|
22 |
+
boxes = detect.predict(image)
|
23 |
+
Image.open(image)
|
24 |
+
image_with_boxes = image.copy()
|
25 |
+
|
26 |
+
draw = ImageDraw.Draw(image_with_boxes)
|
27 |
+
|
28 |
+
for i, box in enumerate(boxes[0].boxes.xyxy):
|
29 |
+
# print(box)
|
30 |
+
x1, y1, x2, y2 = int(box[0]), int(box[1]), int(box[2]), int(box[3])
|
31 |
+
|
32 |
+
cropped_image = image.crop((x1, y1, x2, y2))
|
33 |
+
resized_image = cropped_image.resize((48, 48))
|
34 |
+
grayscale_image = resized_image.convert('L')
|
35 |
+
|
36 |
+
w = (y2+x2-y1-x1)//50
|
37 |
+
pil_image = PILImage.create(grayscale_image)
|
38 |
+
prediction = mood.predict(pil_image)
|
39 |
+
# print(prediction)
|
40 |
+
text = prediction[0]
|
41 |
+
text_position = (x1 + w, y1 + w)
|
42 |
+
draw.rectangle([x1, y1, x2, y2], outline="red", width=w)
|
43 |
+
font = ImageFont.truetype("opensans.ttf", 5*w)
|
44 |
+
draw.text(text_position, text, fill="blue",font=font, stroke_width=int(w*0.2))
|
45 |
+
|
46 |
+
return image_with_boxes
|
47 |
+
|
48 |
+
|
49 |
+
|
50 |
+
# Sample images for user to choose from
|
51 |
+
sample_images = ["./sample_images/angry.jpg", "./sample_images/office.jpg","./sample_images/friends.jpg"]
|
52 |
+
|
53 |
+
iface = gr.Interface(
|
54 |
+
fn=process,
|
55 |
+
inputs=gr.Image(label="Select an image", type="filepath"),
|
56 |
+
outputs='image',
|
57 |
+
live=False,
|
58 |
+
title="Car image classifier",
|
59 |
+
description="Upload a car image or select one of the examples below",
|
60 |
+
examples=sample_images
|
61 |
+
)
|
62 |
+
|
63 |
+
|
64 |
+
iface.launch()
|
detection_training/F1_curve.png
ADDED
detection_training/PR_curve.png
ADDED
detection_training/P_curve.png
ADDED
detection_training/R_curve.png
ADDED
detection_training/args.yaml
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
task: detect
|
2 |
+
mode: train
|
3 |
+
model: /content/yolov8n.pt
|
4 |
+
data: data.yaml
|
5 |
+
epochs: 10
|
6 |
+
patience: 50
|
7 |
+
batch: 16
|
8 |
+
imgsz: 640
|
9 |
+
save: true
|
10 |
+
save_period: -1
|
11 |
+
cache: false
|
12 |
+
device: null
|
13 |
+
workers: 8
|
14 |
+
project: null
|
15 |
+
name: null
|
16 |
+
exist_ok: false
|
17 |
+
pretrained: true
|
18 |
+
optimizer: auto
|
19 |
+
verbose: true
|
20 |
+
seed: 0
|
21 |
+
deterministic: true
|
22 |
+
single_cls: false
|
23 |
+
rect: false
|
24 |
+
cos_lr: false
|
25 |
+
close_mosaic: 10
|
26 |
+
resume: false
|
27 |
+
amp: true
|
28 |
+
fraction: 1.0
|
29 |
+
profile: false
|
30 |
+
freeze: null
|
31 |
+
overlap_mask: true
|
32 |
+
mask_ratio: 4
|
33 |
+
dropout: 0.0
|
34 |
+
val: true
|
35 |
+
split: val
|
36 |
+
save_json: false
|
37 |
+
save_hybrid: false
|
38 |
+
conf: null
|
39 |
+
iou: 0.7
|
40 |
+
max_det: 300
|
41 |
+
half: false
|
42 |
+
dnn: false
|
43 |
+
plots: true
|
44 |
+
source: null
|
45 |
+
show: false
|
46 |
+
save_txt: false
|
47 |
+
save_conf: false
|
48 |
+
save_crop: false
|
49 |
+
show_labels: true
|
50 |
+
show_conf: true
|
51 |
+
vid_stride: 1
|
52 |
+
stream_buffer: false
|
53 |
+
line_width: null
|
54 |
+
visualize: false
|
55 |
+
augment: false
|
56 |
+
agnostic_nms: false
|
57 |
+
classes: null
|
58 |
+
retina_masks: false
|
59 |
+
boxes: true
|
60 |
+
format: torchscript
|
61 |
+
keras: false
|
62 |
+
optimize: false
|
63 |
+
int8: false
|
64 |
+
dynamic: false
|
65 |
+
simplify: false
|
66 |
+
opset: null
|
67 |
+
workspace: 4
|
68 |
+
nms: false
|
69 |
+
lr0: 0.01
|
70 |
+
lrf: 0.01
|
71 |
+
momentum: 0.937
|
72 |
+
weight_decay: 0.0005
|
73 |
+
warmup_epochs: 3.0
|
74 |
+
warmup_momentum: 0.8
|
75 |
+
warmup_bias_lr: 0.1
|
76 |
+
box: 7.5
|
77 |
+
cls: 0.5
|
78 |
+
dfl: 1.5
|
79 |
+
pose: 12.0
|
80 |
+
kobj: 1.0
|
81 |
+
label_smoothing: 0.0
|
82 |
+
nbs: 64
|
83 |
+
hsv_h: 0.015
|
84 |
+
hsv_s: 0.7
|
85 |
+
hsv_v: 0.4
|
86 |
+
degrees: 0.0
|
87 |
+
translate: 0.1
|
88 |
+
scale: 0.5
|
89 |
+
shear: 0.0
|
90 |
+
perspective: 0.0
|
91 |
+
flipud: 0.0
|
92 |
+
fliplr: 0.5
|
93 |
+
mosaic: 1.0
|
94 |
+
mixup: 0.0
|
95 |
+
copy_paste: 0.0
|
96 |
+
cfg: null
|
97 |
+
tracker: botsort.yaml
|
98 |
+
save_dir: runs/detect/train
|
detection_training/confusion_matrix.png
ADDED
detection_training/confusion_matrix_normalized.png
ADDED
detection_training/events.out.tfevents.1723263798.193db2adeb1d.880.0
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:06ef3b5738e6e03fabbeeaffd52c51add19dacf657d7aedf9d546d5c1aa1b2b9
|
3 |
+
size 1573123
|
detection_training/labels.jpg
ADDED
detection_training/labels_correlogram.jpg
ADDED
detection_training/results.csv
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
epoch, train/box_loss, train/cls_loss, train/dfl_loss, metrics/precision(B), metrics/recall(B), metrics/mAP50(B), metrics/mAP50-95(B), val/box_loss, val/cls_loss, val/dfl_loss, lr/pg0, lr/pg1, lr/pg2
|
2 |
+
1, 2.1183, 1.8345, 1.3011, 0.69467, 0.37721, 0.4271, 0.21054, 1.7273, 1.0806, 1.0973, 0.00066584, 0.00066584, 0.00066584
|
3 |
+
2, 1.7519, 1.101, 1.0979, 0.72355, 0.39829, 0.4639, 0.23574, 1.673, 0.99172, 1.0819, 0.0012006, 0.0012006, 0.0012006
|
4 |
+
3, 1.6888, 1.0075, 1.0722, 0.7492, 0.45081, 0.51379, 0.25759, 1.5915, 0.90528, 1.0444, 0.0016033, 0.0016033, 0.0016033
|
5 |
+
4, 1.6409, 0.95279, 1.0577, 0.76166, 0.45202, 0.52456, 0.26817, 1.5833, 0.87973, 1.0401, 0.001406, 0.001406, 0.001406
|
6 |
+
5, 1.6188, 0.92058, 1.0471, 0.76386, 0.46059, 0.53145, 0.27005, 1.5789, 0.84541, 1.0448, 0.001406, 0.001406, 0.001406
|
7 |
+
6, 1.5884, 0.88101, 1.0381, 0.77804, 0.46672, 0.54119, 0.28155, 1.5531, 0.81778, 1.0327, 0.001208, 0.001208, 0.001208
|
8 |
+
7, 1.5645, 0.85025, 1.0288, 0.78715, 0.48032, 0.54812, 0.28519, 1.5269, 0.79034, 1.0252, 0.00101, 0.00101, 0.00101
|
9 |
+
8, 1.5436, 0.82403, 1.0207, 0.79692, 0.48759, 0.56661, 0.29809, 1.4967, 0.77194, 1.015, 0.000812, 0.000812, 0.000812
|
10 |
+
9, 1.5233, 0.80503, 1.0121, 0.79457, 0.50006, 0.5688, 0.29073, 1.5153, 0.76072, 1.016, 0.000614, 0.000614, 0.000614
|
11 |
+
10, 1.5007, 0.77753, 1.0083, 0.79893, 0.50977, 0.58571, 0.31009, 1.4566, 0.72831, 1.0044, 0.000416, 0.000416, 0.000416
|
detection_training/results.png
ADDED
detection_training/train_batch0.jpg
ADDED
detection_training/train_batch1.jpg
ADDED
detection_training/train_batch2.jpg
ADDED
detection_training/val_batch0_labels.jpg
ADDED
detection_training/val_batch0_pred.jpg
ADDED
detection_training/val_batch1_labels.jpg
ADDED
detection_training/val_batch1_pred.jpg
ADDED
detection_training/val_batch2_labels.jpg
ADDED
detection_training/val_batch2_pred.jpg
ADDED
detection_training/weights/detect.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:87a78be86b01cee1f4e6642218f7d9082626e5969bf1df6e6a2e9968be2cdb6d
|
3 |
+
size 6222361
|
detection_training/weights/last.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c952a219e3f78a45ded51c454ab1879f487125226eee74a913f31724e93693da
|
3 |
+
size 6222361
|
faces_classifier.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
faces_detector.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
faces_prediction.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
models/detect.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:87a78be86b01cee1f4e6642218f7d9082626e5969bf1df6e6a2e9968be2cdb6d
|
3 |
+
size 6222361
|
models/mood.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1d0963a0d15945b85ab564847be3b8069222234e6fcde402a18039096386aaa3
|
3 |
+
size 88064574
|
mood_data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:51a51b17424ebf7552d356176b1c33c6919ca000deadae90c892d2f1d48c9a4f
|
3 |
+
size 63863343
|
opensans.ttf
ADDED
Binary file (530 kB). View file
|
|
requirements.txt.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
fastai==2.7.14
|
3 |
+
spacy==3.7.4
|
4 |
+
ultralytics
|
sample_images/angry.jpg
ADDED
sample_images/friends.jpg
ADDED
sample_images/office.jpg
ADDED