eaglelandsonce commited on
Commit
a982b06
1 Parent(s): ae7a8d5

Update pages/11_Cifar10_HF.py

Browse files
Files changed (1) hide show
  1. pages/11_Cifar10_HF.py +8 -5
pages/11_Cifar10_HF.py CHANGED
@@ -1,12 +1,10 @@
1
  import streamlit as st
2
  from transformers import ViTFeatureExtractor, ViTForImageClassification
3
  from PIL import Image
4
- import requests
5
- import numpy as np
6
  import torch
7
 
8
- # Load pre-trained model and feature extractor
9
- model_name = "google/vit-base-patch16-224"
10
  feature_extractor = ViTFeatureExtractor.from_pretrained(model_name)
11
  model = ViTForImageClassification.from_pretrained(model_name)
12
 
@@ -32,4 +30,9 @@ if uploaded_file is not None:
32
  outputs = model(**inputs)
33
  logits = outputs.logits
34
  predicted_class_idx = logits.argmax(-1).item()
35
- st.write(f"Predicted Class: {predicted_class_idx} ({class_names[predicted_class_idx]})")
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import ViTFeatureExtractor, ViTForImageClassification
3
  from PIL import Image
 
 
4
  import torch
5
 
6
+ # Load pre-trained model and feature extractor for CIFAR-10
7
+ model_name = "aaraki/vit-base-patch16-224-in21k-finetuned-cifar10"
8
  feature_extractor = ViTFeatureExtractor.from_pretrained(model_name)
9
  model = ViTForImageClassification.from_pretrained(model_name)
10
 
 
30
  outputs = model(**inputs)
31
  logits = outputs.logits
32
  predicted_class_idx = logits.argmax(-1).item()
33
+
34
+ # Check if the predicted_class_idx is within bounds
35
+ if 0 <= predicted_class_idx < len(class_names):
36
+ st.write(f"Predicted Class: {predicted_class_idx} ({class_names[predicted_class_idx]})")
37
+ else:
38
+ st.error("Prediction index out of range.")