Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug related to KerasSymbol.tensor #93

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions keras/backend/mxnet_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ def __init__(self, symbol, name=None, neighbor=None, is_var=False):


def bind(self, data):
self.tensor = data
if not hasattr(self, 'tensor'):
self.tensor = data
else:
self.tensor[:] = data

if self.name in self._bind_values:
assert self._bind_values[self.name].shape == data.shape, \
"Redefinition of variable %s" % self.name
Expand Down Expand Up @@ -884,7 +888,8 @@ def random_uniform_variable(shape, low, high, dtype=None,
value = mx.random.uniform(low=low, high=high, dtype='float32', shape=shape)
if dtype != np.float32:
value = mx.nd.Cast(value, dtype=dtype)
name = _autogen_name("uniform")
if name is None:
name = _autogen_name("uniform")
ret = KerasVariable(name, value.shape, value.dtype)
ret.bind(value)
return ret
Expand Down Expand Up @@ -923,7 +928,8 @@ def random_normal_variable(shape, mean, scale, dtype=None,
value = mx.random.normal(loc=mean, scale=scale, dtype='float32', shape=shape)
if dtype != np.float32:
value = mx.nd.Cast(value, dtype=dtype)
name = _autogen_name("normal")
if name is None:
name = _autogen_name("normal")
ret = KerasVariable(name, value.shape, value.dtype)
ret.bind(value)
return ret
Expand Down Expand Up @@ -2956,7 +2962,8 @@ def random_normal(shape, mean=0.0, std=1.0, dtype=None, seed=None):
if dtype is None:
dtype = floatx()
dtype = np.dtype(dtype)
name = _autogen_name('normal')
if name is None:
name = _autogen_name('normal')
sym = mx.sym.normal(loc=mean, scale=std, shape=shape, dtype='float32', name=name)
if dtype != np.float32:
sym = mx.sym.Cast(data=sym, dtype=dtype)
Expand All @@ -2983,7 +2990,8 @@ def random_uniform(shape, low=0.0, high=1.0, dtype=None, seed=None):
if dtype is None:
dtype = floatx()
dtype = np.dtype(dtype)
name = _autogen_name('uniform')
if name is None:
name = _autogen_name('uniform')
sym = mx.sym.uniform(low=low, high=high, shape=shape, dtype='float32', name=name)
if dtype != np.float32:
sym = mx.sym.Cast(data=sym, dtype=dtype)
Expand Down