autonomio / talos

Hyperparameter Experiments with TensorFlow and Keras
https://autonom.io
MIT License
1.62k stars 268 forks source link

Issue using class_weights as a parameter. #316

Closed zutron closed 5 years ago

zutron commented 5 years ago

Just a quick note to let you know that I seem to be running into errors when using class_weights as a search parameter.

My model.fit:

history = model.fit(x_train, y_train, validation_data=[x_val, y_val], batch_size=params['batch_size'], epochs=params['epochs'], verbose=0, class_weight= params['classweights'], callbacks=[early_stopper(params['epochs'], mode='moderate',monitor = 'val_pos_f1_score')])

My parameter dictionary: ... 'classweights':[{0:1, 1:0.5},{0:1, 1:1},{0:1, 1:2},{0:1, 1:3}] ...

The scan actually runs fine, but crashes at the upon scan completion with the following error:

Length mismatch: Expected axis has 23 elements, new values have 22 elements

Can post full code and error if needed, though should be easy enough to reproduce.

mikkokotila commented 5 years ago

Can you post the full trace.

zutron commented 5 years ago

Sure - here's one from a quick test run I just did:

`ValueError Traceback (most recent call last)

in 200 #reduction_window = 30, 201 #seed = 101, --> 202 val_split = 0.25) 203 204 ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\talos\scan\Scan.py in __init__(self, x, y, params, model, dataset_name, experiment_no, experiment_name, x_val, y_val, val_split, shuffle, round_limit, time_limit, grid_downsample, random_method, seed, search_method, permutation_filter, reduction_method, reduction_interval, reduction_window, reduction_threshold, reduction_metric, reduce_loss, last_epoch_value, clear_tf_session, disable_progress_bar, print_params, debug) 183 # input parameters section ends 184 --> 185 self._null = self.runtime() 186 187 def runtime(self): ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\talos\scan\Scan.py in runtime(self) 188 189 self = scan_prepare(self) --> 190 self = scan_run(self) ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\talos\scan\scan_run.py in scan_run(self) 30 self.peak_epochs_df = peak_epochs_todf(self) 31 ---> 32 self = scan_finish(self) ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\talos\scan\scan_finish.py in scan_finish(self) 28 # clean the results into a dataframe 29 self.data = self.result[self.result.columns[0]].str.split(',', expand=True) ---> 30 self.data.columns = self.result.columns[0].split(',') 31 32 # remove redundant columns ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pandas\core\generic.py in __setattr__(self, name, value) 5078 try: 5079 object.__getattribute__(self, name) -> 5080 return object.__setattr__(self, name, value) 5081 except AttributeError: 5082 pass pandas\_libs\properties.pyx in pandas._libs.properties.AxisProperty.__set__() ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pandas\core\generic.py in _set_axis(self, axis, labels) 636 637 def _set_axis(self, axis, labels): --> 638 self._data.set_axis(axis, labels) 639 self._clear_item_cache() 640 ~\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\pandas\core\internals\managers.py in set_axis(self, axis, new_labels) 153 raise ValueError( 154 'Length mismatch: Expected axis has {old} elements, new ' --> 155 'values have {new} elements'.format(old=old_len, new=new_len)) 156 157 self.axes[axis] = new_labels ValueError: Length mismatch: Expected axis has 23 elements, new values have 22 elements `
mikkokotila commented 5 years ago

I think this should be fixed in v.0.6:

pip install git+http://github.com/autonomio/talos@daily-dev

Can you try that and let me know how it goes. Thanks!

mikkokotila commented 5 years ago

Given there is no update, I'm assuming this was resolved. Feel free to reopen / open new ticket if anything.