File size: 1,275 Bytes
5793f6d
 
 
 
8092894
2826168
5793f6d
 
92e3db3
8092894
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5793f6d
 
 
8092894
 
5793f6d
 
2c80634
5793f6d
da0e039
 
 
 
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
import os
import pandas as pd
from huggingface_hub import HfApi, HfFolder
import yaml
import numpy as np
import time

config = yaml.safe_load(open("./config/config.yaml")) 
    
def load_image_and_saliency(class_idx, data_dir):
    path = os.path.join(data_dir, 'images', str(class_idx))
    images = os.listdir(path)
    # pick a random image
    id = np.random.randint(0, len(images))
    image = os.path.join(path, images[id])
    gradcam_image = os.path.join(data_dir, 'saliency', 'gradcam', images[id])
    lime_image = os.path.join(data_dir, 'saliency', 'lime', images[id])
    sidu_image = os.path.join(data_dir, 'saliency', 'sidu', images[id])
    rise_image = os.path.join(data_dir, 'saliency', 'rise', images[id])
    return image, gradcam_image, lime_image, sidu_image, rise_image

def load_example_images(class_idx, data_dir, max_images=16):
    path = os.path.join(data_dir, 'images', str(class_idx))
    images = os.listdir(path)
    # pick max_images random images
    ids = np.random.choice(len(images), max_images, replace=False)
    images = [os.path.join(path, images[id]) for id in ids]
    return images

# Function to load words based on global variable
def load_words(idx):
    words = [f"word_{idx}_{i}" for i in range(20)]
    return words