keras

How to plot a confusion matrix

How to plot a confusion matrix Question: I am trying to evaluate my renet50 model with a confusion matrix, but the confusion matrix looks like this: matrix = confusion_matrix(y_test, y_pred, normalize="pred") print(matrix) # output array([[1, 0], [1, 2]], dtype=int64) I am using scikit-learn for generating the confusion matrix and tf keras for making the model …

Total answers: 2

I am trying to build a variational autoencoder. I am getting an error while running model.fit which I don't understand

I am trying to build a variational autoencoder. I am getting an error while running model.fit which I don't understand Question: Epoch 1/10 ————————————————————————— TypeError Traceback (most recent call last) <ipython-input-28-f82b6d9aa841> in <cell line: 2>() 1 # Train model —-> 2 model.fit(X_train, y_train, epochs=10, batch_size=16, validation_data=(X_val, y_val)) 1 frames /usr/local/lib/python3.9/dist-packages/keras/engine/training.py in tf__train_function(iterator) 13 try: 14 …

Total answers: 1

TypeError: Sequential.__init__() takes from 1 to 3 positional arguments but 4 were given

TypeError: Sequential.__init__() takes from 1 to 3 positional arguments but 4 were given Question: Am not able to declare the model due to problems in input_shape input_shape = [x_train_scaled.shape[1]] input_shape Output – [6] model = tf.keras.Sequential( tf.keras.layers.Dense(units=64, input_shape=input_shape, activation=’relu’), tf.keras.layers.Dense(units=64, activation=’relu’), tf.keras.layers.Dense(units=1) ) model.summary() Error shown : TypeError: Sequential.init() takes from 1 to 3 positional …

Total answers: 1

Can't Initialise Two Different Tokenizers with Keras

Can't Initialise Two Different Tokenizers with Keras Question: For spelling correction task, I build a seq2seq model including LSTM and attention mechanism. I do char-level tokenisation with Keras. I initialised two different tokenizers, one for typo sentence and the other for corrected sentence. After testing, I see that model produced empty string and I believe …

Total answers: 1

TypeError: Unhashable type: 'numpy.ndarray' in keras

TypeError: Unhashable type: 'numpy.ndarray' in keras Question: I have a code below while True: question = input("你: ") question_seq = tokenizer.texts_to_sequences([question]) question_seq_padded = keras.preprocessing.sequence.pad_sequences(question_seq, maxlen=max_len) answer_seq = model.predict(question_seq_padded).argmax(axis=-1)[0] answer = tokenizer.index_word[answer_seq] print("機器人:", answer) And when i ran it, happened some wrong answer = tokenizer.index_word[answer_seq] issued error TypeError: Unhashable type: ‘numpy.ndarray’ I try to find the …

Total answers: 2

how regroup multiple fit calls on a single epoche with keras

how regroup multiple fit calls on a single epoche with keras Question: I am training a model with kearas on Go of datas, at a point where my computer can’t handle the RAM needed. So I am trying to implement my training as 1 epoche is done with multiple model.fit calls, with somthing like : …

Total answers: 2

TensorFlow results are not reproducible despite using tf.random.set_seed

TensorFlow results are not reproducible despite using tf.random.set_seed Question: According to a tutorial on Tensorflow I am following, the following code is supposed to give reproducible results, so one can check if the exercise is done correctly. Tensorflow version is 2.11.0. import tensorflow as tf import numpy as np class MyDenseLayer(tf.keras.layers.Layer): def __init__(self, n_output_nodes): super(MyDenseLayer, …

Total answers: 1

How to verify if the tensorflow code trains completely in FP16?

How to verify if the tensorflow code trains completely in FP16? Question: I’m trying to train a TensorFlow (version 2.11.0) code in float16. I checked that FP16 is supported on the RTX 3090 GPU. So, I followed the below link to train the whole code in reduced precision. https://www.tensorflow.org/api_docs/python/tf/keras/backend/set_floatx Then, When I was testing the …

Total answers: 1

Class imported from a local module cannot find the definition of a variable declared in the same module, Python

Class imported from a local module cannot find the definition of a variable declared in the same module, Python Question: I have this piece of code defined in the model_utils.py local module. import os os.environ[‘TF_CPP_MIN_LOG_LEVEL’] = ‘3’ os.environ["SM_FRAMEWORK"] = "tf.keras" import segmentation_models as sm import matplotlib.pyplot as plt import tensorflow_io as tfio import tensorflow as …

Total answers: 1

tf.keras.utils.get_file error: TypeError: '<' not supported between instances of 'int' and 'NoneType'

tf.keras.utils.get_file error: TypeError: '<' not supported between instances of 'int' and 'NoneType' Question: everyone, Recently I start to program with tensorflow 2.10.0, have the following codes in my ipynb file (Jupyter Notebook file): if not data_dir.exists(): tf.keras.utils.get_file(‘free-spoken-digit-dataset-master.zip’,origin="https://codeload.github.com/Jakobovski/free-spoken-digit-dataset/zip/refs/heads/master",extract=True,cache_dir=’.’,cache_subdir=’data’) I want to download the file free-spoken-digit-dataset-master.zip from the URL https://codeload.github.com/Jakobovski/free-spoken-digit-dataset/zip/refs/heads/master, after running the codes the following error …

Total answers: 2