object of type 'NoneType' has no len()
See original GitHub issueFirst time try with Hyperas. I get an error: object of type ‘NoneType’ has no len() at trials=Trials()
in the optim.minimize(...)
call. Not sure what this means. I am trying to optimize a network that takes three inputs in the form of a list X_train[], so X_train[0] has a set of input data, X_train[1] and X_train_[2] also. Not sure if that could be the cause for this error? Don’t know what Hyperas can handle.
Here’s some code:
def data():
# load VGG16 output data, X_train and X_valid are lists with data channels
X_train, Y_train, X_valid, Y_valid = load_VGG16_output(data_type='train', num_channels=3)
return X_train, Y_train, X_valid, Y_valid
def model(X_train, Y_train, X_valid, Y_valid):
in_0 = Input(shape=X_train[0].shape[1:])
x = Dense(256, activation='relu')(in_0)
x = Dropout(0.5)(x)
in_1 = Input(shape=X_train[1].shape[1:])
y = Dense(64, activation='relu')(in_1) #, W_regularizer=l2(0.01))(in_1)
y = Dropout(0.5)(y)
in_2 = Input(X_train[2].shape[1:])
z = Dense(32, activation='relu')(in_2) #, W_regularizer=l2(0.01))(in_2)
z = Dropout(0.5)(z)
x = merge([x, y, z], mode='concat', concat_axis=1)
predict = Dense(1, activation='sigmoid')(x)
model = Model(input=[in_0, in_1, in_2], output=predict)
optimizer=Adam(lr=1e-4, decay=0.003)
model.compile(loss='binary_crossentropy', optimizer=optimizer, metrics=['accuracy'])
# load the class weight to balance the input positive / negative scores
class_weight = load_class_weight()
model.fit(X_train, Y_train,
batch_size={{choice([32, 64, 128])}}, # optimize batch size
nb_epoch=1,
verbose=2,
class_weight=class_weight,
validation_data=(X_valid, Y_valid))
score, acc = model.evaluate(X_valid, Y_valid, verbose=0)
print('Valid accuracy: ', acc)
return {'loss': -acc, 'status': STATUS_OK, 'model': model}
if __name__ == '__main__':
X_train, Y_train, X_valid, Y_valid = data()
best_run, best_model = optim.minimize(model=model,
data=data,
algo=tpe.suggest,
max_evals=5,
trials=Trials())
print('Evalutation of best performing model: ')
print(best_model.evaluate(X_valid, Y_valid))
Issue Analytics
- State:
- Created 7 years ago
- Comments:17 (9 by maintainers)
Top Results From Across the Web
"object of type 'NoneType' has no len()" error - Stack Overflow
You are asking for the Length of a variable that contains None. None is a special value (of type NoneType) that has no...
Read more >TypeError: object of type 'NoneType' has no len() in Python
The Python "TypeError: object of type 'NoneType' has no len()" occurs when we pass a None value to the len() function. To solve...
Read more >TypeError: object of type 'NoneType' has no len() - STechies
This error is generated in Python when we try to calculate the length of an object which returns 'none'. Let us understand it...
Read more >TypeError: object of type 'NoneType' has no len() - Yawin Tutor
The TypeError: object of type 'NoneType' has no len() error occurs while attempting to find the length of an object that returns 'None'....
Read more >TypeError: object of type 'NoneType' has no len() in Python
Reason 1: Assigning None Value to len() Function · Solution 1: Change the None Value · Solution 2: Using an if-else Statement ·...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got it! There is an indent after the![image](https://user-images.githubusercontent.com/27263086/71950005-ace86b80-3210-11ea-8cb7-57856477ebaf.png)
def data():
funtion as followSorry, I can’t reproduce this, but I think this has been resolved. @jdelange please re-open if the problem still persists.