This guide helps you migrate from Ear Segmentation AI v1.x to v2.0.
Version 2.0 is a complete refactor with a modern architecture, but maintains full backward compatibility. Your existing v1.x code will continue to work with deprecation warnings.
v1.x (Old Way)
from earsegmentationai.ear_models import EarModel
# Initialize
model = EarModel()
model.download_models()
model.load_model(device="cuda:0")
# Process image
mask_original, mask_resized = model.predict("image.jpg")
v2.0 (New Way)
from earsegmentationai import ImageProcessor
# Initialize (auto-downloads model)
processor = ImageProcessor(device="cuda:0")
# Process image
result = processor.process("image.jpg")
mask = result.mask
has_ear = result.has_ear
ear_percentage = result.ear_percentage
v1.x (Old Way)
from earsegmentationai.camera_mode import process_camera_mode
process_camera_mode(
deviceId=0,
device="cuda:0",
record=True
)
v2.0 (New Way)
from earsegmentationai import VideoProcessor
processor = VideoProcessor(device="cuda:0")
stats = processor.process(
0, # camera ID
output_path="output.avi",
display=True
)
v1.x Commands
python -m earsegmentationai.main picture-capture --folderpath image.jpg --device cuda:0
python -m earsegmentationai.main webcam-capture --deviceid 0 --device cuda:0
python -m earsegmentationai.main video-capture --filepath video.mp4
v2.0 Commands
earsegmentationai process-image image.jpg --device cuda:0
earsegmentationai webcam --device-id 0 --device cuda:0
earsegmentationai process-video video.mp4 --device cuda:0
Feature | v1.x | v2.0 |
---|---|---|
Single image processing | β | β Enhanced |
Batch processing | β | β |
Video file processing | β | β Enhanced |
Webcam processing | β | β Enhanced |
URL image processing | β | β |
Progress bars | β | β |
Temporal smoothing | β | β |
Configuration files | β | β |
Type hints | β | β |
Comprehensive tests | β | β |
processor = ImageProcessor()
results = processor.process([
"image1.jpg",
"image2.jpg",
"image3.jpg"
])
print(f"Detection rate: {results.detection_rate}%")
result = processor.process("image.jpg")
print(f"Has ear: {result.has_ear}")
print(f"Ear area: {result.ear_percentage}%")
print(f"Bounding box: {result.get_bounding_box()}")
print(f"Center: {result.get_center()}")
from earsegmentationai import Config
config = Config(
model={"architecture": "FPN"},
processing={"batch_size": 8}
)
processor = ImageProcessor(config=config)
earsegmentationai benchmark image.jpg --iterations 100
When using v1.x APIs, youβll see deprecation warnings:
DeprecationWarning: EarModel is deprecated. Use ImageProcessor or VideoProcessor instead.
To suppress these warnings temporarily:
import warnings
warnings.filterwarnings("ignore", category=DeprecationWarning)
# Old
from earsegmentationai.ear_models import EarModel
from earsegmentationai.camera_mode import process_camera_mode
# New
from earsegmentationai import ImageProcessor, VideoProcessor
# Old
model = EarModel()
model.download_models()
model.load_model("cuda:0")
# New
processor = ImageProcessor(device="cuda:0")
# Model downloads automatically on first use
# Old
mask_orig, mask_resized = model.predict(image)
# New
result = processor.process(image)
mask = result.mask
Replace old CLI commands with new ones (see CLI Commands section above).
ImportError: cannot import name 'EarModel' from 'earsegmentationai.ear_models'
Solution: The old modules are available through the compatibility layer:
from earsegmentationai import EarModel # Works with v2.0
v1.x returned tuple: (mask_original, mask_resized)
v2.0 returns ProcessingResult
object with properties
Solution: Access mask directly:
# If you need tuple format for compatibility
result = processor.process(image)
mask_tuple = (result.mask, result.mask) # Both are same in v2.0
Some v1.x parameters like foler_path
(typo) are deprecated.
Solution: These parameters are ignored in v2.0 with warnings.
Gradual Migration: Your v1.x code will continue to work. Migrate gradually.
Use New Features: Take advantage of batch processing and rich results.
Update Tests: Write tests using the new API.
Configuration Files: Use YAML configuration for complex setups.
If you encounter issues during migration:
Remember: v2.0 is fully backward compatible, so thereβs no rush to migrate everything at once!