1
votes
Please here is my code 

def train_apparentflow_net():

    code_path = config.code_dir
    
    fold = int(sys.argv[1])
    print('fold = {}'.format(fold))
    if fold == 0:
        mode_train = 'all'
        mode_val = 'all'
    elif fold in range(1,6):
        mode_train = 'train'
        mode_val = 'val'
    else:
        print('Incorrect fold')

i receive this error: IndexError: list index out of range yet here are my files in my fold

model_apparentflow_net_fold0_epoch050.h5

model_apparentflow_net_fold1_epoch050.h5

model_apparentflow_net_fold2_epoch050.h5
il y a 7 jours17.9 MB
model_apparentflow_net_fold3_epoch050.h5

model_apparentflow_net_fold4_epoch050.h5

model_apparentflow_net_fold5_epoch050.h5

module_apparentflow_net.py

so I don't understand why the python terminal tells me that I reference an index that does not exist yet it exists. Please could someone help me?

thank you so much for all answers

2
I suggest print(sys.argv) This will reveal a list with fewer than 2 elementsLancelot du Lac
The code you attached has nothing to do with files in your folderAlexey Larionov
also add all the commands you entered in you terminal both the argumentsBruno

2 Answers

1
votes

Please look at the following answer sys.argv[1] description

It is failing as there is no argument provided.

You could try

 fold = int(sys.argv[0])
0
votes

if all you need is to select the model, why not add the names in a list and select base on index like this

model_list = ["model_apparentflow_net_fold0_epoch050.h5", "model_apparentflow_net_fold1_epoch050.h5",

"model_apparentflow_net_fold2_epoch050.h5",
"model_apparentflow_net_fold3_epoch050.h5",

"model_apparentflow_net_fold4_epoch050.h5",

"model_apparentflow_net_fold5_epoch050.h5",
]


def train_apparentflow_net(model_list):
      
    code_path = config.code_dir
    
    fold = model_list[1] # specify model here
    print('fold = {}'.format(fold))
    if fold == 0:
        mode_train = 'all'
        mode_val = 'all'
    elif fold in range(1,6):
        mode_train = 'train'
        mode_val = 'val'
    else:
        print('Incorrect fold')