Spaces:
Runtime error
Runtime error
Download app.py from realambuj/Image_Classifier_using_RESNET50: direct link, hf CLI and curl.
- Browser
- Download file 1.47 kB
-
https://huggingface.co/spaces/realambuj/Image_Classifier_using_RESNET50/resolve/6e27146cb8aaf761a89e62b1bce594741af3e7df/app.py
- Command line
-
hf download hf://spaces/realambuj/Image_Classifier_using_RESNET50@6e27146cb8aaf761a89e62b1bce594741af3e7df/app.py
-
curl -L -o app.py https://huggingface.co/spaces/realambuj/Image_Classifier_using_RESNET50/resolve/6e27146cb8aaf761a89e62b1bce594741af3e7df/app.py
1.47 kB
| import streamlit as st | |
| from PIL import Image | |
| from transformers import AutoImageProcessor | |
| import torch | |
| import joblib | |
| with st.sidebar: | |
| st.subheader('Image Classifier using ResNet50') | |
| st.write('This is a image classification app using ResNet50. It is a state of the art model for image classification. It is a pretrained model which is trained on a large dataset of images. It can be used for classifying any image. It is a very powerful model and is very fast. It is also very accurate.') | |
| image = Image.open('resnet_architecture.png') | |
| st.image(image, caption='Bert Model') | |
| st.code('App Built by Ambuj Raj',language='python') | |
| st.title('Image Classifier using ResNet50') | |
| uploaded_file = st.file_uploader("Choose a image", type=['png', 'jpeg', 'jpg']) | |
| if uploaded_file is not None: | |
| st.image(uploaded_file, width=300) | |
| raw_image = Image.open(uploaded_file).convert('RGB') | |
| if st.button('Classify Image'): | |
| with st.spinner('Classifying Image...'): | |
| processor = AutoImageProcessor.from_pretrained("microsoft/resnet-50") | |
| loaded_model = joblib.load("model.sav") | |
| inputs = processor(raw_image, return_tensors="pt") | |
| with torch.no_grad(): | |
| logits = loaded_model(**inputs).logits | |
| # model predicts one of the 1000 ImageNet classes | |
| predicted_label = logits.argmax(-1).item() | |
| st.success('Image Classified!') | |
| st.write('Predicted Label is: ',loaded_model.config.id2label[predicted_label]) | |