Download ml/models/vision/texture_classifier.py from PRiyanshu0-1/TrackChain: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/PRiyanshu0-1/TrackChain/resolve/main/ml/models/vision/texture_classifier.py
- Command line
-
hf download hf://PRiyanshu0-1/TrackChain/ml/models/vision/texture_classifier.py
-
curl -L -o texture_classifier.py https://huggingface.co/PRiyanshu0-1/TrackChain/resolve/main/ml/models/vision/texture_classifier.py
1.13 kB
| # Optional CNN texture classifier (e.g. corrugation) if a labeled class is required. | |
| import torch | |
| import torch.nn as nn | |
| from ml.core.registry import register_model | |
| class RailTextureClassifier(nn.Module): | |
| """Compact convolutional neural network for railhead texture & corrugation pattern classification.""" | |
| def __init__(self, num_classes: int = 4): | |
| super().__init__() | |
| self.features = nn.Sequential( | |
| nn.Conv2d(3, 32, kernel_size=3, padding=1), | |
| nn.BatchNorm2d(32), | |
| nn.ReLU(inplace=True), | |
| nn.MaxPool2d(2, 2), | |
| nn.Conv2d(32, 64, kernel_size=3, padding=1), | |
| nn.BatchNorm2d(64), | |
| nn.ReLU(inplace=True), | |
| nn.AdaptiveAvgPool2d((1, 1)), | |
| ) | |
| self.classifier = nn.Sequential( | |
| nn.Flatten(), | |
| nn.Linear(64, 32), | |
| nn.ReLU(inplace=True), | |
| nn.Linear(32, num_classes), | |
| ) | |
| def forward(self, x: torch.Tensor) -> torch.Tensor: | |
| feat = self.features(x) | |
| logits = self.classifier(feat) | |
| return logits | |