'IndexError: list index out of range please how can i fix it?
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
Solution 1:[1]
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])
Solution 2:[2]
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')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pad |
| Solution 2 | Bruno |
