keras

Tensorflow 2.0 turn off tf.function retracing for prediction

|▌冷眼眸甩不掉的悲伤 提交于 2021-01-29 08:11:21
问题 I am trying to generate prediction intervals for a simple RNN using dropout. I'm using the functional API with training=True to enable dropout during testing. To try different dropout levels, I defined a small function to edit the model configs: from keras.models import Model, Sequential def dropout_model(model, dropout): conf = model.get_config() for layer in conf['layers']: if layer["class_name"]=="Dropout": layer["config"]["rate"] = dropout elif "dropout" in layer["config"].keys(): layer[

Compile error on keras sequential model with custom loss function

ε祈祈猫儿з 提交于 2021-01-29 07:54:48
问题 Trying to compile CNN model of ~16K parameters on GPU in google colab for mnist dataset. With standard loss 'categorical_crossentropy', it is working fine. But with custom_loss it is giving error. lamda=0.01 m = X_train.shape[0] def reg_loss(lamda): model_layers = custom_model.layers # type list where each el is Conv2D obj etc. reg_wts = 0 for idx, layer in enumerate(model_layers): layer_wts = model_layers[idx].get_weights() # type list if len(layer_wts) > 0: # activation, dropout layers do

Jupyter w/ Tensorflow pydotprint not found error

ⅰ亾dé卋堺 提交于 2021-01-29 07:52:16
问题 I'm using the tensorflow docker image run this way: docker run -it --rm -v $(realpath ~/Documents/notebooks):/tf/notebooks -p 8888:8888 tensorflow/tensorflow:latest-py3-jupyter I'm trying to generate dot files / plots of the model I've made, but all of the functions say: Failed to import pydot. You must install pydot and graphviz for pydotprint to work. At the top of my notebook, I have: !pip install pydot !pip install graphviz And I'm using Tensorflow 2.0.0 How do I get this to work?

In tensorflow, is it possible to see another models build structure?

时光毁灭记忆、已成空白 提交于 2021-01-29 06:59:33
问题 For example, if I load somebody else's model, this is what I see: I want to get the code representation of this, for example: model = Sequential() model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=input_shape)) model.add(Conv2D(64, (3, 3), activation='relu')) ... etc Not saying that the above is correct, but I want to know if there a way for me to physically reconstruct the model in code, including all activation functions? I guess I can read the summary, but I don't

Having trouble with CNN prediction

此生再无相见时 提交于 2021-01-29 06:25:12
问题 I am using Convolutional Neural Networking for vehicle identification, my first time. Currently, I am working with just 2 classes(bike and car). Training set: 420 car images and 825 bike images. Test set: 44 car images and 110 bike images Car and Bike images are in different format(bmp,jpg). In single prediction, I am always getting 'bike'. I have tried using the Sigmoid function in the output layer. Then I get only 'car'. My code is like following: `` from keras.models import Sequential from

Error when checking target: expected dense_1 to have shape (1,) but got array with shape (256,)

不羁岁月 提交于 2021-01-29 06:20:31
问题 I am trying to learn tensorflow, and I was following a demo tutorial (https://www.tensorflow.org/tutorials/keras/basic_text_classification) The error report is telling me "Error when checking target: expected dense_1 to have shape (1,) but got array with shape (256,)" Can someone explain to me why this won't work? train_data = keras.preprocessing.sequence.pad_sequences(train_data, value=word_index["<PAD>"], padding='post', maxlen=256) #max length test_data = keras.preprocessing.sequence.pad

Fitting array to datagen then passing as parameter to Keras Classifier

孤人 提交于 2021-01-29 06:11:04
问题 I have a convolutional neural network that i am using to classify cats and dogs, using keras classifier. I had to use custom cross validation, due to how my data is organized, where i have n groups of different breeds of cats and dogs and each breed has 200 images, 600 images per pet class. Now, what i am trying to do is create augmented data (on the fly/in place data augmentation) and concatenate them to my original array of groups. However i get the following error when i try to iterate

tf.keras.predict() is much slower than Keras predict()

橙三吉。 提交于 2021-01-29 06:03:24
问题 When using the Keras that comes embedded with Tensorflow (Tensorflow 2), I noticed a severe increase in computational time when using the predict() function from the Keras embedded inside Tensorflow and the predict() from standalone Keras. See the toy code below: import tensorflow import keras import numpy as np import time test = np.array([[0.1, 0.1, 0.1, 0.1, 0.1, 0.5, 0.1, 0., 0.1, 0.2]]) # Keras from inside Tensorflow model_1 = tensorflow.keras.Sequential([ tensorflow.keras.layers.Dense(1

Error defining an input shape in keras for (60000, 28, 28) array

大憨熊 提交于 2021-01-29 05:57:06
问题 I am setting up my first neural network with keras and tensorflow. I got my input into an array of shape (60000, 28, 28), but when I try and feed it to the model I get an error that the input shape is wrong. I have tried multiple different input shapes including (60000, 28, 28) (1, 28, 28) (28, 28) (28, 28, 1) but none of them seem to work. model = kr.Sequential() model.add(InputLayer(input_shape=(60000, 28, 28))) model.add(Dense(units=784, activation='relu')) model.add(Dense(units=392,

Tf 2: Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR

落爺英雄遲暮 提交于 2021-01-29 05:54:29
问题 I am getting the above error (Could not create cudnn handle: CUDNN_STATUS_INTERNAL_ERROR) when I execute the code below. I have cheked if my gpu is woking using tf.test.is_gpu_available # coding: utf-8 import tensorflow as tf import numpy as np import keras from models import * import os import gc TF_FORCE_GPU_ALLOW_GROWTH = True np.random.seed(1000) #Paths MODEL_CONF = "../models/conf/" MODEL_WEIGHTS = "../models/weights/" #Model informations N_CLASSES = 3 def load_array(name): return np