Reputation: 113
How to call this torch.dtype? because here the error shows it's not callable. before I used floatTensor and it shows the error like this can't convert np.ndarray of type numpy.object_
and now I using float64 it showing the error 'torch.dtype' object is not callable
. please help with this issue.
import torch
a = torch.cuda.is_available()
b = torch.cuda.current_device()
c = torch.cuda.get_device_name()
d = torch.cuda.memory_reserved()
e = torch.cuda.memory_allocated()
var1 = torch.FloatTensor([1.0,2.0,3.0]).cuda()
var1
a1 = var1.device
import pandas as pd
df = pd.read_csv('diabetes.csv')
df.head()
b1 = df.isnull().sum()
import seaborn as sns
import numpy as np
df['Outcome']=np.where(df['Outcome']==1,"Diabetic","No Diabetic")
b2 = df.head()
b3 = sns.pairplot(df,hue="Outcome")
X=df.drop('Outcome',axis=1).values
y=df['Outcome'].values
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=0)
y_train
import torch
import torch.nn as nn
import torch.nn.functional as F
X_train=torch.FloatTensor(X_train).cuda()
X_test=torch.FloatTensor(X_test).cuda()
y_train=torch.float64(y_train).cuda()
this is the error:
C:\Users\vinot\.conda\envs\python21\python.exe D:/python/python_work/pythonProject/diabetes.py
Traceback (most recent call last):
File "D:/python/python_work/pythonProject/diabetes.py", line 35, in <module>
y_train=torch.float64(y_train).cuda()
TypeError: 'torch.dtype' object is not callable
Process finished with exit code 1
Upvotes: 2
Views: 10946
Reputation: 1308
In PyTorch, you can change the type of Tensor by Tensor.type(dtype)
, you can check what type you need via this link. Further, I recommend you should check if your GPU is available first and select float32
instead for float64
(in most case, 32 bits is enough complexity). So that line should become:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
y_train = y_train.type(torch.float32).to(device) # change torch.float32 to torch.float64 if you still want to use float 64
Upvotes: 3
Reputation: 3283
torch.float64 is a dtype object and not a function so it cannot be called.
To make it into a double float (or at least to make sure it is), I would instead call:
y_train = torch.from_numpy(y_train).double().cuda()
Upvotes: 2