keras

How to save keras custom model with dynamic input shape in SaveModel format?

南楼画角 提交于 2021-01-29 18:11:31
问题 I have a custom model with dynamic input shape (flexible second dimension). I need to save it in SaveModel format. But it saves only one signature (the first used). When I try to use different signature after loading - I am getting an error: Python inputs incompatible with input_signature My code is as follows: seq_len = 2 batch_size = 3 import tensorflow as tf class CustomModule(tf.keras.Model): def __init__(self): super(CustomModule, self).__init__() self.v = tf.Variable(1.) #@tf.function

During creating VAE model throws exception “you should implement a `call` method.”

扶醉桌前 提交于 2021-01-29 17:42:57
问题 I want to create VAE(variational autoencoder). During model creating it throws exception. When subclassing the Model class, you should implement a call method. I am using Tensorflow 2.0 def vae(): models ={} def apply_bn_and_dropout(x): return l.Dropout(dropout_rate)(l.BatchNormalization()(x)) input_image = l.Input(batch_shape=(batch_size,28,28,1)) x = l.Flatten()(input_image) x = l.Dense(256,activation="relu")(x) x = apply_bn_and_dropout(x) x = l.Dense(128,activation="relu")(x) x = apply_bn

how to Split data in 3 folds (train,validation,test) using ImageDataGenerator when data is in different directories of each class

China☆狼群 提交于 2021-01-29 17:34:53
问题 How do I split my data into 3 folds using ImageDataGenerator of Keras? ImageDataGenerator only gives validation_split argument so if I use it, I wont be having my test set for later purpose. My data is in the form of >input_data_dir >class_1_dir > image_1.png > image_2.png > class_2_dir > class_3_dir 回答1: As you rightly mentioned, splitting the Data into 3 Folds is not possible in one line of code using Keras ImageDataGenerator . Work around would be to store the Images corresponding to Test

Keras: Using model output as the input for another: When feeding symbolic tensors to a model, we expect thetensors to have a static batch size

我是研究僧i 提交于 2021-01-29 17:27:47
问题 I have the following two models, where model_A is trained first, then the output of model_A is used to train the model_C : import keras from keras.layers import Input, Dense from keras.models import Model inputs = Input(shape=(12,)) # --------------------------------------- # model_A x = Dense(64, activation='relu')(inputs) x = Dense(64, activation='relu')(x) predictions_A = Dense(3, activation='softmax')(x) model_A = Model(inputs=inputs, outputs=predictions_A) model_A.compile(optimizer=

Keras predict_classes method returns “list index out of range” error

∥☆過路亽.° 提交于 2021-01-29 17:11:06
问题 I am new to CNN and machine learning in general and have been trying to follow Image Classification tutorial of TensorFlow. Now, the Google Colab can be found here. I've followed the this official tutorial of TensorFlow. And I've changed it slightly so it saves the model as h5 instead of tf format so I can use the Keras' model.predict_classes . Now, I have the model trained and the model reloaded from the saved model alright. But I'm repeatedly getting list index out of range error whenever I

Using Tensorflow / Keras: Image manipulation inside tf.py_function

為{幸葍}努か 提交于 2021-01-29 16:43:37
问题 I'm using Tensorflow 2.0 / Keras to generate building footprints for a procedural city. I would like to feed in a source image representing a city 'block', and have the network return the predicted building foundations. Input / Output I've had some success using a pix2pix-like GAN architecture, but the output would ideally be a vector image rather than a bitmap. I've therefore been trying to implement a different model, where the input image is convolved down to a 32x32 tensor, converted to a

Keras sequential network: Attempt to convert a value (75) with an unsupported type (<class 'numpy.int32'>) to a Tensor

那年仲夏 提交于 2021-01-29 16:33:58
问题 I am attempting to predict the ideal move in a game using a keras sequential network. The network is fairly simple with (what I think to be) an input shape of (3216,). The code for defining the network is attached bellow. self.model = keras.Sequential() self.model.add(Dense(2000, activation='relu', input_dim=(2 * 7 + 2 + Cfg.tiles_x * Cfg.tiles_y))) self.model.add(Dense(1000, activation='relu')) self.model.add(Dense(100, activation='relu')) self.model.add(Dense(9)) self.model.compile(loss

Is it possible to see the output after Conv2D layer in Keras

一曲冷凌霜 提交于 2021-01-29 16:24:23
问题 I am trying to understand each layer of Keras while implementing CNN. In Conv2D layer i understand that it creates different convolution layer depending on various feature map values. Now, My question is that Can i see different feature map matrix that are applied on input image to get the convolution layer Can i see the value of matrix that is generated after completion of Conv2D step. Thanks in advance 回答1: You can get the output of a certain convolutional layer in this way: import keras

how to train model with batches

喜你入骨 提交于 2021-01-29 16:19:59
问题 I trying yolo model in python. To process the data and annotation I'm taking the data in batches. batchsize = 50 #boxList= [] #boxArr = np.empty(shape = (0,26,5)) for i in range(0, len(box_list), batchsize): boxList = box_list[i:i+batchsize] imagesList = image_list[i:i+batchsize] #to convert the annotation from VOC format convertedBox = np.array([np.array(get_boxes_for_id(box_l)) for box_l in boxList]) #pre-process on image and annotaion image_data, boxes = process_input_data(imagesList,max

How to integrate Tensorflow (Keras) model into Windows application for fast inference (pref C++ real-time)

陌路散爱 提交于 2021-01-29 16:15:55
问题 Suppose I have an existing Windows application (hello1.exe). Suppose I also have a tf.Keras neural net model trained and classifying test data. How do I take the latter "out of the lab" and deploy it in the "real world" by combining the two components something like this: > hello2.exe cat.jpg Hello World. BTW: the file 'cat.jpg' contains a cat That is, hello2.exe extends my existing hello1.exe by using the trained model to infer the contents of the input file. I don't mind if the input data