There are 2 ways to get the output of an intermediate area, as posted here on this... moreThere are 2 ways to get the output of an intermediate area, as posted here on this forum:https://www.cluzters.ai/forums/topic/353/keras-how-to-get-the-output-of-each-layer?c=1597You don't need (or want) both of these, either works:
get_layer_output = K.function([model.layers, [model.layers)
layer_output = get_layer_output()
or
tmp_model = Model(model.layers.input, model.layers.output)
tmp_output = tmp_model.predict(x_train)
This works well for a smaller model, but I always get OOM if my model is too large. Is there an easy way to free the GPU memory of the original model before creating tmp_model or calling get_layer_output? I can save my weights to a text file and create another program in another session, but it seems like there should be an easier way. less
I copied and pasted tensorflow's official Basic classification: Classify images of clothing code https://www.tensorflow.org/tutorials/keras/classification
import tensorflow as... moreI copied and pasted tensorflow's official Basic classification: Classify images of clothing code https://www.tensorflow.org/tutorials/keras/classification
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images, test_labels) = fashion_mnist.load_data()
and ran it. Upon running it printed a load of gibberish and wouldn't stop (almost like when you accidentally put a print in a while loop):
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz
so I terminated it. The above is just a VERY small portion of what printed. I ran it again, only to get an error straight away.
line 7, in <module>
(train_images, train_labels), (test_images,... less
I have two question:
(1) The question about importing some subpackages inside tensorflow.keras.
(2) How to differentiate between the packages installed by 'pip install' and 'conda... moreI have two question:
(1) The question about importing some subpackages inside tensorflow.keras.
(2) How to differentiate between the packages installed by 'pip install' and 'conda install'.(under windows)
I am using anaconda with tensorflow 2.0.0. I am trying to import package like:
import tensorflow.keras.utils.np_utils
However, the error shown that:
---------------------------------------------------------------------------
> ModuleNotFoundError Traceback (most recent call
> last) <ipython-input-2-ee1bc59a14ab> in <module>
> ----> 1 import tensorflow.keras.utils.np_utils
>
> ModuleNotFoundError: No module named 'tensorflow.keras.utils.np_utils'
I am confused about why this is happening, I install the tensorflow with command:
conda install tensorflow==2.0.0
from Anaconda prompt.
Yes, I know the anaconda should have already had all the data science package inside it, the reason that I uninstall tensorflow provided by anaconda and reinstall it was before using... less
I'm trying to train a word embedding classifier using TF2.4 with Keras and using the tf.nn.sampled_softmax_loss. However, when calling the fit method of the model, "Cannot convert... moreI'm trying to train a word embedding classifier using TF2.4 with Keras and using the tf.nn.sampled_softmax_loss. However, when calling the fit method of the model, "Cannot convert a symbolic Keras input/output to a numpy array" TypeError occurs. Please help me to fix the error or with an alternative approach to do candidate sampling.
import tensorflow as tf
import numpy as np
In the Tensorflow ML Basics with Keras tutorial for making a basic text classification, when preparing the trained model for export, the tutorial suggests including the... moreIn the Tensorflow ML Basics with Keras tutorial for making a basic text classification, when preparing the trained model for export, the tutorial suggests including the TextVectorization layer into the Model so it can "process raw strings". I understand why to do this.
But then the code snippet is:
export_model = tf.keras.Sequential()
Why when preparing the model for export, does the tutorial also include a new activation layer layers.Activation('sigmoid')? Why not incorporate this layer into the original model? less
I am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.Here is what I did.In Anaconda, I created an... moreI am trying to do some deep learning work. For this, I first installed all the packages for deep learning in my Python environment.Here is what I did.In Anaconda, I created an environment called tensorflow as follows
conda create -n tensorflow
Then installed the data science Python packages, like Pandas, NumPy, etc., inside it. I also installed TensorFlow and Keras there. Here is the list of packages in that environment
(tensorflow) SFOM00618927A:dl i854319$ conda list
# packages in environment at /Users/i854319/anaconda/envs/tensorflow:
#
appdirs 1.4.3 <pip>
appnope 0.1.0 py36_0
beautifulsoup4 4.5.3 py36_0
bleach 1.5.0 py36_0
cycler 0.10.0 py36_0
decorator 4.0.11 py36_0
entrypoints 0.2.2 py36_1
freetype 2.5.5 ... less
I'm new to TensorFlow and Data Science. I made a simple module that should figure out the relationship between input and output numbers. In this case, x and x squared. The code in... moreI'm new to TensorFlow and Data Science. I made a simple module that should figure out the relationship between input and output numbers. In this case, x and x squared. The code in Python:
import numpy as np
import tensorflow as tf
# TensorFlow only log error messages.
tf.logging.set_verbosity(tf.logging.ERROR)
model = tf.keras.Sequential([
tf.keras.layers.Dense(units = 1, input_shape = )
model.compile(loss = "mean_squared_error", optimizer = tf.keras.optimizers.Adam(0.0001))
model.fit(features, labels, epochs = 50000, verbose = False)
print(model.predict())
I tried a different number of units, and adding more layers, and even using the relu activation function, but the results were always wrong. It works with other relationships like x and 2x. What is the problem here? less
I am trying to follow this tutorial: https://medium.com/@natu.neeraj/training-a-keras-model-on-google-cloud-ml-cb831341c196to upload and train a Keras model on Google Cloud... moreI am trying to follow this tutorial: https://medium.com/@natu.neeraj/training-a-keras-model-on-google-cloud-ml-cb831341c196to upload and train a Keras model on Google Cloud Platform, but I can't get it to work.Right now I have downloaded the package from GitHub, and I have created a cloud environment with AI-Platform and a bucket for storage.I am uploading the files (with the suggested folder structure) to my Cloud Storage bucket (basically to the root of my storage), and then trying the following command in the cloud terminal:
gcloud ai-platform jobs submit training JOB1
--module-name=trainer.cnn_with_keras
--package-path=./trainer
--job-dir=gs://mykerasstorage
--region=europe-north1
--config=gs://mykerasstorage/trainer/cloudml-gpu.yaml
But I get errors, first the cloudml-gpu.yaml file can't be found, it says "no such folder or file", and trying to just remove it, I get errors because it says the --init--.py file is missing, but it isn't, even if it is empty (which it... less
*I try to install tensorflow and kerasI installed tensorflow and I imported it with no errorsKeras is installed but I can't import it *
(base) C:\Windows\system32>pip uninstall... more*I try to install tensorflow and kerasI installed tensorflow and I imported it with no errorsKeras is installed but I can't import it *
(base) C:\Windows\system32>pip uninstall keras
Found existing installation: Keras 2.3.1
Uninstalling Keras-2.3.1:
Would remove:
c:\users\asus\anaconda3\anaconda\lib\site-packages\docs\*
c:\users\asus\anaconda3\anaconda\lib\site-packages\keras-2.3.1.dist-info\*
c:\users\asus\anaconda3\anaconda\lib\site-packages\keras\*
Proceed (y/n)? y
Successfully uninstalled Keras-2.3.1
(base) C:\Windows\system32>pip install keras
Collecting keras
Using cached Keras-2.3.1-py2.py3-none-any.whl (377 kB)
Requirement already satisfied: six>=1.9.0 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.14.0)
Requirement already satisfied: numpy>=1.9.1 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras) (1.18.4)
Requirement already satisfied: keras-applications>=1.0.6 in c:\users\asus\anaconda3\anaconda\lib\site-packages (from keras)... less
I would like to know How to apply gradient clipping on this network on the RNN where there is a possibility of exploding gradients.
tf.clip_by_value(t, clip_value_min,... moreI would like to know How to apply gradient clipping on this network on the RNN where there is a possibility of exploding gradients.
tf.clip_by_value(t, clip_value_min, clip_value_max, name=None)
This is an example that could be used but where do I introduce this ? In the def of RNN
lstm_cell = rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
# Split data because rnn cell needs a list of inputs for the RNN inner loop
_X = tf.split(0, n_steps, _X) # n_steps
tf.clip_by_value(_X, -1, 1, name=None)
But this doesn't make sense as the tensor _X is the input and not the grad what is to be clipped?
Do I have to define my own Optimizer for this or is there a simpler option? less
I don't understand which accuracy in the output to use to compare my 2 Keras models to see which one is better.
Do I use the "acc" (from the training data?) one or the "val acc"... moreI don't understand which accuracy in the output to use to compare my 2 Keras models to see which one is better.
Do I use the "acc" (from the training data?) one or the "val acc" (from the validation data?) one?
There are different accs and val accs for each epoch. How do I know the acc or val acc for my model as a whole? Do I average all of the epochs accs or val accs to find the acc or val acc of the model as a whole?Model 1 Output
Train on 970 samples, validate on 243 samples
Epoch 1/20
0s - loss: 0.1708 - acc: 0.7990 - val_loss: 0.2143 - val_acc: 0.7325
Epoch 2/20
0s - loss: 0.1633 - acc: 0.8021 - val_loss: 0.2295 - val_acc: 0.7325
Epoch 3/20
0s - loss: 0.1657 - acc: 0.7938 - val_loss: 0.2243 - val_acc: 0.7737
Epoch 4/20
0s - loss: 0.1847 - acc: 0.7969 - val_loss: 0.2253 - val_acc: 0.7490
Epoch 5/20
0s - loss: 0.1771 - acc: 0.8062 - val_loss: 0.2402 - val_acc: 0.7407
Epoch 6/20
0s - loss: 0.1789 - acc: 0.8021 - val_loss: 0.2431 - val_acc: 0.7407
Epoch 7/20
0s - loss: 0.1789 - acc: 0.8031 -... less
I am training on 970 samples and validating on 243 samples.
How big should batch size and number of epochs be when fitting a model in Keras to optimize the val_acc? Is there any... moreI am training on 970 samples and validating on 243 samples.
How big should batch size and number of epochs be when fitting a model in Keras to optimize the val_acc? Is there any sort of rule of thumb to use based on data input size?
If I want to use the BatchNormalization function in Keras, then do I need to call it once only at the beginning?
I read this documentation for... moreIf I want to use the BatchNormalization function in Keras, then do I need to call it once only at the beginning?
I read this documentation for it: http://keras.io/layers/normalization/
I don't see where I'm supposed to call it. Below is my code attempting to use it:
model = Sequential()
keras.layers.normalization.BatchNormalization(epsilon=1e-06, mode=0, momentum=0.9, weights=None)
model.add(Dense(64, input_dim=14, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(64, init='uniform'))
model.add(Activation('tanh'))
model.add(Dropout(0.5))
model.add(Dense(2, init='uniform'))
model.add(Activation('softmax'))
I trained my CNN (VGG) through google colab and generated .h5 file. Now problem is, I can predict my output successfully through google colab but when i download that .h5 trained... moreI trained my CNN (VGG) through google colab and generated .h5 file. Now problem is, I can predict my output successfully through google colab but when i download that .h5 trained model file and try to predict output on my laptop, I am getting error when loading the model.
Here is the code:
import tensorflow as tf
from tensorflow import keras
import h5py
I am working on training a VGG16-like model in Keras, on a 3 classes subset from Places205, and encountered the following error:
ValueError: Error when checking target: expected... moreI am working on training a VGG16-like model in Keras, on a 3 classes subset from Places205, and encountered the following error:
ValueError: Error when checking target: expected dense_3 to have shape (3,) but got array with shape (1,)
I read multiple similar issues but none helped me so far. The error is on the last layer, where I've put 3 because this is the number of classes I'm trying right now.
The code is the following:
import keras from keras.datasets
import cifar10 from keras.preprocessing.image
import ImageDataGenerator from keras.models
import Sequential
from keras.layers import Dense, Dropout, Activation, Flatten from keras.layers import Conv2D, MaxPooling2D
from keras import backend as K import os
I have trained a binary classification model with CNN, and here is my code
model = Sequential()
model.add(Convolution2D(nb_filters, kernel_size, kernel_size,
... moreI have trained a binary classification model with CNN, and here is my code
model = Sequential()
model.add(Convolution2D(nb_filters, kernel_size, kernel_size,
border_mode='valid',
input_shape=input_shape))
model.add(Activation('relu'))
model.add(Convolution2D(nb_filters, kernel_size, kernel_size))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
# (16, 16, 32)
model.add(Convolution2D(nb_filters*2, kernel_size, kernel_size))
model.add(Activation('relu'))
model.add(Convolution2D(nb_filters*2, kernel_size, kernel_size))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=pool_size))
# (8, 8, 64) = (2048)
model.add(Flatten())
model.add(Dense(1024))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(2)) # define a binary classification problem
model.add(Activation('softmax'))
model.compile(loss='categorical_crossentropy',
optimizer='adadelta',
metrics=)
model.fit(x_train,... less
I'm trying to predict age from a given picture. I built the model below but the problem is that I'm getting very large loss value with low accuracy while fitting the model.I... moreI'm trying to predict age from a given picture. I built the model below but the problem is that I'm getting very large loss value with low accuracy while fitting the model.I think the problem is choosing the wrong loss function (here mean_squared_error). What can be the problem here?import tensorflow as tffrom tensorflow import kerasX = X.reshape(-1, image_size, image_size, 1)model = keras.models.Sequential()model.add(keras.layers.Conv2D(32, (5, 5), activation='relu', input_shape=X.shape))model.add(keras.layers.MaxPooling2D((2, 2)))model.add(keras.layers.Conv2D(32, (3, 3), activation='relu'))model.add(keras.layers.MaxPooling2D(2, 2))model.add(keras.layers.Conv2D(64, (3, 3), activation='relu'))model.add(keras.layers.Flatten())model.add(keras.layers.Dense(60, activation='relu'))model.add(keras.layers.Dropout(0.4))model.add(keras.layers.Dense(1, activation='softmax'))model.compile(optimizer='adam', loss=keras.losses.mean_squared_error, metrics=)model.fit(X, Y, epochs=170, shuffle=True,... less