Categories
Mastering Development

Multiple output values on tensorflow [closed]

I want to make a tensorflow model that would return me 14400 values. I have input of shape (1, 7854) and output of shape (1, 14400). Using this data I get error: ValueError: Can not squeeze dim[1], expected a dimension of 1, got 14400 for ‘metrics/accuracy/Squeeze’ (op: ‘Squeeze’) with input shapes: [?,14400]. My code is: […]

Categories
Artificial Intelligence (AI) Development

Trouble with EarlyStopping in tf.keras

I am training my first transferred learning model(yay!) and I am having trouble getting the model to stop training when the validation loss hasn’t changed by more than 0.1 in more than 3 epochs. Here is the relevant block of code early_stopping = tf.keras.callbacks.EarlyStopping(monitor=’val_loss’, patience=3, min_delta = 0.1) model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’], callbacks=[early_stopping]) EPOCHS = 100 […]

Categories
Artificial Intelligence (AI) Development

High & Unexpected accuracy when training on one class and predicting on another

I’ve been trying to train my model on fashion images (fashion_mnist) and then according to that training, make predictions on digit images (mnist). (1) According to the printed plots, the model doesn’t recognize the digit very well (which is good), but – for some reason, the printed accuracy is pretty high 97%+, which doesn’t make […]

Categories
Development

.evaluate() method broken for CNN

I’ve been trying to evaluate a CNN model for a while now but I’m running into issues. Whenever I call the .evaluate method on it, my machine freezes for some time (if running on Jupyter notebook, kernel dies eventually following the freeze) and effectively no evaluation takes place. Does anyone have any idea as to […]

Categories
Development

TensorFlow with single output neuron

I’m fairly new to TensorFlow and I’ve been watching tutorials that use the mnist dataset to classify images. These videos (or the ones that I watched) have 10 output neurons corresponding to the class of each image. e.g. neuron 1 is Ankle boot; neuron 2 is Shirt… These neurons output a probability but what if […]

Categories
Development

Not able to evaluate the ML model created using Tensor Flow in PyCharm

I’m beginner in Python and ML. I was practising this Iris Data set to create a ML model using tensor flow 2.0. I parsed the csv and trained the model using the dataset. I’m able to get 90 % training accuracy and 91 % validation accuracy during my model creation. import tensorflow as tf import […]

Categories
Development

Failed to train with tf.keras.applications.MobileNetV2

Environment: TF2.0 Python 3.5 ubuntu 16.04 Problem: I try to use the pre-trained mobilenet_V2 but accuracy doesn’t increase: base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE, include_top=False, weights=’imagenet’) The script is copied from the tutorial of the tensorflow 2.0(https://www.tensorflow.org/tutorials/images/transfer_learning?hl=zh-cn) The only change I made is the dataset which feed into the network. The original code makes binary classification between dogs […]

Categories
Development

How to sovle audio signal problem by using 1D conv neural network in keras

I have a dataset (it is given and not a problem). all_speakers = np.unique([os.path.basename(i).split(‘_’)[1] for i in fsdd]) np.random.shuffle(all_speakers) train_speakers = all_speakers[:2] test_speakers = all_speakers[2:] print(“All speakers:”, all_speakers) print(“Train speakers:”, train_speakers) print(“Test speakers:”, test_speakers) train_files = [ i for i in fsdd if os.path.basename(i).split(‘_’)[1] in train_speakers ] test_files = [i for i in fsdd if […]

Categories
Development

Tensorflow: How to use tf.keras.metrics in multiclass classification?

I want to use some of these metrics when training my neural network: METRICS = [ keras.metrics.TruePositives(name=’tp’), keras.metrics.FalsePositives(name=’fp’), keras.metrics.TrueNegatives(name=’tn’), keras.metrics.FalseNegatives(name=’fn’), keras.metrics.Precision(name=’precision’), keras.metrics.Recall(name=’recall’), keras.metrics.CategoricalAccuracy(name=’acc’), keras.metrics.AUC(name=’auc’), ] BATCH_SIZE = 1024 SHUFFLE_BUFFER_SIZE = 4000 train_dataset = tf.data.Dataset.from_tensor_slices((sent_vectors, labels)) train_dataset = train_dataset.shuffle(SHUFFLE_BUFFER_SIZE).batch(BATCH_SIZE) model = tf.keras.Sequential() model.add(tf.keras.layers.Bidirectional(tf.keras.layers.LSTM(embed_dim))) for units in [256, 256]: model.add(tf.keras.layers.Dense(units, activation=’relu’)) model.add(tf.keras.layers.Dense(4, activation=’softmax’)) model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=METRICS) model.fit( […]

Categories
Development

Tensorflow 2.0 how to export predictions and training-mode from Keras model

I have a model sub-classed from tf.keras.model . I have write a call -and predict methods. when I export the model it seems that only the output from call method is serialized. The simple code to illustrate the problem is below class SimpleModel(tf.keras.Model): def __init__(self): super(SimpleModel, self).__init__() self.layer1 = keras.layers.Flatten(input_shape=(28, 28)) self.layer2 = keras.layers.Dense(128, activation=’relu’) […]