TypeError: relu(): argument 'input' (position 1) must be Tensor, not tuple

cwoolfo1: <p>I am training a stacked GRU with a linear output layer. I have verified the input size is 3 dim. The code is giving me the following error: TypeError: relu(): argument ‘input’ (position 1) must be Tensor, not tuple</p>
<p>I have written code to convert my input numpy arrays to torch tensors but I am still getting that error.</p>
<blockquote>
<p>class CustomDataset(Dataset):<br>
def <strong>init</strong>(self, X_data, Y_data):<br>
super(CustomDataset, self).<strong>init</strong>()<br>
self.X_data = X_data.float()<br>
self.Y_data = Y_data.float()</p>
</blockquote>
<pre><code># Initializes the data and preprocessing.

def __getitem__(self, index):
    return self.X_data[:,:,:], self.Y_data[:,:,:]
# Returns data (input and output) in batches.
# There is an error in this part of the code.
def __len__ (self):
    return len(self.X_data[:,1,1])
# Returns the size of the input data.
</code></pre>
<blockquote>
<p>inputdata = np.load(‘4thin.npy’)<br>
outputdata = np.load(‘4thout.npy’)</p>
</blockquote>
<blockquote>
<p>trainX = inputdata[:208,:,:10]<br>
trainX = torch.from_numpy(trainX)<br>
print(trainX.shape)</p>
</blockquote>
<blockquote>
<p>trainY = outputdata[:208,:,:8]<br>
trainY = torch.from_numpy(trainY)<br>
print(trainY.shape)</p>
</blockquote>
<blockquote>
<p>testX = inputdata[208:,:,:10]<br>
testX = torch.from_numpy(testX)<br>
print(testX.shape)</p>
</blockquote>
<blockquote>
<p>testY = outputdata[208:,:,:8]<br>
testY = torch.from_numpy(testY)<br>
print(testY.shape)<br>
<span class="hashtag-raw">#select</span> a subset of the features from the data for testing of the script<br>
<span class="hashtag-raw">#Loads</span> in the input and output numpy arrays and splits into training and validation datasets.</p>
</blockquote>
<blockquote>
<p>train_dataloader = CustomDataset(trainX, trainY)<br>
test_dataloader = CustomDataset(testX, testY)</p>
</blockquote>
<p>The size of each of the tensors is the following:</p>
<blockquote>
<p>torch.Size([208, 3, 10])<br>
torch.Size([208, 1, 8])<br>
torch.Size([208, 3, 10])<br>
torch.Size([208, 1, 8])</p>
</blockquote>
<p>I set up the program to print the x tensor and got the following:</p>
<blockquote>
<p>tensor([[[  0.,   0.,   0.,  …,   0.,   0.,   0.],<br>
[  0.,   0.,   0.,  …,   0.,   0.,   0.],<br>
[ 15.,   5.,  34.,  …,   4.,  11.,   1.]],<br>
[[  0.,   0.,   0.,  …,   7.,   6.,   7.],<br>
[  6.,  15.,   0.,  …,   0.,   7.,   0.],<br>
[  1.,   5.,  17.,  …,  61.,   9.,   0.]],<br>
[[ 58.,  58.,  35.,  …,  87.,  54.,  38.],<br>
[  0.,   0.,   0.,  …,   0.,   0.,   0.],<br>
[  8.,   0.,   0.,  …,   0.,   0.,   0.]],<br>
…,<br>
[[  2.,   0.,   8.,  …,   3.,   2.,   2.],<br>
[  4.,   4.,  30.,  …,   5.,   0.,  23.],<br>
[125., 145.,  97.,  …, 179., 704., 140.]],<br>
[[  0.,   0.,   0.,  …,   1.,   0.,   0.],<br>
[ 78.,   0.,  43.,  …,  62.,   0.,  64.],<br>
[ 45.,  88.,   0.,  …,   0.,  15.,   0.]],<br>
[[  0.,   0.,   0.,  …,   0.,   0.,   0.],<br>
[  0.,   0.,   0.,  …,   0.,   0.,   0.],<br>
[112.,  84., 104.,  …, 133., 125.,  75.]]])</p>
</blockquote>
<p>The script seems to think this is a tuple and not a tensor. Help would be much appreciated!</p>

ptrblck: <p>Could you post the model definition, please?<br>
Sometimes these errors are caused by an accidental training comma in a line of code, e.g.</p>
<pre><code class="lang-python">x = self.layer(x), 
x = F.relu(x)
</code></pre>
<p>(note the comma in the first line of code).</p>