Arko007 commited on
Commit
579ed70
·
verified ·
1 Parent(s): f0d8f61

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +110 -0
README.md ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ tags:
6
+ - image-classification
7
+ - walnut
8
+ - defect-detection
9
+ - efficientnet
10
+ - timm
11
+ - pytorch
12
+ - surface-defect
13
+ - quality-control
14
+ pipeline_tag: image-classification
15
+ library_name: timm
16
+ base_model: timm/efficientnet_b3.ra2_in1k
17
+ metrics:
18
+ - accuracy
19
+ - f1
20
+ model-index:
21
+ - name: Walnut Shell Defect Classifier
22
+ results:
23
+ - task:
24
+ type: image-classification
25
+ name: Image Classification
26
+ dataset:
27
+ name: Nut Surface Defect Dataset (nutsv2ifolder_split)
28
+ type: weihaoreal/nut-surface-defect-dataset
29
+ metrics:
30
+ - type: accuracy
31
+ value: 0.9855
32
+ name: Validation Accuracy
33
+ - type: f1
34
+ value: 0.98
35
+ name: Macro F1
36
+ ---
37
+
38
+ # Walnut Shell Defect Classifier
39
+
40
+ EfficientNet-B3 finetuned for walnut shell defect classification across 4 categories.
41
+ Trained on the Nut Surface Defect Dataset with class remapping to match walnut-specific defect taxonomy.
42
+
43
+ ## Classes
44
+
45
+ | Output Label | Remapped From (Dataset) |
46
+ |---|---|
47
+ | Healthy | Excellent |
48
+ | Black Spot | Rusting |
49
+ | Shriveled | Scratches |
50
+ | Damaged | Deformation + Fracture |
51
+
52
+ ## Metrics (Epoch 8 — Best Checkpoint)
53
+
54
+ | Class | Precision | Recall | F1 |
55
+ |---|---|---|---|
56
+ | Healthy | 0.88 | 1.00 | 0.93 |
57
+ | Black Spot | 1.00 | 0.99 | 1.00 |
58
+ | Shriveled | 1.00 | 0.98 | 0.99 |
59
+ | Damaged | 1.00 | 0.98 | 0.99 |
60
+ | **Macro Avg** | **0.97** | **0.99** | **0.98** |
61
+ | **Weighted Avg** | **0.99** | **0.99** | **0.99** |
62
+
63
+ **Val Accuracy: 98.55% | Macro F1: 0.98**
64
+
65
+ ## Training Setup
66
+
67
+ | Parameter | Value |
68
+ |---|---|
69
+ | Base Model | EfficientNet-B3 (pretrained ImageNet) |
70
+ | Image Size | 512×512 px |
71
+ | Batch Size | 18 per GPU × 2 T4 = 36 effective |
72
+ | Optimizer | AdamW (lr=2e-5, wd=1e-2) |
73
+ | Scheduler | Cosine Annealing + 3-epoch warmup |
74
+ | Precision | FP16 (torch.cuda.amp) |
75
+ | Drop Rate | 0.4 |
76
+ | Label Smoothing | 0.05 |
77
+ | Early Stop Patience | 7 epochs |
78
+ | Hardware | Kaggle 2× NVIDIA T4 (16 GB each) |
79
+
80
+ ## Inference
81
+
82
+ ```python
83
+ import torch, timm
84
+ from PIL import Image
85
+ import torchvision.transforms as transforms
86
+
87
+ CLASSES = ["Healthy", "Black Spot", "Shriveled", "Damaged"]
88
+
89
+ model = timm.create_model("efficientnet_b3", pretrained=False,
90
+ num_classes=4, drop_rate=0.4)
91
+ ckpt = torch.load("best_model.pth", map_location="cpu")
92
+ state = {k.replace("module.", ""): v for k, v in ckpt["model_state_dict"].items()}
93
+ model.load_state_dict(state)
94
+ model.eval()
95
+
96
+ transform = transforms.Compose([
97
+ transforms.Resize((512, 512)),
98
+ transforms.ToTensor(),
99
+ transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
100
+ ])
101
+
102
+ img = Image.open("walnut.jpg").convert("RGB")
103
+ x = transform(img).unsqueeze(0)
104
+ probs = torch.softmax(model(x), dim=1)
105
+ conf, idx = probs.max(0)
106
+ print({"defect_class": CLASSES[idx.item()], "confidence": round(conf.item(), 4)})
107
+ ```
108
+ ## License
109
+
110
+ Apache 2.0