neural-network

Using Multiple GPUs outside of training in PyTorch

邮差的信 提交于 2021-02-19 08:46:06
问题 I'm calculating the accumulated distance between each pair of kernel inside a nn.Conv2d layer. However for large layers it runs out of memory using a Titan X with 12gb of memory. I'd like to know if it is possible to divide such calculations across two gpus. The code follows: def ac_distance(layer): total = 0 for p in layer.weight: for q in layer.weight: total += distance(p,q) return total Where layer is instance of nn.Conv2d and distance returns the sum of the differences between p and q. I

How does the Tensorflow's TripletSemiHardLoss and TripletHardLoss and how to use with Siamese Network?

半腔热情 提交于 2021-02-19 08:37:18
问题 As much as I know that Triplet Loss is a Loss Function which decrease the distance between anchor and positive but decrease between anchor and negative. Also, there is a margin added to it. So for EXAMPLE LEt us Suppose: a Siamese Network , which gives embeddings: anchor_output = [1,2,3,4,5...] # embedding given by the CNN model positive_output = [1,2,3,4,4...] negative_output= [53,43,33,23,13...] And I think I can get the triplet loss such as: (I think I have to make it as loss using Lambda

Keras: Wrong Input Shape in LSTM Neural Network

我是研究僧i 提交于 2021-02-19 08:26:35
问题 I am trying to train an LSTM recurrent neural network, for sequence classification. My data has the following formart: Input: [1,5,2,3,6,2, ...] -> Output: 1 Input: [2,10,4,6,12,4, ...] -> Output: 1 Input: [4,1,7,1,9,2, ...] -> Output: 2 Input: [1,3,5,9,10,20, ...] -> Output: 3 . . . So basically I want to provide a sequence as an input and get an integer as an output. Each input sequence has length = 2000 float numbers, and I have around 1485 samples for training The output is just an

Checking the gradient when doing gradient descent

允我心安 提交于 2021-02-19 08:22:32
问题 I'm trying to implement a feed-forward backpropagating autoencoder (training with gradient descent) and wanted to verify that I'm calculating the gradient correctly. This tutorial suggests calculating the derivative of each parameter one at a time: grad_i(theta) = (J(theta_i+epsilon) - J(theta_i-epsilon)) / (2*epsilon) . I've written a sample piece of code in Matlab to do just this, but without much luck -- the differences between the gradient calculated from the derivative and the gradient

Checking the gradient when doing gradient descent

血红的双手。 提交于 2021-02-19 08:22:12
问题 I'm trying to implement a feed-forward backpropagating autoencoder (training with gradient descent) and wanted to verify that I'm calculating the gradient correctly. This tutorial suggests calculating the derivative of each parameter one at a time: grad_i(theta) = (J(theta_i+epsilon) - J(theta_i-epsilon)) / (2*epsilon) . I've written a sample piece of code in Matlab to do just this, but without much luck -- the differences between the gradient calculated from the derivative and the gradient

How to desig MLP neural network in Matlab?

杀马特。学长 韩版系。学妹 提交于 2021-02-19 08:22:11
问题 Hi I've design the XOR with a three layered Neural Network. Now I have a new problem similar to xor but still I can't figure out how to solve it . Here's the problem : I want to distinguish the red area from blue area.As you can I have an area of -1 to 1 vertically and -1 to 1 horizontally. can any body give me a clue? or some sort of sample code or network configuration in matlab? 回答1: I had a similar task when I was learning about the ANN concept, I will share the code with you that

Keras Regression to approximate function (goal: loss < 1e-7)

六眼飞鱼酱① 提交于 2021-02-19 07:30:08
问题 I'm working on a neural network which approximates a function f(X)=y, with X a vector [x0, .., xn] and y in [-inf, +inf]. This approximated function needs to have an accuracy (sum of errors) around 1e-8. In fact, I need my neural network to overfit. X is composed of random points in the interval -500 and 500. Before putting these points into the input layer I normalized them between [0, 1]. I use keras as follow: dimension = 10 #example self.model = Sequential() self.model.add(Dense(128,

How many epochs does it take to train VGG-16

。_饼干妹妹 提交于 2021-02-19 06:38:04
问题 I'm training a VGG-16 model from scratch using a dataset containing 3k images. I use Tensorflow platform and 8 cpus without any gpu. Training rate - 0.01, Weight decay - 0.0005, Momentum - 0.9, Batch size - 64, I've kept training for about three days. But the training accuracy has been unchanged, around 15%-20% after 20 epochs. Could anyone give me some hints to improve the accuracy? 回答1: It seems like I have used too large learning rate. Or weight decay does not work as it promises. After I

Keras: Create a custom generator for two input model using flow_from _directory() function

拈花ヽ惹草 提交于 2021-02-19 04:21:33
问题 I was trying to train my siamese network with fit_generator() ,I learned from this answer: Keras: How to use fit_generator with multiple inputs that the best way to do this was to create your own generator that yield the multiple data points, my problem was that I retrieve my data with flow_from_directory() function and I didn't know if that was possible. This is my attempt to readapt a generator for my problem: from keras.models import load_model from keras import optimizers from keras

How to save best model in Keras based on AUC metric?

走远了吗. 提交于 2021-02-18 18:00:33
问题 I would like to save the best model in Keras based on auc and I have this code: def MyMetric(yTrue, yPred): auc = tf.metrics.auc(yTrue, yPred) return auc best_model = [ModelCheckpoint(filepath='best_model.h5', monitor='MyMetric', save_best_only=True)] train_history = model.fit([train_x], [train_y], batch_size=batch_size, epochs=epochs, validation_split=0.05, callbacks=best_model, verbose = 2) SO my model runs nut I get this warning: RuntimeWarning: Can save best model only with MyMetric