autonomio / talos

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

Error while deploying/saving: ValueError: Must pass 2-d input #260

Closed anonymousDog12 closed 5 years ago

anonymousDog12 commented 5 years ago

Keras RNN models require input data to be 3 dimensional, so I reshaped my training data to fit the RNN model. However, this forbids me from saving my model results because talo requires input to be 2-D.


Complete Trace:

Deploy package best_mymodel have been saved.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-a2ea066d7165> in <module>
      3 #choose the best model by sorting the lowest 1-r_value for the validation and save it
      4 data=ta.Predict(t).scan_object.data.sort_values("val_r_value")
----> 5 ta.Deploy(t, 'best_mymodel',metric='val_r_value',asc=True)
      6 
      7 #save all performance of all models in para_space

~/anaconda3/lib/python3.6/site-packages/talos/commands/deploy.py in __init__(self, scan_object, model_name, metric, asc)
     32         self.save_model_as()
     33         self.save_details()
---> 34         self.save_data()
     35         self.save_results()
     36         self.save_params()

~/anaconda3/lib/python3.6/site-packages/talos/commands/deploy.py in save_data(self)
     58     def save_data(self):
     59 
---> 60         x = pd.DataFrame(self.scan_object.x[:100])
     61         y = pd.DataFrame(self.scan_object.y[:100])
     62 

~/anaconda3/lib/python3.6/site-packages/pandas/core/frame.py in __init__(self, data, index, columns, dtype, copy)
    422             else:
    423                 mgr = init_ndarray(data, index, columns, dtype=dtype,
--> 424                                    copy=copy)
    425 
    426         # For data is list-like, or Iterable (will consume into list)

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals/construction.py in init_ndarray(values, index, columns, dtype, copy)
    144     # by definition an array here
    145     # the dtypes will be coerced to a single dtype
--> 146     values = prep_ndarray(values, copy=copy)
    147 
    148     if dtype is not None:

~/anaconda3/lib/python3.6/site-packages/pandas/core/internals/construction.py in prep_ndarray(values, copy)
    247         values = values.reshape((values.shape[0], 1))
    248     elif values.ndim != 2:
--> 249         raise ValueError('Must pass 2-d input')
    250 
    251     return values

ValueError: Must pass 2-d input
mikkokotila commented 5 years ago

Thanks. This will be fixed in the next couple of days no doubt.

For the time being you can overcome this by:

t.x = np.zeros(500)
t.y = np.zeros(500)

The line of code where the issue arise is not really important even you override it this way as it merely stores a small sample of x and y data for reference purpose.

anonymousDog12 commented 5 years ago

Thanks. This will be fixed in the next couple of days no doubt.

For the time being you can overcome this by:

t.x = np.zeros(500)
t.y = np.zeros(500)

The line of code where the issue arise is not really important even you override it this way as it merely stores a small sample of x and y data for reference purpose.

Appreciate it!

BraveDistribution commented 5 years ago

This is also happening while saving CNN - it is not specific to RNN.

mikkokotila commented 5 years ago

This issue would manifest in all cases where x (or y) is not 2d. Given there can be many different data formats, it's not a straightforward thing to resolve. I have to investigate this further.

For now, I've overcome this in v.0.6 by using the above "hack" i.e. simply not storing any data. Here it's important to note that we don't store the data for any other reason that having a small reference to what the data looks like, so it's not critically important to have it.

mikkokotila commented 5 years ago

Closing here as this is already dealt with in v.0.6 onwards.