neural-network

Use layer output in keras custom loss

那年仲夏 提交于 2021-02-09 02:47:33
问题 I am developing a custom loss function in Keras and I need the first layer output. How can I retrieve it? def custom_loss(y_true, y_pred): cross = K.mean(K.binary_crossentropy(y_true, y_pred), axis = 1) layer_output = model.get_layer_output(1) # this is what i'd like to use return cross + perturb 回答1: Checking the docs you can retrieve a layer by using the model.get_layer() method. You can then pass the desired index or well pass the name of the layer. After getting a layer you can easily

Where is `_softmax_cross_entropy_with_logits` defined in tensorflow?

无人久伴 提交于 2021-02-08 14:00:09
问题 I am trying to see how softmax_cross_entropy_with_logits_v2() is implemented. It calls _softmax_cross_entropy_with_logits() . But I don't see where the latter is defined. Does anybody know how to locate its definition? $ ack '\b_softmax_cross_entropy_with_logits\b' tensorflow/compiler/tests/binary_ops_test.py 176: gen_nn_ops._softmax_cross_entropy_with_logits, tensorflow/python/kernel_tests/xent_op_test.py 52: loss, backprop = gen_nn_ops._softmax_cross_entropy_with_logits( 75: loss, backprop

Validation data batch_size of size one? (Keras)

≯℡__Kan透↙ 提交于 2021-02-08 07:19:47
问题 In Keras there is an option to set the size of the validation set batches to one: valid_batches = ImageDataGenerator().flow_from_directory(valid_path, ... batch_size=1) Is it correct that the model then just uses one object from the validation data to validate the model after each training data epoch? If that is the case then my model should not get a very good validation score. But when I run the model it runs without any problems, keeps improving and seems to be using many validation

Keras the simplest NN model: error in training.py with indices

允我心安 提交于 2021-02-08 06:14:31
问题 I have read this example https://github.com/fchollet/keras/blob/master/examples/mnist_mlp.py and decide to use this idea to my base because this is the simplest NN for Keras. This is my base https://drive.google.com/file/d/0B-B3QUQOzGZ7WVhzQmRsOTB0eFE/view (you can download my csv file, it's only 83Kb ) This is picture my base: base.shape = (891, 23) import keras from keras.datasets import mnist from keras.models import Sequential from keras.layers import Dense, Dropout from keras.optimizers

Keras the simplest NN model: error in training.py with indices

大城市里の小女人 提交于 2021-02-08 06:14:29
问题 I have read this example https://github.com/fchollet/keras/blob/master/examples/mnist_mlp.py and decide to use this idea to my base because this is the simplest NN for Keras. This is my base https://drive.google.com/file/d/0B-B3QUQOzGZ7WVhzQmRsOTB0eFE/view (you can download my csv file, it's only 83Kb ) This is picture my base: base.shape = (891, 23) import keras from keras.datasets import mnist from keras.models import Sequential from keras.layers import Dense, Dropout from keras.optimizers

TensorFlow: Neural Network accuracy always 100% on train and test sets

回眸只為那壹抹淺笑 提交于 2021-02-08 03:39:57
问题 I created a TensorFlow neural network that has 2 hidden layers with 10 units each using ReLU activations and Xavier Initialization for the weights. The output layer has 1 unit outputting binary classification (0 or 1) using the sigmoid activation function to classify whether it believes a passenger on the titanic survived based on the input features. (The only code omitted is the load_data function which populates the variables X_train, Y_train, X_test, Y_test used later in the program)

Cannot import multi_gpu_model from keras.utils

狂风中的少年 提交于 2021-02-08 03:28:05
问题 I have tensorflow-gpu 1.2.1 and keras on ubuntu 16.04. I am not able to perform: from kears.utils import multi_gpu_model Has anyone had success with multi_gpu_model as described in their documentation's FAQ section? I have a 4 GPU machine with 4 GeForce GTX 1080 Ti cards and want to use all of them. Here's the error I get: import keras.utils.multi_gpu_model --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last)

Get the loss that a given optimizer is minimizing in Tensorflow

冷暖自知 提交于 2021-02-07 14:49:42
问题 I am working in a unit test system for my tensorflow workspace and I would like to know if there is any method or attribute, given a graph with an optimizer operation (after calling .minimize()), to obtain the final loss tensor that it is optimizing and the variables that it controls. For example if I call train_op = tf.train.AdamOptimizer(1e-4).minimize(cross_entropy) I would like to retrieve cross_entropy only having access to train_op. I have access to the train_op object, I only want to

What does it mean to “break symmetry”? in the context of neural network programming? [duplicate]

限于喜欢 提交于 2021-02-07 14:24:22
问题 This question already has answers here : Why should weights of Neural Networks be initialized to random numbers? [closed] (9 answers) Closed last year . I have heard a lot about "breaking the symmetry" within the context of neural network programming and initialization. Can somebody please explain what this means? As far as I can tell, it has something to do with neurons performing similarly during forward and backward propagation if the weight matrix is filled with identical values during

Is fit_generator in Keras supposed to reset the generator after each epoch?

╄→гoц情女王★ 提交于 2021-02-07 14:22:22
问题 I am trying to use fit_generator with a custom generator to read in data that's too big for memory. There are 1.25 million rows I want to train on, so I have the generator yield 50,000 rows at a time. fit_generator has 25 steps_per_epoch , which I thought would bring in those 1.25MM per epoch. I added a print statement so that I could see how much offset the process was doing, and I found that it exceeded the max when it got a few steps into epoch 2. There are a total of 1.75 million records