Spaces:
Running
Running
Zai
commited on
Commit
·
dbdb9fd
1
Parent(s):
c980322
streamlit working
Browse files- __pycache__/sampling.cpython-310.pyc +0 -0
- headshot/__init__.py +2 -0
- headshot/__pycache__/__init__.cpython-310.pyc +0 -0
- headshot/__pycache__/config.cpython-310.pyc +0 -0
- headshot/__pycache__/data_prep.cpython-310.pyc +0 -0
- headshot/__pycache__/headshot.cpython-310.pyc +0 -0
- headshot/config.py +6 -0
- headshot/data_prep.py +5 -2
- headshot/headshot.py +2 -2
- sampling.py +28 -0
- interface/app.py → space.py +12 -28
- training.py +15 -1
__pycache__/sampling.cpython-310.pyc
ADDED
Binary file (651 Bytes). View file
|
|
headshot/__init__.py
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
from headshot.headshot import Headshot
|
2 |
+
from .config import Config
|
headshot/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (256 Bytes). View file
|
|
headshot/__pycache__/config.cpython-310.pyc
ADDED
Binary file (462 Bytes). View file
|
|
headshot/__pycache__/data_prep.cpython-310.pyc
ADDED
Binary file (1.09 kB). View file
|
|
headshot/__pycache__/headshot.cpython-310.pyc
ADDED
Binary file (1.91 kB). View file
|
|
headshot/config.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class Config:
|
2 |
+
def __init__(self) -> None:
|
3 |
+
pass
|
4 |
+
|
5 |
+
|
6 |
+
config = Config()
|
headshot/data_prep.py
CHANGED
@@ -5,12 +5,15 @@ from datasets import load_dataset
|
|
5 |
|
6 |
data_url = ''
|
7 |
|
|
|
|
|
|
|
8 |
class FaceDataset(Dataset):
|
9 |
-
def __init__(self
|
10 |
self.tranforms = transforms.Compose([
|
11 |
|
12 |
])
|
13 |
-
self.data =
|
14 |
self.labels = labels
|
15 |
|
16 |
def __len__(self):
|
|
|
5 |
|
6 |
data_url = ''
|
7 |
|
8 |
+
datas = None
|
9 |
+
labels = None
|
10 |
+
|
11 |
class FaceDataset(Dataset):
|
12 |
+
def __init__(self):
|
13 |
self.tranforms = transforms.Compose([
|
14 |
|
15 |
])
|
16 |
+
self.data = datas
|
17 |
self.labels = labels
|
18 |
|
19 |
def __len__(self):
|
headshot/headshot.py
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
import torch
|
2 |
from torch import nn
|
3 |
-
from data_prep import FaceDataset
|
4 |
|
5 |
class Headshot(nn.Module):
|
6 |
def __init__(self,num_epoch=20,lr=0.02):
|
7 |
super().__init__()
|
8 |
-
self.dataset = FaceDataset()
|
9 |
self.num_epoch = num_epoch
|
10 |
self.lr = lr
|
11 |
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
|
1 |
import torch
|
2 |
from torch import nn
|
3 |
+
from .data_prep import FaceDataset
|
4 |
|
5 |
class Headshot(nn.Module):
|
6 |
def __init__(self,num_epoch=20,lr=0.02):
|
7 |
super().__init__()
|
8 |
+
# self.dataset = FaceDataset()
|
9 |
self.num_epoch = num_epoch
|
10 |
self.lr = lr
|
11 |
self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
sampling.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from headshot import Headshot
|
3 |
+
from headshot import config
|
4 |
+
|
5 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
6 |
+
|
7 |
+
model = Headshot().to(device)
|
8 |
+
|
9 |
+
pretrained = None
|
10 |
+
|
11 |
+
if pretrained:
|
12 |
+
model_path = ''
|
13 |
+
pass
|
14 |
+
|
15 |
+
else:
|
16 |
+
model_path = ''
|
17 |
+
pass
|
18 |
+
|
19 |
+
model.load_state_dict(model_path)
|
20 |
+
|
21 |
+
def sample():
|
22 |
+
image_path = './interface/images/demo.jpg'
|
23 |
+
|
24 |
+
prediction,image = model.predict_image(image_path)
|
25 |
+
|
26 |
+
print(f"Prediction ->{prediction}")
|
27 |
+
|
28 |
+
return prediction,image
|
interface/app.py → space.py
RENAMED
@@ -1,47 +1,31 @@
|
|
1 |
-
import
|
2 |
import streamlit as st
|
3 |
-
from
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
|
7 |
-
|
8 |
-
def detect_faces(image):
|
9 |
-
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
10 |
-
|
11 |
-
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
12 |
-
|
13 |
-
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
|
14 |
-
|
15 |
-
for (x, y, w, h) in faces:
|
16 |
-
cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 2)
|
17 |
-
|
18 |
-
return image
|
19 |
|
20 |
def main():
|
21 |
st.title("Headshot simulator")
|
22 |
|
23 |
-
video_source = st.sidebar.radio("Select video source:", ("Webcam", "Upload"))
|
24 |
|
25 |
if video_source == "Webcam":
|
26 |
-
|
|
|
|
|
|
|
|
|
27 |
else:
|
28 |
uploaded_file = st.sidebar.file_uploader("Choose a video file", type=["mp4", "avi"])
|
29 |
if uploaded_file is not None:
|
30 |
file_bytes = uploaded_file.read()
|
31 |
-
cap = cv2.VideoCapture(file_bytes)
|
32 |
-
|
33 |
-
if "cap" in locals():
|
34 |
-
while cap.isOpened():
|
35 |
-
ret, frame = cap.read()
|
36 |
-
|
37 |
-
if not ret:
|
38 |
-
break
|
39 |
-
|
40 |
-
frame_with_faces = detect_faces(frame)
|
41 |
|
42 |
-
st.image(frame_with_faces, channels="BGR", use_column_width=True)
|
43 |
|
44 |
-
cap.release()
|
45 |
|
46 |
if __name__ == "__main__":
|
47 |
main()
|
|
|
1 |
+
import torch
|
2 |
import streamlit as st
|
3 |
+
# from .detector import detect_faces
|
4 |
+
from headshot import Headshot
|
5 |
|
6 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
7 |
|
8 |
+
model = Headshot()
|
9 |
|
10 |
+
# model.load_pretrain('')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
def main():
|
13 |
st.title("Headshot simulator")
|
14 |
|
15 |
+
video_source = st.sidebar.radio("Select video source:", ("Webcam", "Upload","Demo"))
|
16 |
|
17 |
if video_source == "Webcam":
|
18 |
+
pass
|
19 |
+
|
20 |
+
elif video_source == "Demo":
|
21 |
+
# prediction,image = sample()
|
22 |
+
pass
|
23 |
else:
|
24 |
uploaded_file = st.sidebar.file_uploader("Choose a video file", type=["mp4", "avi"])
|
25 |
if uploaded_file is not None:
|
26 |
file_bytes = uploaded_file.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
28 |
|
|
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
main()
|
training.py
CHANGED
@@ -1,2 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
1 |
num_epochs = 30
|
2 |
-
out_dir = 'out'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from headshot import Headshot
|
3 |
+
from headshot import config
|
4 |
+
|
5 |
+
|
6 |
num_epochs = 30
|
7 |
+
out_dir = 'out'
|
8 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
|
13 |
+
|
14 |
+
model = Headshot().to(device)
|
15 |
+
|
16 |
+
model.train()
|