NurzatS commited on
Commit
5bcd410
·
verified ·
1 Parent(s): b805b46

Upload 7 files

Browse files
best_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7a10d56e8da9c72b0531088816c554fd4b52646aa96da7ce2d2e8c03ad80526f
3
+ size 44794379
categories.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "smartphone": {
3
+ "asaxiy": "https://asaxiy.uz/product/telefony-i-gadzhety/telefony/smartfony",
4
+ "texnomart": "https://texnomart.uz/ru/katalog/smartfony/",
5
+ "olcha": "https://olcha.uz/ru/category/telefony-gadzhety-aksessuary/telefony"
6
+ },
7
+ "laptop": {
8
+ "asaxiy": "https://asaxiy.uz/product/kompyutery-i-orgtehnika/noutbuki/noutbuki-2",
9
+ "texnomart": "https://texnomart.uz/ru/katalog/noutbuki/",
10
+ "olcha": "https://olcha.uz/ru/category/noutbuki-planshety-kompyutery/noutbuki"
11
+ },
12
+ "tv": {
13
+ "asaxiy": "https://asaxiy.uz/product/televizory-video-i-audio/televizory",
14
+ "texnomart": "https://texnomart.uz/ru/katalog/televizory/",
15
+ "olcha": "https://olcha.uz/ru/category/televizory-audio-i-videotekhnika/televizory"
16
+ },
17
+ "refrigerator": {
18
+ "asaxiy": "https://asaxiy.uz/product/bytovaya-tehnika/krupnaya-tehnika-dlya-kuhni/holodilniki",
19
+ "texnomart": "https://texnomart.uz/ru/katalog/holodilniki/",
20
+ "olcha": "https://olcha.uz/ru/category/tekhnika-dlya-kukhni/krupnaya-kukhonnaya-tekhnika/kholodilniki-i-morozilnye-kamery-1"
21
+ },
22
+ "headphones": {
23
+ "asaxiy": "https://asaxiy.uz/product/telefony-i-gadzhety/naushniki-i-auditexniki/besprovodniye-naushniki",
24
+ "texnomart": "https://texnomart.uz/ru/katalog/naushniki",
25
+ "olcha": "https://olcha.uz/ru/category/telefony-gadzhety-aksessuary/aksessuary/garnitury"
26
+ }
27
+ }
config.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "google/vit-base-patch16-224-in21k",
3
+ "architectures": [
4
+ "ViTForImageClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.0,
7
+ "encoder_stride": 16,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.0,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "headphones",
13
+ "1": "laptop",
14
+ "2": "smartphone",
15
+ "3": "tv",
16
+ "4": "watch"
17
+ },
18
+ "image_size": 224,
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 3072,
21
+ "label2id": {
22
+ "headphones": "0",
23
+ "laptop": "1",
24
+ "smartphone": "2",
25
+ "tv": "3",
26
+ "watch": "4"
27
+ },
28
+ "layer_norm_eps": 1e-12,
29
+ "model_type": "vit",
30
+ "num_attention_heads": 12,
31
+ "num_channels": 3,
32
+ "num_hidden_layers": 12,
33
+ "patch_size": 16,
34
+ "problem_type": "single_label_classification",
35
+ "qkv_bias": true,
36
+ "torch_dtype": "float32",
37
+ "transformers_version": "4.46.3"
38
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:91a33a308ad342631146ff9e6491891f9042b2cc9142991aac8c712a93c63534
3
+ size 343233204
predict.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Инференс через дообученный google/vit-base-patch16-224-in21k.
3
+ """
4
+
5
+ import sys
6
+ from pathlib import Path
7
+
8
+ import torch
9
+ from PIL import Image
10
+ from transformers import ViTForImageClassification, ViTImageProcessor
11
+
12
+ BASE_DIR = Path(__file__).resolve().parent
13
+ MODEL_DIR = BASE_DIR / "models" / "vit-product-classifier"
14
+ DEVICE = torch.device("cuda" if torch.cuda.is_available() else "cpu")
15
+
16
+
17
+ def predict(img_path: str):
18
+ if not MODEL_DIR.exists():
19
+ print(f"Ошибка: папка модели {MODEL_DIR} не найдена. Сначала запусти train.py!")
20
+ return
21
+
22
+ processor = ViTImageProcessor.from_pretrained(str(MODEL_DIR))
23
+ model = ViTForImageClassification.from_pretrained(str(MODEL_DIR)).to(DEVICE).eval()
24
+
25
+ image = Image.open(img_path).convert("RGB")
26
+ inputs = processor(images=image, return_tensors="pt").to(DEVICE)
27
+
28
+ with torch.no_grad():
29
+ outputs = model(**inputs)
30
+ probs = torch.softmax(outputs.logits, dim=1)[0]
31
+ top_prob, top_class_idx = torch.max(probs, 0)
32
+
33
+ class_name = model.config.id2label[top_class_idx.item()]
34
+ print(f"\nИзображение: {img_path}")
35
+ print(f"Предсказание: {class_name} ({top_prob.item() * 100:.2f}%)")
36
+
37
+
38
+ if __name__ == "__main__":
39
+ if len(sys.argv) > 1:
40
+ predict(sys.argv[1])
41
+ else:
42
+ print("Использование: python predict.py <путь_к_картинке>")
preprocessor_config.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "do_normalize": true,
3
+ "do_rescale": true,
4
+ "do_resize": true,
5
+ "image_mean": [
6
+ 0.5,
7
+ 0.5,
8
+ 0.5
9
+ ],
10
+ "image_processor_type": "ViTImageProcessor",
11
+ "image_std": [
12
+ 0.5,
13
+ 0.5,
14
+ 0.5
15
+ ],
16
+ "resample": 2,
17
+ "rescale_factor": 0.00392156862745098,
18
+ "size": {
19
+ "height": 224,
20
+ "width": 224
21
+ }
22
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec41433b3fa38bffbabc5bba4ca50e3370410041b7fe5280a427a34e47d8be0a
3
+ size 5713