File size: 2,138 Bytes
18f2f54
 
 
 
 
738e754
 
18f2f54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ce58e1
18f2f54
2ce58e1
 
18f2f54
2ce58e1
 
fc22191
3afc5cf
2ce58e1
 
 
 
 
 
 
18f2f54
 
 
2ce58e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import streamlit as st
import pandas as pd

from backend.utils import load_dataset, use_container_width_percentage

st.set_page_config(layout='wide')

st.title('ImageNet-1k')
st.markdown('This page shows the summary of 50,000 images in the validation set of [ImageNet-1k](https://huggingface.co/datasets/imagenet-1k)')

# SCREEN_WIDTH, SCREEN_HEIGHT = 2560, 1664

with st.spinner("Loading dataset..."):
    dataset_dict = {}
    for data_index in range(5):
        dataset_dict[data_index] = load_dataset(data_index)
        
imagenet_df = pd.read_csv('./data/ImageNet_metadata.csv')

class_labels = imagenet_df.ClassLabel.unique().tolist()
class_labels.sort()
selected_classes = st.multiselect('Class filter: ', options=['All'] + class_labels)
if not ('All' in selected_classes or len(selected_classes) == 0):
    imagenet_df = imagenet_df[imagenet_df['ClassLabel'].isin(selected_classes)]
# st.write(class_labels)

col1, col2 = st.columns([2, 1])
with col1:
    st.dataframe(imagenet_df)
    use_container_width_percentage(100)

with col2:
    st.text_area('Type anything here to copy later :)')
    image = None
    with st.form("display image"):
        img_index = st.text_input('Image ID to display')
    
        submitted = st.form_submit_button('Display this image')
        error_container = st.empty()

        if submitted:
            try:
                img_index = int(img_index)
                if img_index > 50000-1 or img_index < 0:
                    error_container.error('The Image ID must be in range from 0 to 49999', icon="🚫")
                else:
                    image = dataset_dict[img_index//10_000][img_index%10_000]['image']
                    class_label = dataset_dict[img_index//10_000][img_index%10_000]['label']
                    class_id = dataset_dict[img_index//10_000][img_index%10_000]['id']
            except ValueError:
                error_container.error('Please enter an integer number for Image ID', icon = "🚫")
            
    if image != None:
        st.image(image)
        st.write('**Class label:** ', class_label)
        st.write('\n**Class id:** ', str(class_id))