Marcus Vinicius Zerbini Canhaço
commited on
Commit
·
2dfae6f
1
Parent(s):
9baead7
feat: atualização do detector com otimizações para GPU T4
Browse files- Dockerfile +6 -7
- deploy.sh +32 -45
- src/domain/detectors/cpu.py +1 -1
- src/domain/detectors/gpu.py +2 -1
Dockerfile
CHANGED
@@ -36,23 +36,22 @@ RUN pip install --no-cache-dir -U pip setuptools wheel && \
|
|
36 |
pip install --no-cache-dir --upgrade "tokenizers>=0.15.0" && \
|
37 |
pip install --no-cache-dir --upgrade "git+https://github.com/huggingface/transformers.git"
|
38 |
|
39 |
-
# Criar diretório de vídeos
|
40 |
-
RUN mkdir -p /code/videos
|
41 |
-
chmod -R 777 /code/.cache /code/videos
|
42 |
|
43 |
# Configurar variáveis de ambiente
|
44 |
ENV HOST=0.0.0.0 \
|
45 |
PORT=7860 \
|
46 |
PYTHONUNBUFFERED=1 \
|
47 |
PYTHONPATH=/code \
|
48 |
-
TRANSFORMERS_CACHE=/
|
49 |
-
TORCH_HOME=/
|
50 |
GRADIO_SERVER_NAME=0.0.0.0 \
|
51 |
GRADIO_SERVER_PORT=7860 \
|
52 |
SYSTEM=spaces \
|
53 |
CUDA_VISIBLE_DEVICES=0 \
|
54 |
-
HUGGINGFACE_HUB_CACHE=/
|
55 |
-
HF_HOME=/
|
56 |
TORCH_CUDA_ARCH_LIST="7.5" \
|
57 |
MAX_WORKERS=2 \
|
58 |
TRANSFORMERS_OFFLINE=0 \
|
|
|
36 |
pip install --no-cache-dir --upgrade "tokenizers>=0.15.0" && \
|
37 |
pip install --no-cache-dir --upgrade "git+https://github.com/huggingface/transformers.git"
|
38 |
|
39 |
+
# Criar diretório de vídeos
|
40 |
+
RUN mkdir -p /code/videos && chmod -R 777 /code/videos
|
|
|
41 |
|
42 |
# Configurar variáveis de ambiente
|
43 |
ENV HOST=0.0.0.0 \
|
44 |
PORT=7860 \
|
45 |
PYTHONUNBUFFERED=1 \
|
46 |
PYTHONPATH=/code \
|
47 |
+
TRANSFORMERS_CACHE=/tmp/huggingface \
|
48 |
+
TORCH_HOME=/tmp/torch \
|
49 |
GRADIO_SERVER_NAME=0.0.0.0 \
|
50 |
GRADIO_SERVER_PORT=7860 \
|
51 |
SYSTEM=spaces \
|
52 |
CUDA_VISIBLE_DEVICES=0 \
|
53 |
+
HUGGINGFACE_HUB_CACHE=/tmp/huggingface \
|
54 |
+
HF_HOME=/tmp/huggingface \
|
55 |
TORCH_CUDA_ARCH_LIST="7.5" \
|
56 |
MAX_WORKERS=2 \
|
57 |
TRANSFORMERS_OFFLINE=0 \
|
deploy.sh
CHANGED
@@ -18,25 +18,18 @@ echo "🚀 Preparando deploy para GitHub..."
|
|
18 |
echo "📦 Adicionando arquivos para GitHub..."
|
19 |
git add .
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
echo "
|
30 |
-
git push -f origin main
|
31 |
-
|
32 |
-
if [ $? -eq 0 ]; then
|
33 |
-
echo "✅ Deploy para GitHub concluído com sucesso!"
|
34 |
-
else
|
35 |
-
echo "❌ Erro durante o deploy para GitHub"
|
36 |
-
exit 1
|
37 |
-
fi
|
38 |
else
|
39 |
-
echo "
|
|
|
40 |
fi
|
41 |
|
42 |
# Deploy para Hugging Face
|
@@ -54,32 +47,26 @@ fi
|
|
54 |
echo "📦 Adicionando todos os arquivos..."
|
55 |
git add --all
|
56 |
|
57 |
-
#
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
echo " - NOTIFICATION_EMAIL"
|
77 |
-
echo " - SENDGRID_API_KEY"
|
78 |
-
echo " 3. Os requisitos de memória estão adequados"
|
79 |
-
else
|
80 |
-
echo "❌ Erro durante o deploy para Hugging Face"
|
81 |
-
exit 1
|
82 |
-
fi
|
83 |
else
|
84 |
-
echo "
|
|
|
85 |
fi
|
|
|
18 |
echo "📦 Adicionando arquivos para GitHub..."
|
19 |
git add .
|
20 |
|
21 |
+
# Fazer commit
|
22 |
+
git commit -m "$commit_message"
|
23 |
+
|
24 |
+
# Force push para GitHub
|
25 |
+
echo "🚀 Forçando push para GitHub..."
|
26 |
+
git push -f origin main
|
27 |
+
|
28 |
+
if [ $? -eq 0 ]; then
|
29 |
+
echo "✅ Deploy para GitHub concluído com sucesso!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
else
|
31 |
+
echo "❌ Erro durante o deploy para GitHub"
|
32 |
+
exit 1
|
33 |
fi
|
34 |
|
35 |
# Deploy para Hugging Face
|
|
|
47 |
echo "📦 Adicionando todos os arquivos..."
|
48 |
git add --all
|
49 |
|
50 |
+
# Fazer commit
|
51 |
+
git commit -m "$commit_message"
|
52 |
+
|
53 |
+
# Force push para Hugging Face
|
54 |
+
echo "🚀 Enviando para Hugging Face Space..."
|
55 |
+
git push -f space main
|
56 |
+
|
57 |
+
if [ $? -eq 0 ]; then
|
58 |
+
echo "✅ Deploy para Hugging Face concluído com sucesso!"
|
59 |
+
echo "🌐 Seu app estará disponível em alguns minutos em:"
|
60 |
+
echo " https://huggingface.co/spaces/marcuscanhaco/weapon-detection-app"
|
61 |
+
echo ""
|
62 |
+
echo "⚠️ Lembre-se de verificar no Hugging Face Space se:"
|
63 |
+
echo " 1. O Space está configurado para usar GPU T4"
|
64 |
+
echo " 2. As variáveis de ambiente estão configuradas corretamente:"
|
65 |
+
echo " - HUGGING_FACE_TOKEN"
|
66 |
+
echo " - NOTIFICATION_EMAIL"
|
67 |
+
echo " - SENDGRID_API_KEY"
|
68 |
+
echo " 3. Os requisitos de memória estão adequados"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
else
|
70 |
+
echo "❌ Erro durante o deploy para Hugging Face"
|
71 |
+
exit 1
|
72 |
fi
|
src/domain/detectors/cpu.py
CHANGED
@@ -60,7 +60,7 @@ class WeaponDetectorCPU(BaseDetector):
|
|
60 |
torch.set_num_interop_threads(min(8, os.cpu_count()))
|
61 |
|
62 |
# Carregar modelo com configurações otimizadas
|
63 |
-
cache_dir = os.
|
64 |
os.makedirs(cache_dir, exist_ok=True)
|
65 |
|
66 |
model_name = "google/owlv2-base-patch16"
|
|
|
60 |
torch.set_num_interop_threads(min(8, os.cpu_count()))
|
61 |
|
62 |
# Carregar modelo com configurações otimizadas
|
63 |
+
cache_dir = os.path.join(tempfile.gettempdir(), 'weapon_detection_cache')
|
64 |
os.makedirs(cache_dir, exist_ok=True)
|
65 |
|
66 |
model_name = "google/owlv2-base-patch16"
|
src/domain/detectors/gpu.py
CHANGED
@@ -10,6 +10,7 @@ import cv2
|
|
10 |
from PIL import Image
|
11 |
from transformers import Owlv2Processor, Owlv2ForObjectDetection
|
12 |
from .base import BaseDetector, BaseCache
|
|
|
13 |
|
14 |
logger = logging.getLogger(__name__)
|
15 |
|
@@ -48,7 +49,7 @@ class WeaponDetectorGPU(BaseDetector):
|
|
48 |
self.device = self._get_best_device()
|
49 |
|
50 |
# Diretório de cache para o modelo
|
51 |
-
cache_dir = os.
|
52 |
os.makedirs(cache_dir, exist_ok=True)
|
53 |
|
54 |
# Limpar memória GPU
|
|
|
10 |
from PIL import Image
|
11 |
from transformers import Owlv2Processor, Owlv2ForObjectDetection
|
12 |
from .base import BaseDetector, BaseCache
|
13 |
+
import tempfile
|
14 |
|
15 |
logger = logging.getLogger(__name__)
|
16 |
|
|
|
49 |
self.device = self._get_best_device()
|
50 |
|
51 |
# Diretório de cache para o modelo
|
52 |
+
cache_dir = os.path.join(tempfile.gettempdir(), 'weapon_detection_cache')
|
53 |
os.makedirs(cache_dir, exist_ok=True)
|
54 |
|
55 |
# Limpar memória GPU
|