Skip to content

How to preprocess a single image for inference #444

Answered by SarBH
SarBH asked this question in Q&A
Discussion options

You must be logged in to vote

UPDATE: if we want the preprocessing function to behave as i described processed = preprocessing_fn(img) you can use

    image = cv2.imread(args.sample_input)
    comp = get_preprocessing(preprocessing_fn)
    x = comp(image=image)
def get_preprocessing(preprocessing_fn):
    """Construct preprocessing transform
    
    Args:
        preprocessing_fn (callbale): data normalization function 
            (can be specific for each pretrained neural network)
    Return:
        transform: albumentations.Compose
    
    """
    
    _transform = [
        albu.Lambda(image=preprocessing_fn),
        albu.Lambda(image=to_tensor, mask=to_tensor),
    ]
    return albu.Compose(_transform)

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@YoniChechik
Comment options

@tatyana-pichugina
Comment options

Answer selected by SarBH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants