Skip to content
This repository was archived by the owner on Aug 13, 2025. It is now read-only.
This repository was archived by the owner on Aug 13, 2025. It is now read-only.

How to load IOPaint to a custom class #662

@SixtyTrees

Description

@SixtyTrees

I've installed IOPaint. So far, these features work flawlessly:
iopaint start # starts a webserver

def run_iopaint_single(image_path, mask_path, output_path, model='lama', device='cpu'):
	"""Run IOPaint on a single image-mask pair."""
	cmd = [
		'iopaint', 'run',
		'--image', image_path,
		'--mask', mask_path,
		'--output', output_path,
		'--model', model,
		'--device', device
	]
	try:
		result = subprocess.run(cmd, capture_output=True, text=True, check=True)
		return True, result.stdout
	except subprocess.CalledProcessError as e:
		return False, f"Error: {e.stderr}"

What is the correct way to load iopaint model into a variable of a class and call the process? Something along the lines

import numpy as np
import cv2
import iopaint

class Inpainter:
	def __init__(self, model: str = 'lama', device: str = 'cuda'):
		self.engine = iopaint.get_model(model, device)
		self.model = model
		self.device = device
	
	def inpaint(self, image: np.ndarray, mask: np.ndarray) -> np.ndarray:
		#do stuff
		return self.engine.inpaint(image, mask)
		
if __name__ == '__main__':
	inpainter = Inpainter()
	img = cv2.imread('path/to/image')
	mask = cv2.imread('path/to/mask', 0)
	reslt = inpainter.inpaint(img, mask)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions