'TypeError: <lambda>() got an unexpected keyword argument 'dtype' with keras

I am running ANFIS algorithm on iris dataset. While adding fuzzylayer to the model i am getting error like below:

TypeError: <lambda>() got an unexpected keyword argument 'dtype'

Code :

iris = datasets.load_iris()
Y=[]
for y in iris.target:
    tmp = np.zeros(3)
    tmp[y] = 1
    Y.append(tmp)

x_train, x_test, y_train, y_test = train_test_split(iris.data, Y, test_size=0.1)

K=5
indices = rnd.sample(range(len(x_train)), K)
model = Sequential()
f_layer = FuzzyLayer(K, initializer_centers=lambda x: np.transpose(np.array([x_train[i] for i in indices])), input_dim=4)
model.add(f_layer)

The code is from https://github.com/kenoma/KerasFuzzy/blob/master/KerasFuzzy/case5_iris_dataset.py . I am running same code but getting error.

Keras version -2.8.0. I have tried with lower versions also but getting same error.



Solution 1:[1]

This problem caused by deprecated layer initialization procedure in Keras prior 2.1.6.

As author of KerasFuzzy I have updated codebase to support newer versions of Keras.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 kenoma