LSTM-FCN icon indicating copy to clipboard operation
LSTM-FCN copied to clipboard

Work with Tensorflow 2.2.0 and built-in Keras: Exception has occurred: ValueError

Open krivenkoz opened this issue 5 years ago • 3 comments

Hi Titu! First of all many thanks for sharing RNN for TSC. It's very useful!

I'm using Tensorflow 2.2.0 and built-in Keras, so slightly change the code (for example, using 'from tensorflow.keras.models import Model' instead of 'from keras.models import Model') When i'm trying to run all_datasets_training.py, I've got next error in keras_utils.py (both Windows and Linux):

Exception has occurred: ValueError The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

It occurs in train_model function within row: model.fit(X_train, y_train, batch_size=batch_size, epochs=epochs, callbacks=callback_list, class_weight=class_weight, verbose=2, validation_data=(X_test, y_test))

The shape of input data (GunPoint): X_train [50, 1 , 150] X_test [150, 1, 150]

What am I do wrong? image_2020_07_03T12_47_01_333Z

krivenkoz avatar Jul 03 '20 12:07 krivenkoz

It seems the problem is in class_weight. It should be a dict instead of ndarray. Am I right?

krivenkoz avatar Jul 07 '20 13:07 krivenkoz

Hello @krivenkoz,

If you have finally been able it run the whole code in TF2.2, could you please share it? I have been struggling with this for a week now. Thanks in advance.

mzeeshanarshad avatar Nov 02 '20 08:11 mzeeshanarshad

Hello! i solve this issue. I changed part of the code in utils/keras_utils.py. And my code works well. Screenshot from 2021-01-19 00-52-50

` from sklearn.utils import class_weight as cw

class_weight = cw.compute_class_weight('balanced',classes,y_ind) class_weight = {i : class_weight[i] for i in range(len(le.classes_))} #class_weight = recip_freq[le.transform(classes)] #print(type(recip_freq)) #print(type(class_weight)) print("Class weights : ", class_weight) `

seokho-1116 avatar Jan 18 '21 15:01 seokho-1116