ResNet34 is a powerful convolutional neural network for image classification. With InferX, you can run ResNet34 on any device using the same API - from edge devices to powerful servers.
from inferx.models.resnet34 import ResNet34import cv2# Initialize the model (automatically detects your hardware)model = ResNet34()# Load and classify an imageimage = cv2.imread("path/to/your/image.jpg")results = model.inference(image)# Print top predictionsfor prediction in results['predictions'][:5]: print(f"{prediction['class']}: {prediction['confidence']:.3f}")
# Filter predictions by confidence thresholdresults = model.inference( image, confidence_threshold=0.5, top_k=10)# Only show high-confidence predictionshigh_confidence = [ pred for pred in results['predictions'] if pred['confidence'] > 0.7]for pred in high_confidence: print(f"High confidence: {pred['class']} ({pred['confidence']:.3f})")
{ 'predictions': [ { 'class': str, # Class name (e.g., "golden retriever") 'class_id': int, # ImageNet class ID 'confidence': float # Confidence score (0-1) } ], 'inference_time': float, # Time taken for inference (seconds) 'preprocessing_time': float # Time taken for preprocessing (seconds)}
# Example for manufacturing quality controldef check_product_quality(image_path, expected_class="product_name"): model = ResNet34() image = cv2.imread(image_path) results = model.inference(image, top_k=5) # Check if expected class is in top predictions for pred in results['predictions']: if expected_class.lower() in pred['class'].lower(): if pred['confidence'] > 0.8: return "PASS", pred['confidence'] else: return "LOW_CONFIDENCE", pred['confidence'] return "FAIL", 0.0# Test productstatus, confidence = check_product_quality("product_image.jpg", "bottle")print(f"Quality Check: {status} (Confidence: {confidence:.3f})")