-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPythonImportHelper-v2-Completion.json
189 lines (189 loc) · 8.77 KB
/
PythonImportHelper-v2-Completion.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
[
{
"label": "AutoModel",
"importPath": "transformers",
"description": "transformers",
"isExtraImport": true,
"detail": "transformers",
"documentation": {}
},
{
"label": "AutoFeatureExtractor",
"importPath": "transformers",
"description": "transformers",
"isExtraImport": true,
"detail": "transformers",
"documentation": {}
},
{
"label": "AutoModel",
"importPath": "transformers",
"description": "transformers",
"isExtraImport": true,
"detail": "transformers",
"documentation": {}
},
{
"label": "AutoFeatureExtractor",
"importPath": "transformers",
"description": "transformers",
"isExtraImport": true,
"detail": "transformers",
"documentation": {}
},
{
"label": "Image",
"importPath": "PIL",
"description": "PIL",
"isExtraImport": true,
"detail": "PIL",
"documentation": {}
},
{
"label": "Image",
"importPath": "PIL",
"description": "PIL",
"isExtraImport": true,
"detail": "PIL",
"documentation": {}
},
{
"label": "ImageDraw",
"importPath": "PIL",
"description": "PIL",
"isExtraImport": true,
"detail": "PIL",
"documentation": {}
},
{
"label": "ImageFont",
"importPath": "PIL",
"description": "PIL",
"isExtraImport": true,
"detail": "PIL",
"documentation": {}
},
{
"label": "cv2",
"kind": 6,
"isExtraImport": true,
"importPath": "cv2",
"description": "cv2",
"detail": "cv2",
"documentation": {}
},
{
"label": "numpy",
"kind": 6,
"isExtraImport": true,
"importPath": "numpy",
"description": "numpy",
"detail": "numpy",
"documentation": {}
},
{
"label": "cosine",
"importPath": "scipy.spatial.distance",
"description": "scipy.spatial.distance",
"isExtraImport": true,
"detail": "scipy.spatial.distance",
"documentation": {}
},
{
"label": "cosine",
"importPath": "scipy.spatial.distance",
"description": "scipy.spatial.distance",
"isExtraImport": true,
"detail": "scipy.spatial.distance",
"documentation": {}
},
{
"label": "DeepFace",
"importPath": "deepface",
"description": "deepface",
"isExtraImport": true,
"detail": "deepface",
"documentation": {}
},
{
"label": "load_model",
"kind": 2,
"importPath": "main",
"description": "main",
"peekOfCode": "def load_model():\n \"\"\"\n Hugging Face modelini yuklaydi va qaytaradi.\n \"\"\"\n model_name = \"jayanta/vit-base-patch16-224-in21k-face-recognition\"\n print(\"Model yuklanmoqda...\")\n model = AutoModel.from_pretrained(model_name)\n feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)\n print(\"Model muvaffaqiyatli yuklandi.\")\n return model, feature_extractor",
"detail": "main",
"documentation": {}
},
{
"label": "get_face_embedding",
"kind": 2,
"importPath": "main",
"description": "main",
"peekOfCode": "def get_face_embedding(model, feature_extractor, image):\n \"\"\"\n Tasvirdan yuz embeddinglarini oladi.\n :param model: Yuklangan Hugging Face modeli\n :param feature_extractor: Yuklangan extractor\n :param image: Tasvir (numpy array)\n :return: Yuz embeddinglari (vektorlar)\n \"\"\"\n try:\n pil_image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) # OpenCV formatdan PIL formatga o'tkazish",
"detail": "main",
"documentation": {}
},
{
"label": "calculate_similarity",
"kind": 2,
"importPath": "main",
"description": "main",
"peekOfCode": "def calculate_similarity(embedding1, embedding2):\n \"\"\"\n Ikki embedding orasidagi o'xshashlikni hisoblaydi.\n :param embedding1: Birinchi embedding\n :param embedding2: Ikkinchi embedding\n :return: O'xshashlik darajasi\n \"\"\"\n similarity = 1 - cosine(embedding1, embedding2)\n return similarity\n# === 4. Kameradan real vaqt rejimida yuzlarni tanib olish ===",
"detail": "main",
"documentation": {}
},
{
"label": "detect_and_compare_faces",
"kind": 2,
"importPath": "main",
"description": "main",
"peekOfCode": "def detect_and_compare_faces(model, feature_extractor, reference_embeddings):\n \"\"\"\n Kameradan yuzlarni o'qib, referens embedding bilan solishtiradi.\n :param model: Hugging Face modeli\n :param feature_extractor: Feature extractor\n :param reference_embeddings: Referens tasvir embeddinglari\n \"\"\"\n cap = cv2.VideoCapture(0) # Kamerani ochish\n print(\"Kameradan yuzlarni qidirishni boshlash. ESC tugmasini bosing chiqish uchun.\")\n natija_chiqarilgan = False # Natijalarni bir marta chiqarish uchun flag",
"detail": "main",
"documentation": {}
},
{
"label": "load_model",
"kind": 2,
"importPath": "main2",
"description": "main2",
"peekOfCode": "def load_model():\n model_name = \"jayanta/vit-base-patch16-224-in21k-face-recognition\"\n model = AutoModel.from_pretrained(model_name)\n feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)\n return model, feature_extractor\n# === 2. Yuz embeddinglarini olish ===\ndef get_face_embedding(model, feature_extractor, image):\n try:\n pil_image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n inputs = feature_extractor(images=pil_image, return_tensors=\"pt\")",
"detail": "main2",
"documentation": {}
},
{
"label": "get_face_embedding",
"kind": 2,
"importPath": "main2",
"description": "main2",
"peekOfCode": "def get_face_embedding(model, feature_extractor, image):\n try:\n pil_image = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))\n inputs = feature_extractor(images=pil_image, return_tensors=\"pt\")\n outputs = model(**inputs)\n embeddings = outputs.last_hidden_state.mean(dim=1).squeeze().detach().numpy()\n return embeddings\n except Exception as e:\n print(f\"Xatolik yuz berdi: {e}\")\n return None",
"detail": "main2",
"documentation": {}
},
{
"label": "detect_gender",
"kind": 2,
"importPath": "main2",
"description": "main2",
"peekOfCode": "def detect_gender(image):\n try:\n analysis = DeepFace.analyze(img_path=image, actions=['gender'])\n return analysis['gender']\n except Exception as e:\n print(f\"Jinsni aniqlashda xatolik yuz berdi: {e}\")\n return \"Unknown\"\n# === 4. Kameradan real vaqt rejimida yuzlarni aniqlash ===\ndef detect_and_compare_faces(model, feature_extractor, reference_embeddings, reference_names, font_path):\n cap = cv2.VideoCapture(0)",
"detail": "main2",
"documentation": {}
},
{
"label": "detect_and_compare_faces",
"kind": 2,
"importPath": "main2",
"description": "main2",
"peekOfCode": "def detect_and_compare_faces(model, feature_extractor, reference_embeddings, reference_names, font_path):\n cap = cv2.VideoCapture(0)\n while True:\n ret, frame = cap.read()\n if not ret:\n break\n gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)\n face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + \"haarcascade_frontalface_default.xml\")\n faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=7, minSize=(100, 100))\n for (x, y, w, h) in faces:",
"detail": "main2",
"documentation": {}
},
{
"label": "calculate_similarity",
"kind": 2,
"importPath": "main2",
"description": "main2",
"peekOfCode": "def calculate_similarity(embedding1, embedding2):\n return 1 - cosine(embedding1, embedding2)\n# === 6. Asosiy kodni ishga tushirish ===\nif __name__ == \"__main__\":\n model, feature_extractor = load_model()\n reference_images = [\n r\"C:\\Users\\13\\Desktop\\face_recog\\Camera Roll\\WIN_20250110_15_56_44_Pro.jpg\",\n r\"C:\\Users\\13\\Desktop\\face_recog\\Camera Roll\\WIN_20250110_15_57_58_Pro.jpg\",\n r\"C:\\Users\\13\\Desktop\\face_recog\\Camera Roll\\WIN_20250110_15_58_15_Pro.jpg\",\n r\"C:\\Users\\13\\Desktop\\face_recog\\Camera Roll\\WIN_20250110_15_58_29_Pro.jpg\",",
"detail": "main2",
"documentation": {}
}
]