autonomio / talos

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

AttributeError: 'list' object has no attribute 'max' #270

Closed Shaier closed 5 years ago

Shaier commented 5 years ago

I am using keras functional API. I'm trying to pass in a list of inputs. I tried to follow this issue:

But I'm still getting an error:

AttributeError: 'list' object has no attribute 'max' `This is my current model:


def create_model(x_train,y_train, parameters): 

# Multiple Inputs

# 1st input model
frame1 = Input(shape=(9216,))
hidden1 = Dense(30, activation='relu')(frame1)
hidden1= Dropout(0.2)(hidden1)
hidden1 = Dense(50, activation='relu')(hidden1)
#hidden1 = Dense(30, activation='relu')(hidden1)
output1 = Dense(10, activation='softmax')(hidden1) 

# 2nd input model
frame2 = Input(shape=(9216,))
hidden2 = Dense(30, activation='relu')(frame2)
hidden1= Dropout(0.2)(hidden2)
hidden2 = Dense(50, activation='relu')(hidden2)
#hidden2 = Dense(30, activation='relu')(hidden2)
output2 = Dense(10, activation='softmax')(hidden2) 

model = Model(inputs=[x1, x2], 
              outputs=[output1, output2])

#Compile the model
model.compile(optimizer='adam', loss='mse', metrics=['mse'])

history = model.fit(model.fit(x=x_train,y=y_train, 
                              validation_split=0.2,
                              batch_size=parameters['batch_size'],
                              shuffle=False,
                              epochs=20,
                              verbose=1))

return history, model 

# summarize layers
print(model.summary())

#My parameters for the grid search are:

parameters = {'batch_size': [10,20]}

#I get the error when I run this:

import talos as ta
t = ta.Scan([train1,train2], 
            [y1,y2],
            params=parameters ,
            model=create_model)  

AttributeError: 'list' object has no attribute 'max'

#Note that my train1, train2 are numpy arrays with 9216 values. (96x96 image)
mikkokotila commented 5 years ago

Can you share the whole trace.

Shaier commented 5 years ago

Yes, thank you for the quick reply!

AttributeError                            Traceback (most recent call last)
<ipython-input-22-3b26e0b2dbbb> in <module>()
      2             [y1,y2],
      3             params=p,
----> 4             model=model)

/usr/local/lib/python3.6/dist-packages/talos/scan/Scan.py in __init__(self, x, y, params, model, dataset_name, experiment_no, x_val, y_val, val_split, shuffle, round_limit, grid_downsample, random_method, seed, search_method, reduction_method, reduction_interval, reduction_window, reduction_threshold, reduction_metric, reduce_loss, last_epoch_value, clear_tf_session, disable_progress_bar, print_params, debug)
    163         # input parameters section ends
    164 
--> 165         self._null = self.runtime()
    166 
    167     def runtime(self):

/usr/local/lib/python3.6/dist-packages/talos/scan/Scan.py in runtime(self)
    167     def runtime(self):
    168 
--> 169         self = scan_prepare(self)
    170         self = scan_run(self)

/usr/local/lib/python3.6/dist-packages/talos/scan/scan_prepare.py in scan_prepare(self)
     56 
     57     # create the data asset
---> 58     self.y_max = self.y.max()
     59     self = validation_split(self)
     60     self.shape = classify(self.y)

AttributeError: 'list' object has no attribute 'max'
mikkokotila commented 5 years ago

Is it that in your case y1 and y2 are unique?

Shaier commented 5 years ago

y1 and y2 share some similar numbers

mikkokotila commented 5 years ago

Ok. It will take a couple of weeks I guess, but this will be handled. I want to look back everything that had to do with non-2d inputs and make sure it's all taken care of once and for all. I think this should be the only remaining thing though, so it would be fast to do it.

ChaplinHao commented 5 years ago

@mikkokotila @Shaier Hi, I meet the same problem, when put the a list array multiple inputs or outputs, the error will be occur, and I installed the latest version of talos, any solution? and why?

Shaier commented 5 years ago

I still haven't found a solution to this. Sorry

mikkokotila commented 5 years ago

If you take the branch params-api-test which is v.0.6 you can just remove the line self.y_max = self.y.max() and you should be ok. I'll take care of this later, but that could be a temporary solution.

gregstarr commented 5 years ago

This does not take care of the problem for me

Traceback (most recent call last):
  File "search.py", line 61, in <module>
    x_val=val_data, y_val=[y_val, strength_val], grid_downsample=5e-6)
  File "C:\ProgramData\Anaconda3\envs\substorm-detection\lib\site-packages\talos\scan\Scan.py", line 170, in __init__
    self._null = self.runtime()
  File "C:\ProgramData\Anaconda3\envs\substorm-detection\lib\site-packages\talos\scan\Scan.py", line 174, in runtime
    self = scan_prepare(self)
  File "C:\ProgramData\Anaconda3\envs\substorm-detection\lib\site-packages\talos\scan\scan_prepare.py", line 60, in scan_prepare
    self.shape = classify(self.y)
  File "C:\ProgramData\Anaconda3\envs\substorm-detection\lib\site-packages\talos\utils\pred_class.py", line 5, in classify
    shape = detect_shape(y)
  File "C:\ProgramData\Anaconda3\envs\substorm-detection\lib\site-packages\talos\utils\pred_class.py", line 19, in detect_shape
    return y.shape[1]
AttributeError: 'list' object has no attribute 'shape'
gregstarr commented 5 years ago

Actually my problem may be related to multiple outputs. Is there a way to have multiple outputs?

mikkokotila commented 5 years ago

Actually my problem may be related to multiple outputs. Is there a way to have multiple outputs?

At the moment this is not supported. There is #154 from past, which is related with this. It's basically waiting for somebody to pick it up and make that contribution.

Alternatively, if you can share with me exactly what you are trying to do, including your model, your data, params dictionary, and what you expect to see as a result, and I will see on that basis, maybe it's straightforward to implement support for this.

mikkokotila commented 5 years ago

This is now resolved in daily-dev. See #154 and #353 for more info. Closing here.

@Shaier @gregstarr @ChaplinHao thanks for your patience and have a great day as well.