This commit is contained in:
Emad Barsoum 2017-03-16 16:30:04 -07:00
Родитель 4a93dd0021
Коммит f341959d9d
9 изменённых файлов: 19 добавлений и 26 удалений

Просмотреть файл

@ -115,7 +115,7 @@ def train_and_evaluate(reader, reader_test, model, epoch_size=50000, max_epochs=
criterion = create_criterion_function(model, normalize=lambda x: x / 256)
#debughelpers.dump_function(criterion, 'criterion')
#from cntk.graph import plot
#from cntk.logging.graph import plot
#plot(criterion, filename=os.path.join(model_path, "ConvNet_CIFAR10_DataAug.pdf"))
# iteration parameters

Просмотреть файл

@ -137,7 +137,7 @@ def train(reader, model, max_epochs):
labels = reader.streams.slot_labels
#labels = reader.streams.intent_labels # for intent classification
#from cntk.graph import plot
#from cntk.logging.graph import plot
#plot(criterion, filename=data_dir + "/model.pdf")
# iteration parameters --needed here because learner schedule needs it

Просмотреть файл

@ -78,7 +78,7 @@ class DataReader(object):
# From the end of the file there are probably some leftover lines
if len(feature_sequences) > 0:
yield C.one_hot(feature_sequences, self.vocab_dim), C.one_hot(label_sequences, self.vocab_dim), token_count
yield C.Value.one_hot(feature_sequences, self.vocab_dim), C.one_hot(label_sequences, self.vocab_dim), token_count

Просмотреть файл

@ -375,7 +375,7 @@ class Value(cntk_py.Value):
>>> sparse_indices = [[1,5],[4]]
>>> i0 = C.input_variable(shape=num_classes, is_sparse=True)
>>> z = C.times(i0, np.eye(num_classes))
>>> value = C.one_hot(sparse_indices, num_classes)
>>> value = C.Value.one_hot(sparse_indices, num_classes)
>>> z.eval({i0: value})
[array([[ 0., 1., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 1.]], dtype=float32),
@ -386,7 +386,7 @@ class Value(cntk_py.Value):
>>> sparse_indices = [[1,5,3,2],[4,1]]
>>> i0 = C.input_variable(shape=sample_shape, is_sparse=True)
>>> z = C.times(i0, np.eye(num_classes))
>>> value = C.one_hot(sparse_indices, sample_shape)
>>> value = C.Value.one_hot(sparse_indices, sample_shape)
>>> z.eval({i0: value})
[array([[[ 0., 1., 0., 0., 0., 0.],
[ 0., 0., 0., 0., 0., 1.]],

Просмотреть файл

@ -368,7 +368,7 @@ class _DebugNode(UserFunction):
def _nodes_to_debug(model):
from cntk.graph import depth_first_search
from cntk.logging.graph import depth_first_search
def node_filter(x):
if hasattr(x, 'op_name') and x.op_name in ['NoOp']:
@ -421,7 +421,7 @@ def debug_model(model, in_stream=sys.stdin, out_stream=sys.stdout,
for n in nodes}
model = model.clone(CloneMethod.share, modifications)
from cntk.graph import plot
from cntk.logging.graph import plot
nodes = _nodes_to_debug(model)
if len(nodes) == 1:

Просмотреть файл

@ -158,7 +158,7 @@ def Embedding(shape=None, init=default_override_or(glorot_uniform()), weights=No
>>> e = f(x)
>>> e.shape
(5,)
>>> e(C.one_hot([[1], [0], [0], [1]], num_classes=2))
>>> e(C.Value.one_hot([[1], [0], [0], [1]], num_classes=2))
array([[[ 0.7, 0.6, 0.3, 0.2, 0.9]],
<BLANKLINE>
[[ 0.5, 0.3, 0.1, 0.4, 0.2]],

Просмотреть файл

@ -2655,19 +2655,6 @@ def constant(value=None, shape=None, dtype=None, device=None, name=''):
:class:`~cntk.ops.variables.Constant`
'''
from .variables import Constant
if not device:
device = use_default_device()
if (np.isscalar(value) or isinstance(value, np.ndarray)) and not shape:
shape = ()
if dtype is not None:
if isinstance(value, np.ndarray) and dtype != value.dtype:
value = np.array(value, dtype=dtype)
else:
if isinstance(value, np.ndarray):
dtype = value.dtype
else:
dtype = np.float32
return Constant(value, shape, dtype, device, name)
##########################################################################

Просмотреть файл

@ -542,7 +542,7 @@ class Function(cntk_py.Function):
>>> # 1st sequence: word 1
>>> # 2nd sequence: words 2 and 4
>>> batch = [[1],[2,4]]
>>> sparse_batch = C.one_hot(batch, vocab_size)
>>> sparse_batch = C.Value.one_hot(batch, vocab_size)
>>> _, fv = f.forward({v:sparse_batch})
>>> list(fv.values())[0]
[array([[ 0., 1., 0., 0., 0.]], dtype=float32),

Просмотреть файл

@ -300,15 +300,21 @@ class Constant(VariableMixin, TensorOpsMixin, cntk_py.Constant):
'''
def __init__(self, value=None, shape=None, dtype=None, device=None, name=''):
if dtype is None:
if not device:
device = use_default_device()
if (np.isscalar(value) or isinstance(value, np.ndarray)) and not shape:
shape = ()
if dtype is not None:
if isinstance(value, np.ndarray) and dtype != value.dtype:
value = np.array(value, dtype=dtype)
else:
if isinstance(value, np.ndarray):
dtype = value.dtype
else:
dtype = np.float32
if device is None:
device = DeviceDescriptor.use_default_device()
if np.isscalar(value):
super(Constant, self).__init__(sanitize_shape(shape),
sanitize_dtype_cntk(dtype), value, device, name)