Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pytorch cuda tensor in module

import torch
import torch.nn as nn

class Model(nn.Module):
    def __init__(self):
        super(Model, self).__init__()
        self.weight = torch.nn.Parameter(torch.zeros(2, 1))
        self.bias = torch.nn.Parameter(torch.zeros(1))
        self.register_buffer('a_constant_tensor', torch.tensor([0.5]))

    def forward(self, x):
        # linear regression completely from scratch,
        # using parameters created in __init__
        x = torch.mm(x, self.weight) + self.bias + self.a_constant_tensor
        return x


model = Model().cuda()
Comment

PREVIOUS NEXT
Code Example
Python :: streamlit sidebar width 
Python :: Link In Django 
Python :: default values python 
Python :: python modules 
Python :: input code for python 
Python :: convert a string into a list 
Python :: Word2Vec 4.0 Gensim model python dataframe 
Python :: BaseSSHTunnelForwarderError: Could not establish session to SSH gateway 
Python :: .format python 3 
Python :: python zip folder and subfolders 
Python :: python convert bytes to string 
Python :: read api from django 
Python :: pandas dataframe any along row 
Python :: python list contains string 
Python :: python 3 tkinter treeview example 
Python :: read a function of excel in python 
Python :: get xlim python 
Python :: django channel 
Python :: copy dataframe columns names 
Python :: map a list to another list python 
Python :: Customizable TKinter Buttons Python 
Python :: how to use if else in python 
Python :: django change settings at runtime 
Python :: Python script for computing descriptive statistics 
Python :: How to install a python packagae 
Python :: number of elements in the array numpy 
Python :: get index of dataframe 
Python :: select random img in python using os.listdir 
Python :: add timestamp csv python 
Python :: concat sort 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =