提交 e8756c30 authored 作者: Frederic Bastien's avatar Frederic Bastien

disable gradient of Images2Neibs for mode wrap_centered that is not implemented!

上级 418173f3
......@@ -47,7 +47,10 @@ class Images2Neibs(Op):
return Apply(self, [ten4, neib_shape,neib_step], [T.matrix(dtype=ten4.type.dtype)])
def grad(self, (x, neib_shape, neib_step), (gz,)):
return [neibs2images(gz, neib_shape, x.shape), None, None]
if self.mode=='valid':
return [neibs2images(gz, neib_shape, x.shape), None, None]
else:
raise NotImplementedError()
def c_code_cache_version(self):
return (3,)
......
......@@ -389,6 +389,22 @@ def test_neibs_grad_verify_grad():
if cuda.cuda_available:
unittest_tools.verify_grad(fn, [images_val], mode=mode_with_gpu)
def test_neibs_grad_verify_grad_warp_centered():
# It is not implemented for now. So test that we raise an error.
shape = (2,3,6,6)
images = T.dtensor4()
images_val = numpy.arange(numpy.prod(shape), dtype='float32').reshape(shape)
def fn(images):
return T.sum(T.sqr(images2neibs(images, (3,3),mode='wrap_centered')), axis=[0,1])
try:
unittest_tools.verify_grad(fn, [images_val], mode=mode_without_gpu)
raise Exception("Expected an error")
if cuda.cuda_available:
unittest_tools.verify_grad(fn, [images_val], mode=mode_with_gpu)
except NotImplementedError:
pass
if __name__ == '__main__':
#test_neibs_gpu()
#test_neibs()
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论