keras-2

restore_best_weights issue keras early stopping

两盒软妹~` 提交于 2020-07-08 05:25:06
问题 I am using EarlyStopping from Keras for my deep learning project. The documentations here mentions a very useful idea of restoring best weights. But somehow I am not able to use it yet. I am using Keras 2.2.2/TF 1.10, installed using Anaconda. Call is simple as follows. is there any issue? es = EarlyStopping(monitor='val_acc', min_delta=1e-4, patience=patience_,verbose=1,restore_best_weights=True) __init__() got an unexpected keyword argument 'restore_best_weights' 回答1: Ah, a very common

How do I load a keras saved model with custom Optimizer

拥有回忆 提交于 2020-05-14 18:24:09
问题 I have compiled and trained a keras model with a custom optimizer. I saved the model but when I try to load the model, it throws an error stating ValueError: Unknown optimizer: MyOptimizer . I tried to pass MyOptimizer as a custom object something like : models.load_model('myModel.h5', custom_objects={'optimizer':MyOptimizer}) and it still throws an error. How do I load the model a keras model with custom Objects? 回答1: I ran into the same problem :) I made it work by loading the model with

Keras for semantic segmentation, flow_from_directory() error

我怕爱的太早我们不能终老 提交于 2020-03-03 01:59:22
问题 I was attempting to use my modification of the example code in the Keras documentation that shows how to set up image_datagen.flow_from_directory() in the case where image masks are being used in place of labels (for image segmentation, where we are predicting a class for each pixel). By the way, I set featurewise_center = True in an attempt to subtract the mean of each color channel of all the training images from each image's color channels, so that over the entire training set, each color

validation accuracy is 0 with Keras fit_generator

给你一囗甜甜゛ 提交于 2020-02-25 04:40:28
问题 I recently upgraded to Keras 2.2.2. The validation accuracy is zero for all training epochs. My training data has data samples in 2 categories i.e., train_data_dir has 2 subfolders. My validation data (i.e., val_data_dir) has data samples in 1 category only but it contains 2 subfolders (one for each category) with no data samples in one of the subfolders. I used to get a meaningful non-zero value for the validation accuracy with an earlier version of Keras. Please help me spot the issue my

Keras Multi-inputs AttributeError: 'NoneType' object has no attribute 'inbound_nodes'

房东的猫 提交于 2020-02-01 03:27:30
问题 I'm trying to build a model as ilustrated in below diagram. The idea is to take more than one categorical features (one-hot vectors) and embed them separately, then combine those embedded vectors with a 3D tensor for a LSTM. With following code in Keras2.0.2 , when creating the Model() object with multiple inputs, it raises an AttributeError: 'NoneType' object has no attribute 'inbound_nodes' similar to this question. Can anyone help me to figure out what's the problem? Model: Code: from

Getting x_test, y_test from generator in Keras?

假如想象 提交于 2020-01-14 01:36:09
问题 For certain problems, the validation data can't be a generator, e.g.: TensorBoard histograms: If printing histograms, validation_data must be provided, and cannot be a generator. My current code looks like: image_data_generator = ImageDataGenerator() training_seq = image_data_generator.flow_from_directory(training_dir) validation_seq = image_data_generator.flow_from_directory(validation_dir) testing_seq = image_data_generator.flow_from_directory(testing_dir) model = Sequential(..) # .. model

Keras doesn't train using fit_generator()

血红的双手。 提交于 2020-01-07 04:20:11
问题 I am using Keras 2.0.4 (TensorFlow backend) for an image classification task. I am trying to train my own network (without any pretrained parameters). As my data is huge I cannot load all into memory. For this reason I use ImageDataGenerator() , flow_from_directory() and fit_generator() . Creating ImageDataGenerator object: train_datagen = ImageDataGenerator(preprocessing_function = my_preprocessing_function) # only preprocessing; no augmentation; static data set my_preprocessing_function

Convert code from Keras 1 to Keras 2: TypeError: __call__() missing 1 required positional argument: 'shape'

◇◆丶佛笑我妖孽 提交于 2020-01-05 07:49:37
问题 I am trying to convert a V-net code that was written in Keras 1 into Keras 2. It seems that I have an issue with the following class: class Deconv3D(Layer): def __init__(self, nb_filter, kernel_dims, output_shape, strides): assert K.backend() == 'tensorflow' self.nb_filter = nb_filter self.kernel_dims = kernel_dims self.strides = (1,) + strides + (1,) self.output_shape_ = output_shape super(Deconv3D, self).__init__() def build(self, input_shape): assert len(input_shape) == 5 self.input_shape_

Binarize tensor in Keras

落花浮王杯 提交于 2020-01-04 05:36:10
问题 I need to create a loss function for Keras that works with only binary values. In wanted for to transform all the values greater than 0.5 to 1.0, so I did that: def MyLoss(y_true, y_pred: y_true_f = K.flatten(y_true) y_pred_f = K.flatten(K.cast(K.greater(y_pred, 0.5), 'float32')) #y_pred_f = K.flatten(K.cast(y_pred > 0.5), 'float32') #y_pred_f = K.flatten(y_pred > 0.5) return K.sum(y_true_f * y_pred_f) The code compiles, but later it generates the following error: ValueError: None values not

Can not save model using model.save following multi_gpu_model in Keras

懵懂的女人 提交于 2020-01-01 05:32:31
问题 Following the upgrade to Keras 2.0.9, I have been using the multi_gpu_model utility but I can't save my models or best weights using model.save('path') The error I get is TypeError: can’t pickle module objects I suspect there is some problem gaining access to the model object. Is there a work around this issue? 回答1: Workaround Here's a patched version that doesn't fail while saving: from keras.layers import Lambda, concatenate from keras import Model import tensorflow as tf def multi_gpu