def accuracy(y, t): y, t = as_variable(y), as_variable(t) pred = y.data.argmax(axis=1).reshape(t.shape) result = (pred == t.data) acc = result.mean() return Variable(as_array(acc))
def dropout(x, dropout_ratio=0.5): x = as_variable(x) if kdezero.Config.train: xp = cuda.get_array_module(x) mask = xp.random.rand(*x.shape) > dropout_ratio scale = xp.array(1.0 - dropout_ratio).astype(x.dtype) y = x * mask / scale return y else: return x
def reshape(x, shape): if x.shape == shape: return as_variable(x) return Reshape(shape)(x)
def broadcast_to(x, shape): if x.shape == shape: return as_variable(x) return BroadcastTo(shape)(x)
def sum_to(x, shape): if x.shape == shape: return as_variable(x) return SumTo(shape)(x)