singa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [singa] joddiy commented on a change in pull request #737: Add upsample operator
Date Tue, 16 Jun 2020 07:25:34 GMT

joddiy commented on a change in pull request #737:
URL: https://github.com/apache/singa/pull/737#discussion_r440639599



##########
File path: python/singa/autograd.py
##########
@@ -4698,6 +4698,82 @@ def cossim(a, b):
     return CosSim()(a, b)[0]
 
 
+class UpSample(Operator):
+    """
+    Init a UpSample operator

Review comment:
       fixed

##########
File path: python/singa/autograd.py
##########
@@ -4698,6 +4698,82 @@ def cossim(a, b):
     return CosSim()(a, b)[0]
 
 
+class UpSample(Operator):
+    """
+    Init a UpSample operator
+    """
+
+    def __init__(self, mode, scales):
+        """
+        Args:
+            scales (list[int]): The scale array along each dimension. It takes 
+                value greater than or equal to 1. 
+        """
+        super(UpSample, self).__init__()
+        self.scales = scales
+        self.mode = mode
+        if self.mode != "nearest":

Review comment:
       fixed

##########
File path: python/singa/autograd.py
##########
@@ -4698,6 +4698,82 @@ def cossim(a, b):
     return CosSim()(a, b)[0]
 
 
+class UpSample(Operator):
+    """
+    Init a UpSample operator
+    """
+
+    def __init__(self, mode, scales):
+        """
+        Args:
+            scales (list[int]): The scale array along each dimension. It takes 
+                value greater than or equal to 1. 
+        """
+        super(UpSample, self).__init__()
+        self.scales = scales
+        self.mode = mode
+        if self.mode != "nearest":
+            assert False, "only support nearest mode."
+
+    def forward(self, x):
+        """
+        forward of UpSample
+        Args:
+            x (CTensor): input tensor.
+        Returns:
+            the output CTensor.
+        """
+        if isinstance(self.scales, np.ndarray):
+            self.scales = self.scales.tolist()
+        else:
+            self.scales = list(self.scales)
+        self.x_shape = list(x.shape())
+        for axis, s in zip(range(len(self.scales)), self.scales):
+            s = int(s)
+            if s == 1:
+                continue
+            x = x.Repeat([s, ], axis)
+        return x
+
+    def backward(self, dy):
+        """
+        backward of UpSample

Review comment:
       fixed




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message