woshixuhao / semantic-explainable-AI

The codes and dataset for the semantic explainable AI (S-XAI)
15 stars 4 forks source link

a problem when running the code S-XAI.py #1

Closed numb89757 closed 12 months ago

numb89757 commented 2 years ago

I'm trying to implement this project. I run the code in the sequence CNN_training.py GA.py and then S-XAI.py. I successfully run the first two python file. But when run the code in S-XAI.py, I meet a problem in this code segment:

# 查看分割图 
350    segments = slic(img_as_float(img), n_segments=n_segments, sigma=sigma)
351     fig1=plt.figure(1)
352    plt.imshow(mark_boundaries(img, segments))
353    position_spot = plt.ginput(4, timeout=90)
354    plt.close(fig1)
355    if position_spot[0]==position_spot[1]:
356         print('no position')
357         continue
358    print([position_spot])

The Exception output as follow. How could I fix the code?

----------第0次迭代----------
Traceback (most recent call last):
  File "S-XAI.py", line 1345, in <module>
    cut_position(use_model)
  File "S-XAI.py", line 355, in cut_position
    if position_spot[0]==position_spot[1]:
IndexError: list index out of range

2.

Besides, where is the file '{config.position_animal}_space_2000.npy'? I notice the code as follow I show, however I can't find the file from your Google Drive. 😢 or maybe it would generate automatically?

859     cdf_record=[]
860     for i in ['eye','nose','leg']:
861         for j in ['dog','cat']:
862             config.position_space =i
863             config.position_animal = j
864             _, _, space_index, space_value = get_position(conv_out_2_0, 5, show_picture=False)
865             space_index = np.array(space_index, dtype=int)
866             space = np.load(f'result_save/{config.position_animal}_space_2000.npy')

appreciate for your help.

woshixuhao commented 2 years ago

Thanks for your questions! I have revise the code and add some explanation to help readers better understand the function in the github and upload relevant files.

  1. This code functions to mask the semantic position manually. For each picture, we should click 4 times (different position) on the semantic position. You will see four red dots on the picture. Then, the picture will be closed and reopened automatically. You need to click 1 time on a nearby position (e.g., body) to decide the color of mask. When the operation is finished, the next picture will be opened. If the picture donnot has semantic position, you can click 4 time on the same place to skip this picture. I have added some notes for this code.
  2. I upload these files in the 'result_save' dir in github, you can download them. Or you can generate them from the val_distribution function in the code with some modification. I have added some notes before this sentence. If you have any problems about the code, welcome to ask me at any time!
woshixuhao commented 2 years ago

Thanks for your questions! I have revise the code and add some explanation to help readers better understand the function in the github and upload relevant files. This reply is also attached on the github.

  1. This code functions to mask the semantic position manually. For each picture, we should click 4 times on the semantic position. You will see four red dots on the picture. Then, the picture will be closed and reopened automatically. You need to click 1 time on a nearby position (e.g., body) to decide the color of mask. When the operation is finished, the next picture will be opened. If the picture do not has semantic position, you can click 4 time on the same place to skip this picture.

  2. I  upload these files in the 'result_save' dir in github, you can download them. Or you can generate them from the val_distribution function in the code with some modification. I have added some notes before this sentence.

If you have any problems about the code, welcome to ask me at any time!

------------------ 原始邮件 ------------------ 发件人: "woshixuhao/semantic-explainable-AI" @.>; 发送时间: 2022年11月22日(星期二) 下午3:13 @.>; @.***>; 主题: [woshixuhao/semantic-explainable-AI] a problem when running the code S-XAI.py (Issue #1)

I'm trying to implement this project. I run the code in the sequence CNN_training.py GA.py and then S-XAI.py. I successfully run the first two python file. But when run the code in S-XAI.py, I meet a problem in this code segment:

查看分割图 350 segments = slic(img_as_float(img), n_segments=n_segments, sigma=sigma) 351 fig1=plt.figure(1) 352 plt.imshow(mark_boundaries(img, segments)) 353 position_spot = plt.ginput(4, timeout=90) 354 plt.close(fig1) 355 if position_spot[0]==position_spot[1]: 356 print('no position') 357 continue 358 print([position_spot])

The Exception output as follow. How could I fix the code? ----------第0次迭代---------- Traceback (most recent call last): File "S-XAI.py", line 1345, in <module> cut_position(use_model) File "S-XAI.py", line 355, in cut_position if position_spot[0]==position_spot[1]: IndexError: list index out of range

Besides, where is the file '{config.position_animal}_space_2000.npy'? I notice the code as follow I show, however I can't find the file from your Google Drive. 😢 or maybe it would generate automatically? 859 cdf_record=[] 860 for i in ['eye','nose','leg']: 861 for j in ['dog','cat']: 862 config.position_space =i 863 config.positionanimal = j 864 , _, space_index, space_value = get_position(conv_out_2_0, 5, show_picture=False) 865 space_index = np.array(space_index, dtype=int) 866 space = np.load(f'result_save/{config.position_animal}_space_2000.npy')
appreciate for your help.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>