keras

Keras Model - Get input in custom loss function

走远了吗. 提交于 2021-01-28 10:12:04
问题 I am having trouble with Keras Custom loss function. I want to be able to access truth as a numpy array. Because it is a callback function, I think I am not in eager execution , which means I can't access it using the backend.get_value() function. i also tried different methods, but it always comes back to the fact that this 'Tensor' object doesn't exist. Do I need to create a session inside the custom loss function ? I am using Tensorflow 2.2, which is up to date. def custom_loss(y_true, y

Difference between Keras and TensorFlow Hub Version of MobileNetV2

可紊 提交于 2021-01-28 09:50:32
问题 I am working on a transfer learning approach and got very different results when using the MobileNetV2 from keras.applications and the one available on TensorFlow Hub. This seems strange to me as both versions claim here and here to extract their weights from the same checkpoint mobilenet_v2_1.0_224. This is how the differences can be reproduced, you can find the Colab Notebook here: !pip install tensorflow-gpu==2.1.0 import tensorflow as tf import numpy as np import tensorflow_hub as hub

Shearing image in tensorflow

寵の児 提交于 2021-01-28 09:26:07
问题 I am using tf.keras to build my network. And I am doing all the augmentation in tensor_wise level since my data in tfrecords file. Then I needed to do shearing and zca for augmentation but couldn't find a proper implementation in tensor flow. And I can't use the DataImageGenerator that did both operation I needed because as I said my data doesn't fit in memory and it is in tfrecord format. So all my augmentations process should be tesnorwise. @fchollet here suggested a way to use

Shearing image in tensorflow

主宰稳场 提交于 2021-01-28 09:25:02
问题 I am using tf.keras to build my network. And I am doing all the augmentation in tensor_wise level since my data in tfrecords file. Then I needed to do shearing and zca for augmentation but couldn't find a proper implementation in tensor flow. And I can't use the DataImageGenerator that did both operation I needed because as I said my data doesn't fit in memory and it is in tfrecord format. So all my augmentations process should be tesnorwise. @fchollet here suggested a way to use

Keras ValueError: No gradients provided for any variable

£可爱£侵袭症+ 提交于 2021-01-28 09:01:14
问题 I've read related threads but not been able to solve my problem. I'm currently trying to get my model to run in order to classify 5000 different events, which all currently fall under the same category (so my "labels" dataset consists of 5000 1s). I'm using one hot encoding for my labels data set: labels = np.loadtxt("/content/drive/My Drive/5000labels1.csv") from keras.utils import to_categorical labels=to_categorical(labels) # convert labels to one-hot encoding I then define my model like

Keras CNN with 1D data

淺唱寂寞╮ 提交于 2021-01-28 08:31:25
问题 Every instance of my data is an array with 72 elements. I am trying to construct a 1D cnn to do some classification but I got this error: Error when checking target: expected dense_31 to have 3 dimensions, but got array with shape (3560, 1) This is my code: training_features = np.load('features.npy') training_labels = np.load('labels.npy') training_features = training_features.reshape(-1, 72, 1) model = Sequential() model.add(Conv1D(64, 3, activation='relu', input_shape=(72, 1))) model.add

Keras multiple input, output, loss model

强颜欢笑 提交于 2021-01-28 07:40:25
问题 I am working on super-resolution GAN and having some doubts about the code I found on Github. In particular, I have multiple inputs, multiple outputs in the model. Also, I have two different loss functions. In the following code will the mse loss be applied to img_hr and fake_features? # Build and compile the discriminator self.discriminator = self.build_discriminator() self.discriminator.compile(loss='mse', optimizer=optimizer, metrics=['accuracy']) # Build the generator self.generator =

How to predict a single image with Keras ImageDataGenerator?

∥☆過路亽.° 提交于 2021-01-28 07:22:15
问题 I have trained the CNN to classify images on 3 class. while training the model i have used ImageDataGenerator class from keras to apply preprocessing function on image and rescale it. Now my network is trained with a good accuracy on test set, but i don't know how to apply preprocessing function on single image prediction. If i use ImageDataGenerator it looks for directory. Suggest me some alternatives to do preprocessing function and rescaling on single image. see my code below TRAINING SET:

Keras dimension mismatch with ImageDataGenerator

折月煮酒 提交于 2021-01-28 07:13:41
问题 I am attempting to 'flow' my data into a neural network with Keras. I am using the .flow_from_directory method and the process is giving me fits. I am using the basic example from the keras documentation (I am using tensorflow): ROWS = 64 COLS = 64 CHANNELS = 3 from keras.preprocessing.image import ImageDataGenerator train_datagen = ImageDataGenerator( rescale=1./255) test_datagen = ImageDataGenerator(rescale=1./255) train_generator = train_datagen.flow_from_directory( 'train', target_size=

Keras: How to save models or weights?

╄→гoц情女王★ 提交于 2021-01-28 07:02:41
问题 I am sorry if this question seems pretty straight forward. But reading the Keras save and restore help page : https://www.tensorflow.org/beta/tutorials/keras/save_and_restore_models I do not understand how to use the "ModelCheckpoint" for saving during training. The help file mentions it should give 3 files, I see only one, MODEL.ckpt. Here is my code: checkpoint_dir = FolderName + "/tmp/model.ckpt" cp_callback = k.callbacks.ModelCheckpoint(checkpoint_dir,verbose=1,save_weights_only=True)