AttributeError: 'GlobalStorage' object has no attribute 'float'

username: keerthi
cooked: <p>Hello, I am trying to run my GCN on image dataset. I have used dataloader and this is the following output of the data loader<br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/c/8/c8079b219d4b050d8512a8daa5e364fc807cba07.png" data-download-href="https://discuss.pytorch.org/uploads/default/c8079b219d4b050d8512a8daa5e364fc807cba07" title="image"><img src="https://discuss.pytorch.org/uploads/default/original/3X/c/8/c8079b219d4b050d8512a8daa5e364fc807cba07.png" alt="image" data-base62-sha1="sxxMY6GYYTLMspd802sWDvzmf1J" width="690" height="117" data-dominant-color="E3E3E5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">1265×215 19.5 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Below is my code for my model and my training of my data:<br>
class GCNN(torch.nn.Module):<br>
def <strong>init</strong>(self):<br>
super().<strong>init</strong>()<br>
self.conv1 = GCNConv(face_dataset.num_node_features, 100)<br>
self.conv2 = GCNConv(100, face_dataset.landmarks_len)</p>
<pre><code>def forward(self, data):
    x, edge_index = data.x, data.edge_index

    x = self.conv1(x, edge_index)
    x = F.relu(x)
    x = F.dropout(x, training=self.training)
    x = self.conv2(x, edge_index)

    return x
</code></pre>
<p>dataloader = DataLoader(face_dataset, batch_size=4,<br>
shuffle=True)</p>
<p>model = GCNN()<br>
optimizer = torch.optim.Adam(model.parameters(), lr=0.01, weight_decay=5e-4)<br>
log_interval = 1<br>
num_epoch = 5</p>
<p>def train(epoch):<br>
model.train()<br>
for batch_idx, (data, target) in enumerate(dataloader):<br>
optimizer.zero_grad()<br>
output = model(data)<br>
print(output)<br>
print(target)<br>
loss = F.nll_loss(output, target)<br>
loss.backward()<br>
optimizer.step()<br>
if batch_idx % log_interval == 0:<br>
print(‘Train Epoch: {} [{}/{} ({:.0f}%)]\tLoss: {:.6f}’.format(<br>
epoch, batch_idx * len(data), len(dataloader.dataset),<br>
100. * batch_idx / len(dataloader), loss.item()))</p>
<p>for i in range(0, num_epoch):<br>
train(i)</p>
<h2><a name="i-am-getting-the-below-error-1" class="anchor" href="#i-am-getting-the-below-error-1"></a>I am getting the below error:</h2>
<p>RuntimeError                              Traceback (most recent call last)<br>
 in <br>
109<br>
110 for i in range(0, num_epoch):<br>
 → 111     train(i)</p>
<p> in train(epoch)<br>
96     for batch_idx, (data, target) in enumerate(dataloader):<br>
97         optimizer.zero_grad()<br>
—&gt; 98         output = model(data)<br>
99         print(output)<br>
100         print(target)</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)<br>
887             result = self._slow_forward(*input, **kwargs)<br>
888         else:<br>
 → 889             result = self.forward(*input, **kwargs)<br>
890         for hook in itertools.chain(<br>
891                 _global_forward_hooks.values(),</p>
<p> in forward(self, data)<br>
75         x, edge_index = data.x, data.edge_index<br>
76<br>
—&gt; 77         x = self.conv1(x, edge_index)<br>
78         x = F.relu(x)<br>
79         x = F.dropout(x, training=self.training)</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)<br>
887             result = self._slow_forward(*input, **kwargs)<br>
888         else:<br>
 → 889             result = self.forward(*input, **kwargs)<br>
890         for hook in itertools.chain(<br>
891                 _global_forward_hooks.values(),</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch_geometric\nn\conv\gcn_conv.py in forward(self, x, edge_index, edge_weight)<br>
180                     edge_index = cache<br>
181<br>
 → 182         x = self.lin(x)<br>
183<br>
184         # propagate_type: (x: Tensor, edge_weight: OptTensor)</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)<br>
887             result = self._slow_forward(*input, **kwargs)<br>
888         else:<br>
 → 889             result = self.forward(*input, **kwargs)<br>
890         for hook in itertools.chain(<br>
891                 _global_forward_hooks.values(),</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch_geometric\nn\dense\linear.py in forward(self, x)<br>
107     def forward(self, x: Tensor) → Tensor:<br>
108         “”“”“”<br>
 → 109         return F.linear(x, self.weight, self.bias)<br>
110<br>
111     <span class="mention">@torch.no_grad</span>()</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch\nn\functional.py in linear(input, weight, bias)<br>
1751     if has_torch_function_variadic(input, weight):<br>
1752         return handle_torch_function(linear, (input, weight), input, weight, bias=bias)<br>
 → 1753     return torch._C._nn.linear(input, weight, bias)<br>
1754<br>
1755</p>
<p>RuntimeError: expected scalar type Byte but found Float</p>
<p>and then i changed my output to:<br>
output = model(data.float())</p>
<h2><a name="but-then-i-am-getting-the-below-error-2" class="anchor" href="#but-then-i-am-getting-the-below-error-2"></a>but then i am getting the below error:</h2>
<p>KeyError                                  Traceback (most recent call last)<br>
~\anaconda3\envs\keerthi\lib\site-packages\torch_geometric\data\storage.py in <strong>getattr</strong>(self, key)<br>
47         try:<br>
—&gt; 48             return self[key]<br>
49         except KeyError:</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch_geometric\data\storage.py in <strong>getitem</strong>(self, key)<br>
67     def <strong>getitem</strong>(self, key: str) → Any:<br>
—&gt; 68         return self._mapping[key]<br>
69</p>
<p>KeyError: ‘float’</p>
<p>During handling of the above exception, another exception occurred:</p>
<p>AttributeError                            Traceback (most recent call last)<br>
 in <br>
1 for i in range(0, num_epoch):<br>
----&gt; 2     train(i)</p>
<p> in train(epoch)<br>
3     for batch_idx, (data, target) in enumerate(dataloader):<br>
4         optimizer.zero_grad()<br>
----&gt; 5         output = model(data.float())<br>
6         print(output)<br>
7         print(target)</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch_geometric\data\data.py in <strong>getattr</strong>(self, key)<br>
360                 "dataset, remove the ‘processed/’ directory in the dataset’s "<br>
361                 “root folder and try again.”)<br>
 → 362         return getattr(self._store, key)<br>
363<br>
364     def <strong>setattr</strong>(self, key: str, value: Any):</p>
<p>~\anaconda3\envs\keerthi\lib\site-packages\torch_geometric\data\storage.py in <strong>getattr</strong>(self, key)<br>
49         except KeyError:<br>
50             raise AttributeError(<br>
—&gt; 51                 f"‘{self.<strong>class</strong>.<strong>name</strong>}’ object has no attribute ‘{key}’")<br>
52<br>
53     def <strong>setattr</strong>(self, key: str, value: Any):</p>
<p>AttributeError: ‘GlobalStorage’ object has no attribute ‘float’<br>
can anyone please tell me how to fix this?</p>