neural-network

keras layers tutorial and samples

断了今生、忘了曾经 提交于 2019-12-31 07:18:09
问题 I am trying to code and learn different neural network models. I am having a lot of complication with input dimensionality. I am looking for some tutorial that shows differences in layers and how to set input and outputs for each layers. 回答1: Keras documentation shows you all the input_shape s expected by each layer. In Keras, you'll see input shapes in these forms: input_shape defined by user in layers shapes shown in summaries and others array shapes tensor shapes Input shape defined by

Adding Dropout to testing/inference phase

心已入冬 提交于 2019-12-31 06:52:08
问题 I've trained the following model for some timeseries in Keras: input_layer = Input(batch_shape=(56, 3864)) first_layer = Dense(24, input_dim=28, activation='relu', activity_regularizer=None, kernel_regularizer=None)(input_layer) first_layer = Dropout(0.3)(first_layer) second_layer = Dense(12, activation='relu')(first_layer) second_layer = Dropout(0.3)(second_layer) out = Dense(56)(second_layer) model_1 = Model(input_layer, out) Then I defined a new model with the trained layers of model_1 and

How to extract weights “from input layer to hidden layer” and “from hidden layer to output layer” with Keras API?

会有一股神秘感。 提交于 2019-12-31 05:49:06
问题 I am new to Keras and I am trying to get the weights in Keras. I know how to do it in Tensorflow in Python. Code: data = np.array(attributes, 'int64') target = np.array(labels, 'int64') feature_columns = [tf.contrib.layers.real_valued_column("", dimension=2, dtype=tf.float32)] learningRate = 0.1 epoch = 10000 # https://www.tensorflow.org/api_docs/python/tf/metrics validation_metrics = { "accuracy": tf.contrib.learn.MetricSpec(metric_fn = tf.contrib.metrics.streaming_accuracy , prediction_key

CNN Keras: How many weights will be trained?

匆匆过客 提交于 2019-12-31 02:15:09
问题 I have a little comprehension problem with CNN. And I'm not quite sure how many filters and thus weights are trained. Example: I have an input layer with the 32x32 pixels and 3 channels (i.e. shape of (32,32,3) ). Now I use a 2D-convolution layer with 10 filters of shape (4,4) . So I end up with 10 channels each with shape of (28,28) , but do I now train a separate filter for each input channel or are they shared? Do I train 3x10x4x4 weights or do I train 10x4x4 weights? 回答1: You can find out

Cost function always returning zero for a binary classification in tensorflow

左心房为你撑大大i 提交于 2019-12-31 01:55:10
问题 I have written the following binary classification program in tensorflow that is buggy. The cost is returning to be zero all the time no matter what the input is. I am trying to debug a larger program which is not learning anything from the data. I have narrowed down at least one bug to the cost function always returning zero. The given program is using some random inputs and is having the same problem. self.X_train and self.y_train is originally supposed to read from files and the function

How to do point-wise categorical crossentropy loss in Keras?

风流意气都作罢 提交于 2019-12-30 18:27:04
问题 I have a network that produces a 4D output tensor where the value at each position in spatial dimensions (~pixel) is to be interpreted as the class probabilities for that position. In other words, the output is (num_batches, height, width, num_classes) . I have labels of the same size where the real class is coded as one-hot. I would like to calculate the categorical-crossentropy loss using this. Problem #1: The K.softmax function expects a 2D tensor (num_batches, num_classes) Problem #2 : I

keras/tensorflow model: gradient w.r.t. input return the same (wrong?) value for all input data

帅比萌擦擦* 提交于 2019-12-30 16:17:09
问题 Given a trained keras model I am trying to compute the gradient of the output with respect to the input. This example tries to fit the function y=x^2 with a keras model composed by 4 layers of relu activations, and compute the gradient of the model output with respect to the input. from keras.models import Sequential from keras.layers import Dense from keras import backend as k from sklearn.model_selection import train_test_split import numpy as np import tensorflow as tf # random data x = np

Keras flowFromDirectory get file names as they are being generated

萝らか妹 提交于 2019-12-30 07:54:32
问题 Is it possible to get the file names that were loaded using flow_from_directory ? I have : datagen = ImageDataGenerator( rotation_range=3, # featurewise_std_normalization=True, fill_mode='nearest', width_shift_range=0.2, height_shift_range=0.2, horizontal_flip=True ) train_generator = datagen.flow_from_directory( path+'/train', target_size=(224, 224), batch_size=batch_size,) I have a custom generator for my multi output model like: a = np.arange(8).reshape(2, 4) # print(a) print(train

Activation function for output layer for regression models in Neural Networks

泄露秘密 提交于 2019-12-30 07:53:16
问题 I have been experimenting with neural networks these days. I have come across a general question regarding the activation function to use. This might be a well known fact to but I couldn't understand properly. A lot of the examples and papers I have seen are working on classification problems and they either use sigmoid (in binary case) or softmax (in multi-class case) as the activation function in the out put layer and it makes sense. But I haven't seen any activation function used in the

Returning probabilities in a classification prediction in Keras?

≯℡__Kan透↙ 提交于 2019-12-30 06:22:52
问题 I am trying to make a simple proof-of-concept where I can see the probabilities of different classes for a given prediction. However, everything I try seems to only output the predicted class, even though I am using a softmax activation. I am new to machine learning, so I'm not sure if I am making a simple mistake or if this is a feature not available in Keras. I'm using Keras + TensorFlow. I have adapted one of the basic examples given by Keras for classifying the MNIST dataset. My code