Views
No views yet
(384, 384, 3) (RGB images)huggingface_hub library.1import tensorflow as tf
2from huggingface_hub import from_pretrained_keras
3import cv2
4import numpy as np
5
6# Load the model from the Hugging Face Hub
7try:
8 model = from_pretrained_keras("Arko007/diabetic-retinopathy-v1")
9 print("Model loaded successfully!")
10except Exception as e:
11 print(f"Error loading model: {e}")
12
13def preprocess_image(image_path):
14 '''Your preprocessing function must match the one used in training.'''
15 img = cv2.imread(image_path)
16 img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
17 img = cv2.resize(img, (384, 384))
18 img = img.astype(np.float32) / 255.0
19 return img
20
21# Preprocess your image to a (384, 384, 3) tensor
22# example_image = preprocess_image("path/to/your/image.jpg")
23
24# The model expects a batch, so add a batch dimension
25# example_image_batch = tf.expand_dims(example_image, axis=0)
26
27# Get predictions
28# predictions = model.predict(example_image_batch)
29# predicted_class = tf.argmax(predictions, axis=1).numpy()[0]
30
31# print(f"Predicted Retinopathy Grade: {predicted_class}")train.py script. Key aspects of the training include:1e-4.ModelCheckpoint to save the best model based on validation accuracy and ReduceLROnPlateau to adjust the learning rate during training.