id
stringlengths
3
8
text
stringlengths
1
115k
st100200
Hi all, I have a tuple like this: (tensor([[ 5.0027e-03, 1.3885e-03, -6.4720e-03, ..., 2.1762e-03, 2.0357e-03, 1.0070e-03], [ 9.5693e-04, 7.5463e-04, -7.4230e-04, ..., -1.4247e-03, -1.5754e-03, 2.6448e-03], [ 7.9327e-03, 3.3485e-03, -9.9604e-04, ..., -4.5044e-03, ...
st100201
It looks like your tuple has only the first element set. You could try torch.norm(x[0], 2).
st100202
Hello, Is it correct to save the logits and probabilities of best model like the following ? for epoch in range(args.start_epoch, args.epochs): if args.distributed: train_sampler.set_epoch(epoch) adjust_learning_rate(optimizer, epoch) # train for one epoch prec_train, loss_train = tra...
st100203
Hi, I’m new to transfer learning and I got two questions about inceptionV3. I’m following the pytorch transfer learning tutorial and I’m gonna do ‘ConvNet as fixed feature extractor’ (https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html 17). So I should freeze all the layers except the FINAL fc laye...
st100204
You can disable the auxiliary output by setting aux_logits=False. I would start the fine tuning by disabling it and just re-train the final classifier.
st100205
Hi, Thanks for your reply. But why wouldn’t you retrain the auxiliary classifier and the final classifier together?
st100206
The aux_logits are created a bit deeper in the model (line of code 11), so that it would just make sense to use them, if your fine tuning goes further down the model (below self.Mixed_6e(x)). Maybe I misunderstood your first post, but I thought you just wanted to re-create the last linear layer. If you want to fine tun...
st100207
I’m sorry maybe i did not explain it clearly. What I wanted to do is to re-create both the last fc layer and the fc layer within the auxiliary classifier, then just re-train the two layers. Therefore, for each epoch during training, we’ll have two outputs (one for auxiliary and one for the final fc layer) and two loss...
st100208
The approach would work (summing the losses and backpropagate through the sum), but it’s probably not necessary, if you don’t want to finetune below the auxiliary classifier. Assuming that all layers are frozen (do not require gradients) except the last linear layer, the auxiliary loss would just vanish as it’s not nee...
st100209
Hi, I am trying to use torch.mul() for a sparse tensor, but unfortunately the code below throws a run-time error: a = torch.tensor([0.92], requires_grad=True) i = torch.LongTensor([[0,0,0,0], [0,0,1,1], [0,0,2,2], [0,0,3,3]]) v = torch.FloatTensor([1, 2, 1, 1]) # A 4D sparse tensor t = torch.sparse.FloatTensor(i.t(),...
st100210
According to #8853 227, mul/mul_ for (Sparse, Sparse) -> Sparse and (Sparse, Scalar) -> Sparse exist, but (Sparse, Dense) is still on todo list.
st100211
I hava a tensor like this x = torch.Tensor([[1, 2, 3, 0], [4, 5, 0, 0], [6, 7, 0, 0]]). How can I get tensor y = softmax(x, dim=1), like this y = torch.Tensor([[a, b, c, 0], [d, e, 0, 0], [f, g, 0, 0]]) ? I really appreciate it.
st100212
Solved by handesy in post #2 You may want to do a masked softmax, e.g., https://github.com/allenai/allennlp/blob/master/allennlp/nn/util.py#L216
st100213
You may want to do a masked softmax, e.g., https://github.com/allenai/allennlp/blob/master/allennlp/nn/util.py#L216 366
st100214
I want to use cifar 10 dataset from torchvision.datasets to do classification. import torch import torchvision import torchvision.transforms as transforms from torch.utils.data.sampler import SubsetRandomSampler transform = transforms.Compose( [transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5...
st100215
I made a custom dataset with dataloader, which was about 3 different categories images. I used vgg16 to predict which category was in the image. If i want to predict a single image however, i would get back something like this: tensor([[-0.0559, -1.6212, -0.3467]], grad_fn=) How would I know which of the categories c...
st100216
rmnvcc: self.y_train = self.mlb.fit_transform(images_df[‘tag’].str.split()).astype(np.float32) You need to keep track of this mapping. Best regards Thomas
st100217
Hi, I am trying to implement the power mean in pytorch following this paper 34. It is pretty straight forward to do it in numpy: def gen_mean(vals, p): p = float(p) return np.power( np.mean( np.power( np.array(vals, dtype=complex), p), axis=0), ...
st100218
Solved by tom in post #6 Well, -(378**(1/3))is a root, too, so I’d start with that. If not, you can precompute -1**(1/3) to (0.5+0.866j) and “outer” multiply 378**(1/3) (or whatever outcome you have by a two-tensor tensor([0.5, 0.866]) if it is negative and tensor([1.0, 0...
st100219
You could mock a complex number using two floats (one for magnitude and one for phase) this way the pow operation becomes easy but the mean operation is not that simple. Splitting the number by it’s real and imaginary part would make the mean easy but the pow would become hard. What I would recommend is to use both rep...
st100220
Given that you only have two phases (0 and pi) in your input, if p is fixed you can easily precompute that and just multiply the sign with the result. Then you multiply with the p-norm divided by the vector size to 1/p (or absorb that factor into the phase). Best regards Thomas Edited P.S.: Looking at the paper authors...
st100221
Thanks @tom I am unsure to follow you. It is true that the paper only suggest using max/min/and odd power mean from 1 to 10. However this does not solve the issues of having negative numbers as far I understand. i.e. Taking the 3rd power mean of -9,-3 ( gen_mean([-9, -3],3) try to do np.power(-378,1/3) which solution ...
st100222
Well, -(378**(1/3))is a root, too, so I’d start with that. If not, you can precompute -1**(1/3) to (0.5+0.866j) and “outer” multiply 378**(1/3) (or whatever outcome you have by a two-tensor tensor([0.5, 0.866]) if it is negative and tensor([1.0, 0]) if the mean is positive. Best regards Thomas
st100223
Thanks @tom I think you’re right this solution will just do it. Here is what it looks like by the way: def p_mean_pytorch(tensor,power): mean_tensor = tensor.pow(power).mean(0) return ( (mean_tensor * mean_tensor.sign() ).pow(1/power) * mean_pow.sign() ) i.e. p_mean_pytorch(torch.tensor([[-1...
st100224
I usually recommend broadcasting for outer products. Here you can combine with advanced indexing (.long() makes it an index instead of a mask): # seq x batch a = torch.tensor([[-100.,33,99],[39,9,-10000],[1,3,4],[0,0,0]]) magical_number=torch.tensor([[0.5,(0.75)**(0.5)],[1,0]]) # np.power(-1+0j,1/3), 1 ; keep out of f...
st100225
Hi, I noticed “Empty bags (i.e., having 0-length) will have returned vectors filled by zeros.” in the pytorch document. image.png1668×422 47.5 KB you can see it in the picture, where offset1 is [0,1,2,2,2] which represents five bags, the third and fourth bag should be empty, but i got nan instead of zeros, why does t...
st100226
Hey, I have a network which overrides the parameters() function to only include trainable parameters. This has worked well until I tried to run it with DataParallel. I guess I was not supposed to override it because DataParallel does not work with my model. Here’s an example: # Python 3.6 # Pytorch 4.1 installed via an...
st100227
I’m not completely sure, but I think your parameters method filtering only parameters requiring gradients will break replicate 47 as your current method won’t yield all parameters.
st100228
I thought so, as I kept getting a KeyError in replicate.py when I had frozen a layer. What I don’t get is why it is throwing a NotImplementedError in module.py 4 when I return all parameters (i.e. all parameters require gradients). That’s why I thought I was yielding parameters incorrectly somehow.
st100229
With this class # Python 3.6 # Pytorch 4.1 installed via anaconda import torch from torch import nn class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.module_list = nn.ModuleList() self.module_list.append(nn.Linear(10, 10)) self.module_list.append(nn.Linear(1...
st100230
Your Net class doesn’t have the forward method implemented. Could you add the method and try it again? Was this code running on a single GPU?
st100231
Oh yea your right, I forgot to add the forward call in the conceptual class! Disregard the first error then. The second error is what was originally my problem. I have tried running it on two GTX 1080ti as well as two different nvidia GPUs. The code was originally running on a single GPU without using DataParallel. Usi...
st100232
# Python 3.6 # Pytorch 4.1 installed via anaconda import torch from torch import nn class Net(nn.Module): def __init__(self): super(Net, self).__init__() self.module_list = nn.ModuleList() self.module_list.append(nn.Linear(2, 2)) self.module_list.append(nn.Linear(2, 2)) def...
st100233
I still think the error is related to the fact that you are not replicating all Parameters, thus these are missing in the replicas. If you only specify one GPU for DataParallel, the module will just be called without replication (line of code 19). Maybe I’m not understanding your use case, but currently only the parame...
st100234
There isn’t really any issue, I solved it by setting only_trainable=False in my parameters function so it would behave exactly like normal nn.Module.parameters() function. I was initially curious as to why it didn’t work before so I created some example code and forgot to implement forward which made me think there was...
st100235
Hi, I have installed torchvison using ‘pip install --no-deps torchvision’ (pip3 install torchvision will cause error), but pycharm cannot import. pycharm can import torch correctly. I have already installed anaconda. Both torch and torchvision cannot be imported in IDLE. The paths are: ‘Requirement already satisfied: t...
st100236
Solved by robo in post #3 Thanks,the problem has been soloved. I installed python3.7 before anaconda, so there is the problem that python3.7 cannot use Torch and torchvision. because of the python3.7, when I install torchvision using ‘pip install --no-deps torchvision’,...
st100237
Since there’re so many Python distributions installed, I wonder whether these environments are messed up. Does pip and python come from the same Python distribution? You can check this through the following commands. where python.exe where pip.exe As for IDLE, make sure you set it to the Python distribution that has P...
st100238
Thanks,the problem has been soloved. I installed python3.7 before anaconda, so there is the problem that python3.7 cannot use Torch and torchvision. because of the python3.7, when I install torchvision using ‘pip install --no-deps torchvision’, torchvision seems not install correctly with anaconda. I think that is th...
st100239
Can someone please point me to a step-by-step guide for building Pytorch from source in Windows OS and the Anaconda environment? All the guides I’m finding are either out of date or not clear enough for me to understand. Thanks. Edit: I should mention that I have already successfully installed Pytorch via the conda r...
st100240
I followed the steps in the guide, but my build ultimately failed with the following errors: c:\users\wagne134\anaconda3\include\pyconfig.h(59): fatal error C1083: Cannot open include file: ‘io.h’: No such file or directory error: command ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Tools\MSVC\14...
st100241
wagne134: Cannot open include file: ‘io.h’: No such file or directory Could you give me the result of the following command? echo %INCLUDE% echo %LIB% I’m afraid that you didn’t install the MSVC 14.11 toolset.
st100242
I was trying to build a language model but got error THIndexTensor_(size)(target, 0) == batch_size. Here is the code import numpy as np import torch from torch.autograd import Variable import torch.nn as nn data = '...' words = list(set(data)) word2ind = {word: i for i, word in enumerate(wo...
st100243
Hi, I think problem is that you are missing the batch dimension on your target_tensor. The error says that the size of the 0th dimension is not equal to the batch size. Try changing this: loss = criterion(output, target_tensor[i].unsqueeze(0)).
st100244
Thank you for your reply. But I don’t think it works, it raised an error: RuntimeError: multi-target not supported at d:\downloads\pytorch-master-1\torch\lib\thnn\generic/ClassNLLCriterion.c:20 I think it is because I unsqueezed the target, and torch regards it as a muti-target. And after using unsqueeze, I printed the...
st100245
Your output should have one more dimension than the target corresponding to a score for each label and the target should just contain the index of the correct label.
st100246
Yeah, I mean before using unsqueeze, I got torch.Size([1, 1139]), torch.Size([1139]), which is right I think. But it raised THIndexTensor_(size)(target, 0) == batch_size. And I didn’t try to use batch here.
st100247
Pytorch always use batches (even if it means having a first dimension of size 1). If you have a single element with 1139 possible label, then output should be 1x1139 and target should be a LongTensor of size 1 (containing the index of the correct label).
st100248
Thank you so much, man!! It just worked. But there is another error, can you help me with this? :light_smile: --------------------------------------------------------------------------- RuntimeError Traceback (most recent call last) <ipython-input-75-95f5d8615326> in <module>() ----> 1 outp...
st100249
The problem here is in the way you use Variable. Basically as soon as you start using a Variable, it will create an history of all the computations you do with it to be able to get gradients. So for elements that do not need gradients, you want to create it as late as possible. Keep in mind that creating a Variable is ...
st100250
If I may post on this thread, I’m having a similar issue as the original one so I thought I’d post it here rather than creating a new thread. My training code looks as follows: model.train() train_loss = [] train_accu = [] i = 0 for epoch in range(30): for data, target in test_loader: print(target.shape) ...
st100251
Your .view has the wrong dimensions. Based on your input size, it should be x = x.view(-1, 64*16*16) or alternatively x = view(x.size(0), -1). Since you are pooling twice with kernel_size=2 and stride=2, your height and width will be reduced to 64/2/2 = 16. Therefore, you also have to change the in_features of fc1 to 6...
st100252
Thank you for replying Ah yes, you’re quite right! Now I’m getting this error however: RuntimeError: size mismatch, m1: [3 x 16384], m2: [4096 x 1024] at /opt/conda/conda-bld/pytorch-cpu_1515613813020/work/torch/lib/TH/generic/THTensorMath.c:1416
st100253
Sorry, I was too fast posting. I’ve added the note, that you also have to change the in_features of fc1 to 64*16*16.
st100254
That did the job! Thanks so much! Admittedly I should have noticed that last point myself too
st100255
Hi, I’m trying to concatenate two layers as below. class Net1(nn.Module): def __init__(self, num_classes=2): super(Net1, self).__init__() self.conv1 = nn.Conv2d(in_channels=3, out_channels=10, kernel_size=3, stride=1, padding=1) self.relu1 = nn.ReLU() self.conv2 = nn.Conv2d(in_chan...
st100256
Your model works with an input size of [batch_size, 3, 224, 224]. Could you post the Dataset or generally how you load and process the data? Based on the error message it seems there is a mismatch between your data and target. PS: I’ve formatted your post. You can add code snippets using three backticks.
st100257
Thank you Here is my data loading part data_dir_train= 'cross_vali/train' data_dir_val = 'cross_vali/val' transform = transforms.Compose( [transforms.Resize(224), transforms.ToTensor()]) #transforms.Normalize((76.02, 34.22, 37.86), (52.76, 6.61, 28.19))]) trainset = torchvision.datasets.ImageFolder(root=...
st100258
Thanks for the code. Could you print the shape of output10 before the torch.cat operation in forward?
st100259
Hi everyone, I got a similar issue : Expected input batch_size (896) to match target batch_size My code is the following: import torch import torch.nn as nn import torchvision.models as models class EncoderCNN(nn.Module): def __init__(self, embed_size): super(EncoderCNN, self).__init__() resnet ...
st100260
I’m trying to implement an ensemble model, as there are some independent models, I want to traing the models in parallel using torch.multiprocessing, However, I always get Too many open files error. Here is a minimal example that reproduce the error: import torch import torch.nn as nn from torch.multiprocessing impor...
st100261
I’m getting your code to run fine, although I changed one thing: pool = Pool(processes = 3) ret = pool.map(self.f, range(self.K)) print(ret) to with Pool(processes = 3) as pool: ret = pool.map(self.f, range(self.K)) print(ret) Dont forget to close your pools if you dont use a with statement
st100262
Ah, I can’t replicate the error with your code. I had the same error when I was running too many processes that I had not closed. If this is not the case you can try increasing the maximum amount by running ulimit -n 2048 if you are on Linux and have root privileges. Change 2048 to something that fits you. To see the c...
st100263
I am using F.log_softmax+nn.NLLLoss and after about 150 epochs both my training and validation are flat around nearly 0 Normally with cross entropy i’d expect the validation curve to go back up (over-fitting) but that is not happening here. If i understand this set up correctly, the higher the correct prediction confid...
st100264
Your model is perfectly fitting the distribution in the training and validation set. I don’t want to be pessimistic, but I think something might be wrong. Could you check the distribution of your labels? Could it be that your DataLoader is somehow returning the same labels over and over again?
st100265
I will post some code later, but in general this is what happens… If i let this go for longer both training and validation would will stagnate, training at maybe 0.05 and validation at 0.08 Once they hit those numbers (5 and 8) they never improve or get worse. My concern is that the validation loss never shoots back u...
st100266
So the losses are not approx. zero, but a bit higher. Are you using an adaptive optimizer, e.g. Adam?
st100267
Yes. Adam. I have tried several different learning rates as well. They all ultimately result in the same or similar behavior
st100268
It might be Adam is reducing the per-parameter estimates so that your training stagnate and the val loss doesn’t blow up. You could try a different optimizer like SGD and try it again.
st100269
I changed the beta values in Adam and was able to get this validation does continue to increase passed 100 epochs albeit slowly… training continues to drop slowly I think also the model might be extremely sensitive to learning rate… this is 3e-5 lowering it starts the causes stranger behavior such as starting losses a...
st100270
To get back to the original question: F.log_softmax + nn.NLLLoss work exactly as raw logits + nn.CrossEntropyLoss. I think this issue is now more of a general nature. The validation loss might increase after a while. Sometimes your model just gets stuck and both losses stay the same for a (long) while. I like to check ...
st100271
Hi guys, I want to use a CNN as a feature extractor. When defining a neural net with nn.Sequential, for example self.features = nn.Sequential(OrderedDict({ 'conv_1': nn.Conv2d(1, 10, kernel_size=5), 'conv_2': nn.Conv2d(10, 20, kernel_size=5), 'dropout': nn.Dropout2d(), 'linear_1': nn.Lin...
st100272
Solved by ptrblck in post #2 Your get_index_by_name method could implement something like this small hack: list(dict(features.named_children()).keys()).index('conv_2') > 1
st100273
Your get_index_by_name method could implement something like this small hack: list(dict(features.named_children()).keys()).index('conv_2') > 1
st100274
I tried installing pytorch in my pc which has Debian. I get error stating that it is not a supported wheel on this platform both for with and without UCS2 versions of python 2.7 torch-0.2.0.post2-cp27-cp27m-manylinux1_x86_64.whl is not a supported wheel on this platform. torch-0.2.0.post2-cp27-cp27mu-manylinux1_x86_64....
st100275
pip --version That will reveal which version of python your pip is associated with, and then it’ll be easier to figure out the problem.
st100276
that’s really weird. from what you’ve shown so far, one of those wheels has to work.
st100277
ya it is indeed weird. I am able to install it in my laptop. Just doesn’t seem to work on my pc… It is interesting to note that the below command worked: pip install --user https://s3.amazonaws.com/pytorch/whl/cu75/torch-0.1.6.post22-cp27-none-linux_x86_64.whl This is an older version though. I found this answer from ...
st100278
the obvious but hacky fix is to rename the file torch-0.2.0.post2-cp27-cp27mu-manylinux1_x86_64.whl to torch-0.2.0.post2-cp27-cp27mu-none_x86_64.whl
st100279
Stuck at same place. Wheel is not supported, while I’m using Linux Mint (Ubuntu 16.04) with Python 2.7 Screenshot from 2017-08-29 11-28-07.png1360×768 68.8 KB
st100280
I provided full instructions here: "wheel not supported" for pip install Torch CPU !pip install http://download.pytorch.org/whl/cu75/torch-0.2.0.post1-cp27-cp27mu-manylinux1_x86_64.whl !pip install torchvision !pip install --upgrade http://download.pytorch.org/whl/cu75/torch-0.2.0.post1-cp...
st100281
Hi. changing to none for whl file didn’t work. What did work was building from source. Also had to set environment variable No_Cuda to true. Just an information to pass on to others.
st100282
Hi, I am trying to implement a model of which the loss function depends on a pair of training data. Specifically, given dataset D={x_i}, the loss function will be E(f(x_i), f(x_j)), where f is the neural network model. I wonder if there is an efficient way to generate a stream of random pairs {x_i, x_j} for training?...
st100283
I am new to pytorch. I have a sparse tensor and a full one and I want to find the similarity between these two binary tensors. I tried binary_cross_entropy_with_logits but it isn’t for a sparse and a full tensor and I couldn’t find anything else, so I tried to change sparse tensor to full, and tried to map sparse tenso...
st100284
I am running the code in pytorch using gpu which produces a matrix that is fed to the matlab code where the other logic is implemented. The code is working fine but takes 10 to 15 min for one epoch using 2 gpu’s. The probable reason might be the data transfer from pytorch cuda tensor to matlab variable and then running...
st100285
Hi! I’m trying to implement the model presented on this paper by Uber: https://arxiv.org/pdf/1709.01907.pdf 3. Long story short, I have a LSTM used to predict the next day of a time series, after consuming N days of data. I have a function used to train that inference part, and another one to infer the next value on t...
st100286
I just skimmed through your code, and stumbled over these lines: list_predictions += [forecaster_output.cpu().numpy() ]#+ target_tensor[0].numpy()] # pass list of lists with lists of B predictions outputs += [list_predictions[0]] Wouldn’t this just add the first prediction to outputs, while the new ones are appended a...
st100287
Yeah, you are right. When the model is functional I hope to use Monte Carlos Dropout so I would need multiple computations of the same prediction. But for now I’m just appending the first prediction to test. I will clean up the code on my post
st100288
I’m not sure, if that was the issue or not. Do you get different predictions now?
st100289
Same thing… This wasn’t the problem. I’ve updated the code on my post without that part to make it less confusing.
st100290
Did you try to use the same data from training while testing, as a sanity check?
st100291
Yes! This is all done with the training data. I haven’t touched the dev data yet
st100292
Hi, does anyone know what batch_size for validation set means for following code: indices = list(range(len(train_data))) np.random.shuffle(indices) split = int(np.floor(valid_size * len(train_data))) train_idx, valid_idx = indices[split:], indices[:split] train_loader = DataLoade...
st100293
Solved by albanD in post #2 Hi, It means that the data will be drawn by batches of 50. As you usually can’t put the whole validation dataset at once in your neural net, you do it in minibatch, similarly as you do for training.
st100294
Hi, It means that the data will be drawn by batches of 50. As you usually can’t put the whole validation dataset at once in your neural net, you do it in minibatch, similarly as you do for training.
st100295
Hi!, I’ve noticed that here 1 (in Chainer GAN lib) they use 1008 out classes while in implementation provided by pytorch team used here 1, you use 1000 output classes. Messing around with comparing Inception scores I found that numbers do not match. I want to make some comparative study between models in their repo and...
st100296
Hello How important is it for the CNN that the data is perfectly “grid-like”? I know CNN’s are great for images because the pixels in an image are placed like in a grid with constant distance to each other. This grid can be 1 dimensional as well as for a time series with constant update frequencies. My data that are a ...
st100297
Let me explain the objective first. Let’s say I have 1000 images each with an associated quality score [in range of 0-10]. Now, I am trying to perform the image quality assessment using CNN with regression(in pytorch). I have divided the images into equal size patches. Now, I have created a CNN network in order to perf...
st100298
Could you print the shape of x just before the .view call? I think 3200 is the wrong number here and thus your batch size will increase. You are pushing “everything left” into the batch dimension using view(-1, 3200). So if x has 6400 features, the batch dimension will be doubled. You could use x = x.view(x.size(0), -1...
st100299
I have a model (nn.module) class and inside this class i create a random tensor using torch.randn(). When I create a model.to(device) where device is cuda, the random tensor doesn’t get moved to cuda. Is the behavior correct? how should i do it, without passing device to the model. Thanks