Skip to content

kyegomez/STE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-Modality

Straight Through Estimator

Implementation of STE in pytorch

import torch 
import torch.nn as nn


class STEFunc(torch.autograd.Function):
    @staticmethod
    def forward(ctx, input):
        return torch.sign(torch.clamp(input, min=-1.0, max=1.0))
    
    @staticmethod
    def backward(ctx, grad_output):
        #Bypass the non differterable operations
        return grad_output
    
class STE(nn.Module):
    def forward(self, input):
        return STEFunc.apply(input)
    

# random input
x = torch.randn(1, 3, 32, 32)

# STE
ste = STE()

# forward
y = ste(x)

print(y)

Citations

About

My Implementation of "Straight Through Estimate" in pytorch

Resources

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages