blobcity / ai-seed

1000+ ready code templates to kickstart your next AI experiment
https://cloud.blobcity.com
Apache License 2.0
115 stars 54 forks source link

Add age range prediction example #967

Closed sakares closed 2 years ago

sakares commented 2 years ago

This PR is about adding how to predict a person face age by deep learning architecture name Vision Transformers We utilized the available Huggingface ViT nateraw/vit-age-classifier model

ViT prediction code:

def get_age_range(img):

    # Transform our image and pass it through the model
    inputs = transforms(img, return_tensors='pt')
    outputs = model(**inputs)
    logits = outputs.logits
    predicted_class_idx = logits.argmax(-1).item()

    # Predicted Classes
    preds = model.config.id2label[predicted_class_idx]

    return preds

Example result: link

or screenshot here:

Screen Shot 2021-10-05 at 20 45 15
Thilakraj1998 commented 2 years ago

@sakares keep the creator tags/detail on bottom cell.

sakares commented 2 years ago

@Thilakraj1998 updated, please check