Replies: 1 comment
-
Trying using uppercase X = torch.from_numpy(X).type(torch.float)
y = torch.from_numpy(y).type(torch.float) You didnt set type for Full codeimport torch
from torch import nn
import numpy as np
from sklearn.datasets import make_circles
n_samples = 1000
X, y = make_circles(n_samples,
noise = 0.03,
random_state = 42)
X = torch.from_numpy(X).type(torch.float)
y = torch.from_numpy(y).type(torch.float) # works for int dtype as well
# print(X.dtype, y.dtype)
device="cuda" if torch.cuda.is_available() else "cpu"
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=42)
class CircleModelV0(nn.Module):
def __init__(self):
super().__init__()
self.layer_1=nn.Linear(in_features=2,out_features=5)
self.layer_2=nn.Linear(in_features=5,out_features=1)
def forward(self,x):
return self.layer_2(self.layer_1(x))
model_0=CircleModelV0().to(device)
with torch.inference_mode():
untrained_preds=model_0(x_test.to(device)) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
....
....
.../
import torch
from torch import nn
import numpy as np
print(x.dtype)
x=torch.from_numpy(np.array(x))
y=torch.from_numpy(np.array(y))
device="cuda" if torch.cuda.is_available() else "cpu"
from sklearn.model_selection import train_test_split
x_train,x_test,y_train,y_test=train_test_split(x,y,test_size=0.2,random_state=42)
class CircleModelV0(nn.Module):
def init(self):
super().init()
self.layer_1=nn.Linear(in_features=2,out_features=5)
self.layer_2=nn.Linear(in_features=5,out_features=1)
def forward(self,x):
return self.layer_2(self.layer_1(x))
model_0=CircleModelV0().to(device)
with torch.inference_mode():
untrained_preds=model_0(x_test.to(device))
ERROR GENERATED IS
----> 2 untrained_preds=model_0(x_test.to(device))
5 frames
/usr/local/lib/python3.10/dist-packages/torch/nn/modules/linear.py in forward(self, input)
114
115 def forward(self, input: Tensor) -> Tensor:
--> 116 return F.linear(input, self.weight, self.bias)
117
118 def extra_repr(self) -> str:
RuntimeError: mat1 and mat2 must have the same dtype, but got Double and Float
Beta Was this translation helpful? Give feedback.
All reactions