pytorch

Gradient accumulation in an RNN

点点圈 提交于 2021-01-28 01:52:36
问题 I ran into some memory issues (GPU) when running a large RNN network, but I want to keep my batch size reasonable so I wanted to try out gradient accumulation. In a network where you predict the output in one go, that seems self-evident but in an RNN you do multiple forward passes for each input step. Because of that, I fear that my implementation does not work as intended. I started from user albanD's excellent examples here , but I think they should be modified when using an RNN. The reason

Pytorch CUDA error: no kernel image is available for execution on the device on RTX 3090 with cuda 11.1

岁酱吖の 提交于 2021-01-28 01:50:34
问题 If I run the following: import torch import sys print('A', sys.version) print('B', torch.__version__) print('C', torch.cuda.is_available()) print('D', torch.backends.cudnn.enabled) device = torch.device('cuda') print('E', torch.cuda.get_device_properties(device)) print('F', torch.tensor([1.0, 2.0]).cuda()) I get this: A 3.7.5 (default, Nov 7 2019, 10:50:52) [GCC 8.3.0] B 1.8.0.dev20210115+cu110 C True D True E _CudaDeviceProperties(name='GeForce RTX 3090', major=8, minor=6, total_memory

ModuleNotFoundError: No module named 'torch.utils.serialization'

二次信任 提交于 2021-01-27 21:55:33
问题 When I run a project used Pytorch I came up with this error: Traceback (most recent call last): File "train_drnet.py", line 10, in <module> import utils File "/home/muse/drnet-py/utils.py", line 18, in <module> from data.kth import KTH File "/home/muse/drnet-py/data/kth.py", line 7, in <module> from torch.utils.serialization import load_lua ModuleNotFoundError: No module named 'torch.utils.serialization' how to solve this,please? 回答1: I think it was removed from Pytorch about a year ago, you

Creating and shaping data for 1D CNN

…衆ロ難τιáo~ 提交于 2021-01-27 21:43:04
问题 I have a (244, 108) numpy array. It contains percentage change of close value of a trade for each minute in one day ie 108 values and like that for 244 days. Basically its a 1D vector. So in order to do 1D CNN how should I shape my data? What i have done: x.shape = (244, 108) x = np.expand_dims(x, axis=2) x.shape = (243, 108, 1) y.shape = (243,) Model: class Net(torch.nn.Module): def __init__(self): super(Net, self).__init__() self.layer1 = torch.nn.Conv1d(in_channels=108, out_channels=1,

Converting Keras (Tensorflow) convolutional neural networks to PyTorch convolutional networks?

被刻印的时光 ゝ 提交于 2021-01-27 21:07:04
问题 Keras and PyTorch use different arguments for padding: Keras requires a string to be input, while PyTorch works with numbers. What is the difference, and how can one be translated into another (what code gets the equivalent result in either framework)? PyTorch also takes the args in_channels, out_chanels while keras only takes an argument called filters. What does 'filters' mean? 回答1: Regarding padding, Keras => 'valid' - no padding; 'same' - input is padded so that the output shape is same

How to randomly set a fixed number of elements in each row of a tensor in PyTorch

冷暖自知 提交于 2021-01-27 19:13:31
问题 I was wondering if there is any more efficient alternative for the below code, without using the "for" loop in the 4th line? import torch n, d = 37700, 7842 k = 4 sample = torch.cat([torch.randperm(d)[:k] for _ in range(n)]).view(n, k) mask = torch.zeros(n, d, dtype=torch.bool) mask.scatter_(dim=1, index=sample, value=True) Basically, what I am trying to do is to create an n by d mask tensor, such that in each row exactly k random elements are True. 回答1: Here's a way to do this with no loop.

How can torchaudio.transform.Resample be called without __call__ function inside?

妖精的绣舞 提交于 2021-01-27 18:59:09
问题 if sample_rate != sr: waveform = torchaudio.transforms.Resample(sample_rate, sr)(waveform) sample_rate = sr I was wondering how this Resamle works in there. So took a look at the docs of torchaudio. I thought there would be __call__ function. Because Resample is used as a function. I mean that Resample()(waveform) . But inside, there are only __init__ and forward function. I think the forward function is the working function but I don't know why it is named 'forward' not __call__. What am I

How to speed up the “ImageFolder” for ImageNet

£可爱£侵袭症+ 提交于 2021-01-27 17:12:10
问题 I am in an university, and all the file system are in a remote system, wherever I log in with my account, I could aways access my home directory. even though I log into the GPU servers through SSH command. This is the condition where I employ the GPU servers to read data. Currently, I use the PyTorch to train ResNet from scratch on ImageNet, my codes only use all the GPUs in the same computer, I found that the "torchvision.datasets.ImageFolder" will take almost two hours. Would you please

The location of source code for torch.mean()

∥☆過路亽.° 提交于 2021-01-27 14:51:30
问题 I'm trying to find the source code for torch.mean and am unable to find it in the pytorch github. It is under math operations but I can't find it at all. I've looked everywhere and inspected most pages under pytorch/torch and am still unable to find it. I even did ?? in a jupyter notebook but it just returned a useless docstring 回答1: Since operations components are written in C++, they are not callable with operations such as ?? or "__file__" or "getsourcefile" type of operations. The files

How to convert a pandas dataframe into a numpy array with the column names

感情迁移 提交于 2021-01-27 13:00:02
问题 This must use vectorized methods, nothing iterative I would like to create a numpy array from pandas dataframe. My code: import pandas as pd _df = pd.DataFrame({'itme': ['book', 'book' , 'car', ' car', 'bike', 'bike'], 'color': ['green', 'blue' , 'red', 'green' , 'blue', 'red'], 'val' : [-22.7, -109.6, -57.19, -11.2, -25.6, -33.61]}) item color val book green -22.70 book blue -109.60 car red -57.19 car green -11.20 bike blue -25.60 bike red -33.61 There are about 12k million rows. I need to