EricFerreiraS / disentangled_representation-concept_ranking

From Disentangled Representation to Concept Ranking: Interpreting Deep Representations in Image Classification tasks - Paper Code
https://link.springer.com/chapter/10.1007/978-3-031-23618-1_22
MIT License
0 stars 0 forks source link

getting empty file by Running "feature_extraction_global.py" to extract the global concepts. #1

Open muhammadahsan opened 1 month ago

muhammadahsan commented 1 month ago

getting empty files by Running "feature_extraction_global.py" to extract the global concepts. The resultant files contains only column names like; ,target,name

EricFerreiraS commented 1 month ago

Hi Muhammad, thanks for reaching out to me. Can you provide more details about your setup? Have you executed the 'Netdissect' approach before executing the code? This step guarantees that the setup is correct. If you have already executed it, can you check your dataset directory and the settings on the 'settings.py' file?

muhammadahsan commented 1 month ago

Yes, I run Netdissect first, then feature_extraction_global.py Actually the below code is returning empty lists of activations_sum, activations_max, activations_avg:

// Function to extract values from the model for each image activations_sum=[] activations_max=[] activations_avg=[] def hook_fn(m, i, o): unit_sum={} unit_max={} unit_avg={} for grad in o:
try: for i,j in enumerate(grad):

sum of all values in the activation map

            unit_sum[i+1]=j.sum().item()
            ##max
            unit_max[i+1]=j.max().item()
            ##avg
            unit_avg[i+1]=j.mean().item()
        activations_sum.append(unit_sum)
        activations_max.append(unit_max)
        activations_avg.append(unit_avg)
    except AttributeError: 
        print ("None found for Gradient")

//Layer that I'm going to use. After all, try to get all layers

layer = model._modules['layer4']

layer.register_forward_hook(hook_fn)

EricFerreiraS commented 1 month ago

There are some points that you have to check: