Update README.md
Browse files
README.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
---
|
5 |
|
6 |
# Classificador de Dor em Vídeo
|
@@ -15,7 +28,68 @@ Este modelo foi treinado para classificar vídeos de expressões faciais em trê
|
|
15 |
|
16 |
O modelo é baseado no [VideoMAE](https://huggingface.co/MCG-NJU/videomae-base) (Video Masked Autoencoder) e foi refinado (fine-tuned) especificamente para detectar e classificar níveis de dor a partir de vídeos de expressões faciais.
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
## Detalhes do Treinamento
|
21 |
|
|
|
1 |
---
|
2 |
library_name: transformers
|
3 |
+
tags:
|
4 |
+
- video-classification
|
5 |
+
- videomae
|
6 |
+
- medical
|
7 |
+
- pain-assessment
|
8 |
+
- healthcare
|
9 |
+
- computer-vision
|
10 |
+
- pytorch
|
11 |
+
metrics:
|
12 |
+
- f1
|
13 |
+
- accuracy
|
14 |
+
- recall
|
15 |
+
- confusion_matrix
|
16 |
+
- precision
|
17 |
---
|
18 |
|
19 |
# Classificador de Dor em Vídeo
|
|
|
28 |
|
29 |
O modelo é baseado no [VideoMAE](https://huggingface.co/MCG-NJU/videomae-base) (Video Masked Autoencoder) e foi refinado (fine-tuned) especificamente para detectar e classificar níveis de dor a partir de vídeos de expressões faciais.
|
30 |
|
31 |
+
## Exemplo de uso
|
32 |
+
```python
|
33 |
+
import os
|
34 |
+
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
|
35 |
+
|
36 |
+
|
37 |
+
from transformers import VideoMAEImageProcessor, AutoModelForVideoClassification
|
38 |
+
import torch
|
39 |
+
import numpy as np
|
40 |
+
import av
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
def extract_frames(video_path, num_frames=16):
|
45 |
+
frames = []
|
46 |
+
try:
|
47 |
+
container = av.open(video_path)
|
48 |
+
stream = container.streams.video[0]
|
49 |
+
indices = np.linspace(0, stream.frames - 1, num=num_frames, dtype=int)
|
50 |
+
|
51 |
+
for i, frame in enumerate(container.decode(stream)):
|
52 |
+
if i in indices:
|
53 |
+
img = frame.to_ndarray(format="rgb24")
|
54 |
+
frames.append(img)
|
55 |
+
if len(frames) == num_frames:
|
56 |
+
break
|
57 |
+
|
58 |
+
container.close()
|
59 |
+
except Exception as e:
|
60 |
+
print(f"Erro ao processar o vídeo: {e}")
|
61 |
+
|
62 |
+
if len(frames) < num_frames:
|
63 |
+
pad_size = num_frames - len(frames)
|
64 |
+
if frames:
|
65 |
+
last_frame = frames[-1]
|
66 |
+
frames += [last_frame.copy() for _ in range(pad_size)]
|
67 |
+
else:
|
68 |
+
frames = [np.zeros((224, 224, 3), dtype=np.uint8)] * num_frames
|
69 |
+
|
70 |
+
return frames
|
71 |
+
|
72 |
+
processor = VideoMAEImageProcessor.from_pretrained("maike616/pain-classifier-video")
|
73 |
+
model = AutoModelForVideoClassification.from_pretrained("maike616/pain-classifier-video")
|
74 |
+
|
75 |
+
high = r'AI4Pain Dataset\Validation\video\high_pain\1_Pain_HIGH_20.mp4'
|
76 |
+
low = r'AI4Pain Dataset\Validation\video\low_pain\1_Pain_LOW_3.mp4'
|
77 |
+
no_pain = r'AI4Pain Dataset\Validation\video\no_pain\1_Rest_1.mp4'
|
78 |
+
|
79 |
+
video_frames = extract_frames(no_pain)
|
80 |
+
|
81 |
+
inputs = processor(video_frames, return_tensors="pt")
|
82 |
+
|
83 |
+
with torch.no_grad():
|
84 |
+
outputs = model(**inputs)
|
85 |
+
probs = torch.softmax(outputs.logits, dim=1)
|
86 |
+
predicted_class_idx = outputs.logits.argmax(-1).item()
|
87 |
+
predicted_class = model.config.id2label[predicted_class_idx]
|
88 |
+
|
89 |
+
print(f"Classe predita: {predicted_class}")
|
90 |
+
print(f"Probabilidades: {probs[0].tolist()}")
|
91 |
+
|
92 |
+
```
|
93 |
|
94 |
## Detalhes do Treinamento
|
95 |
|