| | --- |
| | license: mit |
| | tags: |
| | - medical |
| | - vision |
| | - pytorch |
| | - optometry |
| | pipeline_tag: image-regression |
| | library_name: timm |
| | --- |
| | |
| | # Visionary-Net |
| | **AI-Powered Refractive Error Estimation** |
| |
|
| | Visionary-Net is a deep learning model that acts as a "Neural Auto-Refractor." It analyzes blur patterns in an image to estimate the optical prescription needed to correct them. |
| |
|
| | ## ⚡ Model Specs |
| | - **Backbone:** EfficientNet-B0 |
| | - **Input:** 224x224 RGB Image |
| | - **Output:** Sphere (SPH), Cylinder (CYL), Axis (Sin/Cos) |
| | - **Best Checkpoint:** `model_v1_ep9.pth` (Included in repo) |
| |
|
| | ## 💻 How to Use |
| |
|
| | You need `timm`, `torch`, and `opencv-python`. |
| |
|
| | ```python |
| | import torch |
| | import torch.nn as nn |
| | import timm |
| | import cv2 |
| | import numpy as np |
| | from huggingface_hub import hf_hub_download |
| | |
| | # 1. Define Architecture |
| | class VisionaryNet(nn.Module): |
| | def __init__(self): |
| | super().__init__() |
| | self.backbone = timm.create_model('efficientnet_b0', pretrained=False, num_classes=0) |
| | self.head = nn.Sequential( |
| | nn.Linear(1280, 512), nn.ReLU(), nn.Dropout(0.2), nn.Linear(512, 4) |
| | ) |
| | def forward(self, x): |
| | return self.head(self.backbone(x)) |
| | |
| | # 2. Load the Best Checkpoint (Epoch 9) |
| | model_path = hf_hub_download(repo_id="sanskxr02/Visionary-Net", filename="model_v1_ep9.pth") |
| | |
| | device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
| | model = VisionaryNet().to(device) |
| | model.load_state_dict(torch.load(model_path, map_location=device)) |
| | model.eval() |
| | |
| | # 3. Predict on an Image |
| | img = cv2.imread("test_blur.jpg") # Load image |
| | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) # Convert to RGB |
| | img = cv2.resize(img, (224, 224)) / 255.0 # Resize & Normalize |
| | |
| | img_t = torch.from_numpy(img).permute(2, 0, 1).unsqueeze(0).float().to(device) |
| | |
| | with torch.no_grad(): |
| | preds = model(img_t)[0].cpu().numpy() |
| | |
| | sph, cyl, sin_a, cos_a = preds |
| | axis = np.degrees(np.arctan2(sin_a, cos_a)) / 2.0 |
| | if axis < 0: axis += 180 |
| | |
| | print(f"👁️ Prescription: SPH {sph:.2f} D | CYL {cyl:.2f} D | AXIS {axis:.0f}°") |
| | |
| | |