#     except:
    #         pass
    #     img_dict = IMUT.IMG_list(path=p, outpath_root='out/filter/', GT=GT, labs=labs).select_imgs(img_list)
    # else:
    img_list = {
        k: v
        for k, v in enumerate(sorted(os.listdir(p))[base:base + window])
    }
    print(img_list)
    img_dict = IMUT.IMG_list(path=p, outpath_root=res_path, GT=GT,
                             labs=labs).select_imgs(img_list)
    #img_dict=IMUT.IMG_list(path=p,outpath_root='out/filter/', GT=GT, labs=labs).select_particular_img('gr.jpg')

    arch_dict = {
        'resnet18':
        EVMET.Architecture(
            models.resnet18(pretrained=True).eval(), 'resnet18', 'layer4'),
        'resnet50':
        EVMET.Architecture(
            models.resnet50(pretrained=True).eval(), 'resnet50', 'layer4'),
        'vgg16':
        EVMET.Architecture(
            models.vgg16(pretrained=True).eval(), 'vgg16', 'features_29')
    }
    arch = arch_dict[arch_name]
    #arch=EVMET.Architecture(models.resnet101(pretrained=True).eval(),'resnet101','layer4')
    #arch=EVMET.Architecture(models.resnet152(pretrained=True).eval(),'resnet152','layer4')
    #arch=EVMET.Architecture(models.vgg16(pretrained=True).eval(),'vgg16','features_29')

    metrics_dict = {
        'average_drop':
        ADIC.AverageDrop('average_drop', arch),
Exemple #2
0
    os.mkdir(f'{outpath_root}filter/')
except:
    pass


img_dict=IMUT.IMG_list(path=p,outpath_root='out/filter/ScoreCAM/',GT=GT,labs=labs).select_imgs(img_list)
try:
    os.mkdir(f'{img_dict.outpath_root}')
except:
    pass

#img_dict.set_outpath_root(f'{img_dict.get_outpath_root()}vgg16_ScoreCAM/')
print(img_dict.get_outpath_root())
print(img_dict.get_img_dict())

arch=EVMET.Architecture(models.resnet18(pretrained=True).eval(),'resnet18','layer4')
#arch=EVMET.Architecture(models.vgg16(pretrained=True).eval(),'vgg16','features_29')
avg_drop=ADIC.AverageDrop('average_drop',arch)
inc_conf=ADIC.IncreaseInConfidence('increase_in_confidence',arch)
deletion=DAI.Deletion('deletion',arch)
insertion=DAI.Insertion('insertion',arch)

em=EVMET.MetricsEvaluator(img_dict, saliency_map_extractor=run, model=arch, metrics=[avg_drop, inc_conf, deletion, insertion])

start = time.time()
now = start

M_res,m_res=em()
print(f'Execution time: {int(time.time() - start)}s')
print(f'In {num_imgs} images')
for M in M_res:
base, window = chunk_id * chunk_dim + displacement, chunk_dim
pattern = 'ILSVRC2012_val_********.JPEG'
#img_list=get_n_imgs(range(base+1,base+window+1),pattern)

with open('filter.txt', 'r') as f:
    txt = f.read()

img_list = [p.split()[0] for p in txt.strip().split('\n')[base:base + window]]
img_list = {get_num_img(p.split()[0]): p.split()[0] for p in img_list}
try:
    os.mkdir(f'{outpath_root}filter/')
except:
    pass

#arch=EVMET.Architecture(models.resnet18(pretrained=True).eval(),'resnet18','layer4')
arch = EVMET.Architecture(
    models.vgg16(pretrained=True).eval(), 'vgg16', 'features_29')

avg_drop = ADIC.AverageDrop('average_drop', arch)
inc_conf = ADIC.IncreaseInConfidence('increase_in_confidence', arch)
deletion = DAI.Deletion('deletion', arch)
insertion = DAI.Insertion('insertion', arch)

img_dict = IMUT.IMG_list(path=p, outpath_root='out/filter/', GT=GT,
                         labs=labs).select_imgs(img_list)

em = EVMET.MetricsEvaluator(img_dict,
                            saliency_map_extractor=run,
                            model=arch,
                            metrics=[avg_drop, inc_conf, deletion, insertion])
start = time.time()
now = start
Exemple #4
0
        for x in f.read().strip().split('\n')
    }

#img_dict=IMUT.IMG_list(path=p,GT=GT,labs=labs).generate_random(num_imgs)
base, window = chunk_id * chunk_dim + displacement, chunk_dim
pattern = 'ILSVRC2012_val_********.JPEG'
#img_list=get_n_imgs(range(base+1,base+window+1),pattern)

with open('filter.txt', 'r') as f:
    txt = f.read()
img_list = [p.split()[0] for p in txt.strip().split('\n')[base:base + window]]
img_list = {get_num_img(p.split()[0]): p.split()[0] for p in img_list}

model = models.vgg16(pretrained=True).eval()
#arch=EVMET.Architecture(model,'resnet18',model.layer4[1].conv2)
arch = EVMET.Architecture(model, 'vgg16', model.features[29])

avg_drop = ADIC.AverageDrop('average_drop', arch)
inc_conf = ADIC.IncreaseInConfidence('increase_in_confidence', arch)
deletion = DAI.Deletion('deletion', arch)
insertion = DAI.Insertion('insertion', arch)

img_dict = IMUT.IMG_list(path=p, outpath_root='out/filter/', GT=GT,
                         labs=labs).select_imgs(img_list)

em = EVMET.MetricsEvaluator(img_dict,
                            saliency_map_extractor=run,
                            model=arch,
                            metrics=[avg_drop, inc_conf, deletion, insertion])
start = time.time()
now = start