Closed florianduclot closed 1 year ago
Thanks for this @florianduclot !
I can see it, first as you say there is a typo in the key it should be class_custom_weights
and not custom_weights
. Second, the config meta file stores it as a str
so we have to convert it to a dict. Can you try if this fixes it?
At the top, import literal_eval:
from ast import literal_eval
Change routine to:
if meta_dict[ReadConfig.CLASS_WEIGHTS.value] == 'custom':
meta_dict[ReadConfig.CLASS_WEIGHTS.value] = literal_eval(meta_dict['class_custom_weights'])
for k, v in meta_dict[ReadConfig.CLASS_WEIGHTS.value].items():
meta_dict[ReadConfig.CLASS_WEIGHTS.value][k] = int(v)
Let me know how goes and I will update pip package.
Simon
Thanks for the quick feedback, @sronilsson ,
I can't test that right at this time but it's equivalent to what I've tested to work (see my last code snippet above) so I agree with you that it should work.
I'll try your exact solution when I get a chance but it might not be today, unfortunately.
Hi @florianduclot - I did push the updated code and just a heads up up if you try it, I re-organized the files a fair bit to make more readable - the code piece lives in simba.model.grid_search_rf
now.
Just wanted to confirm: I tried the latest Simba version yesterday and it indeed works as intended.
Thanks again for pushing the fix.
Describe the bug A
KeyError
is thrown when training multiple models from meta files using custom weights. The meta file contains:class_weights
:custom
class_custom_weights
:{0: '1', 1: '2'}
The following error is thrown:
To Reproduce Steps to reproduce the behavior: Save a model settings meta file with custom weights using the defaults weights: The meta file contains:
class_weights
:custom
class_custom_weights
:{0: '1', 1: '2'}
Click on the green "Train multiple models (one for each saved setting)" button; the annotations are loaded, and then the error above is thrown.
Expected behavior The model training proceeds without error.
Desktop (please complete the following information):
Additional context This seems to result from the fact that
__check_validity_of_meta_files()
expects the meta file to have the column namecustom_weights
whereas the actual name isclass_custom_weights
. Manually changing this intrain_multiple_models.py
fixes the issue but quickly fails again with:This shows that the routine fails to deal with the dict being read as str from the file. I could fix all of that using the same approach used elsewhere in SimBa:
Note that it seems one could/should update
ReadConfig.CUSTOM_WEIGHTS
to beclass_custom_weights
or revert change the meta file to havecustom_weights
as column name but that is beyond my knowledge of SimBA to know which way to address this would be the most reliable and safe.