pytorchデータ型

2017 ワード

import torch

'''
pytorch GPU     ,          GPU         
pytorch  python     ,           CUDA GPU
   opencv-python  numpy           GPU/CUDA       
'''

a=torch.randn(2,3)

print(a.type())#torch.FloatTensor
print(type(a))#
'''
torch.Tensor.type()   pytorch tensor   ,
 type(a)  python  ,         ,
      tensor.type()
'''
'''
pytorch         torch.Tensor
 pytorch ,             /  
        torch.Tensor
'''
print(a.dtype)#torch.float32
print(a.device)#cpu   pytorch  tensor     CPU      GPU 
print(isinstance(a,torch.FloatTensor))#True
'''
isinstance             
'''
# print(isinstance(a,torch.cuda.FloatTensor))
# a=a.cuda()
# print(isinstance(a,torch.cuda.FloatTensor))

'''
pytorch    :dimension=0  torch.tensor     :loss  ,    torch.tensor  
prediciton   target        
         torch.tensor dimension=0   
    train.py        
loss=loss.item()
  tensor    
'''
a=torch.tensor(1.2)
print(a.shape)
print(len(a.shape))
print(a.size())
'''
tensor.shape   shape     
tensor.size()  size()     
'''

'''
pytorch dimension=1         
(1)bias         
bias dimension=1  tensor
(2)linear input
    linear regression  ,     one-dimension

torch.tensor          tensor      
torch.Tensor          tensor   (               )
'''
a=torch.tensor(1.325)
b=torch.Tensor(1)
c=torch.FloatTensor(2)

import numpy as np
data=np.ones(2)
d=torch.from_numpy(data)
#numpy.ndarray   torch.tensor

e=torch.randn(2,3)
data2=e.numpy()
#torch.tensor   numpy

print('a',a)
print('b',b)
print('c',c)
print('d',d)
print('data2',data2,type(data2))
'''
a tensor(1.3250)
b tensor([5.6052e-45])
c tensor([9.1365e-09, 4.5909e-41])
d tensor([1., 1.], dtype=torch.float64)
data2 [[-1.6662962  -0.4791848  -0.43611825]
 [-0.99609876  0.20896369 -0.7278052 ]] 
'''