本文整理匯總了Python中cntk.input方法的典型用法代碼示例。如果您正苦於以下問題:Python cntk.input方法的具體用法?Python cntk.input怎麽用?Python cntk.input使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cntk
的用法示例。
在下文中一共展示了cntk.input方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_basic_model
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def create_basic_model(input, out_dims):
net = C.layers.Convolution(
(5, 5), 32, init=C.initializer.glorot_uniform(), activation=C.relu, pad=True
)(input)
net = C.layers.MaxPooling((3, 3), strides=(2, 2))(net)
net = C.layers.Convolution(
(5, 5), 32, init=C.initializer.glorot_uniform(), activation=C.relu, pad=True
)(net)
net = C.layers.MaxPooling((3, 3), strides=(2, 2))(net)
net = C.layers.Convolution(
(5, 5), 64, init=C.initializer.glorot_uniform(), activation=C.relu, pad=True
)(net)
net = C.layers.MaxPooling((3, 3), strides=(2, 2))(net)
net = C.layers.Dense(64, init=C.initializer.glorot_uniform())(net)
net = C.layers.Dense(out_dims, init=C.initializer.glorot_uniform(), activation=None)(net)
return net
示例2: create_vgg9_model
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def create_vgg9_model(input, out_dims):
with C.layers.default_options(activation=C.relu):
model = C.layers.Sequential([
C.layers.For(range(3), lambda i: [
C.layers.Convolution(
(3, 3), [64, 96, 128][i], init=C.initializer.glorot_uniform(), pad=True
),
C.layers.Convolution(
(3, 3), [64, 96, 128][i], init=C.initializer.glorot_uniform(), pad=True
),
C.layers.MaxPooling((3, 3), strides=(2, 2))
]),
C.layers.For(range(2), lambda: [
C.layers.Dense(1024, init=C.initializer.glorot_uniform())
]),
C.layers.Dense(out_dims, init=C.initializer.glorot_uniform(), activation=None)
])
return model(input)
示例3: _padding
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def _padding(x, pattern, axis): # pragma: no cover
base_shape = x.shape
if b_any([dim < 0 for dim in base_shape]):
raise ValueError('CNTK Backend: padding input tensor with '
'shape `%s` contains non-specified dimension, '
'which is not supported. Please give fixed '
'dimension to enable padding.' % base_shape)
if pattern[0] > 0:
prefix_shape = list(base_shape)
prefix_shape[axis] = pattern[0]
prefix_shape = tuple(prefix_shape)
x = C.splice(C.constant(value=0, shape=prefix_shape), x, axis=axis)
base_shape = x.shape
if pattern[1] > 0:
postfix_shape = list(base_shape)
postfix_shape[axis] = pattern[1]
postfix_shape = tuple(postfix_shape)
x = C.splice(x, C.constant(value=0, shape=postfix_shape), axis=axis)
return x
示例4: _padding
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def _padding(x, pattern, axis):
base_shape = x.shape
if b_any([dim < 0 for dim in base_shape]):
raise ValueError('CNTK Backend: padding input tensor with '
'shape `%s` contains non-specified dimension, '
'which is not supported. Please give fixed '
'dimension to enable padding.' % base_shape)
if pattern[0] > 0:
prefix_shape = list(base_shape)
prefix_shape[axis] = pattern[0]
prefix_shape = tuple(prefix_shape)
x = C.splice(C.constant(value=0, shape=prefix_shape), x, axis=axis)
base_shape = x.shape
if pattern[1] > 0:
postfix_shape = list(base_shape)
postfix_shape[axis] = pattern[1]
postfix_shape = tuple(postfix_shape)
x = C.splice(x, C.constant(value=0, shape=postfix_shape), axis=axis)
return x
示例5: _padding
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def _padding(x, pattern, axis):
base_shape = x.shape
if b_any([dim < 0 for dim in base_shape]):
raise ValueError('CNTK Backend: padding input tensor with '
'shape `%s` contains non-specified dimension, '
'which is not supported. Please give fixed '
'dimension to enable padding.' % base_shape)
if pattern[0] > 0:
prefix_shape = list(base_shape)
prefix_shape[axis] = pattern[0]
prefix_shape = tuple(prefix_shape)
x = C.splice(C.constant(value=0, shape=prefix_shape), x, axis=axis)
base_shape = x.shape
if pattern[1] > 0:
postfix_shape = list(base_shape)
postfix_shape[axis] = pattern[1]
postfix_shape = tuple(postfix_shape)
x = C.splice(x, C.constant(value=0, shape=postfix_shape), axis=axis)
return x
示例6: create_terse_model
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def create_terse_model(input, out_dims):
with C.layers.default_options(activation=C.relu):
model = C.layers.Sequential([
C.layers.For(range(3), lambda i: [
C.layers.Convolution(
(5, 5), [32, 32, 64][i], init=C.initializer.glorot_uniform(), pad=True
),
C.layers.MaxPooling((3, 3), strides=(2, 2))
]),
C.layers.Dense(64, init=C.initializer.glorot_uniform()),
C.layers.Dense(out_dims, init=C.initializer.glorot_uniform(), activation=None)
])
return model(input)
示例7: create_dropout_model
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def create_dropout_model(input, out_dims):
with C.layers.default_options(activation=C.relu):
model = C.layers.Sequential([
C.layers.For(range(3), lambda i: [
C.layers.Convolution(
(5, 5), [32, 32, 64][i], init=C.initializer.glorot_uniform(), pad=True
),
C.layers.MaxPooling((3, 3), strides=(2, 2))
]),
C.layers.Dense(64, init=C.initializer.glorot_uniform()),
C.layers.Dropout(0.25),
C.layers.Dense(out_dims, init=C.initializer.glorot_uniform(), activation=None)
])
return model(input)
示例8: convolution_bn
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def convolution_bn(input, filter_size, num_filters, strides=(1, 1),
init=C.he_normal(), activation=C.relu):
if activation is None:
activation = lambda x: x
r = C.layers.Convolution(
filter_size, num_filters,
strides=strides, init=init,
activation=None, pad=True, bias=False
)(input)
# r = C.layers.BatchNormalization(map_rank=1)(r)
return activation(r)
示例9: resnet_basic_inc
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def resnet_basic_inc(input, num_filters):
c1 = convolution_bn(input, (3, 3), num_filters, strides=(2, 2))
c2 = convolution_bn(c1, (3, 3), num_filters, activation=None)
s = convolution_bn(input, (1, 1), num_filters, strides=(2, 2), activation=None)
return C.relu(c2 + s)
示例10: resnet_basic_stack
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def resnet_basic_stack(input, num_filters, num_stack):
assert num_stack > 0
r = input
for _ in range(num_stack):
r = resnet_basic(r, num_filters)
return r
示例11: create_resnet_model
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def create_resnet_model(input, out_dims):
conv = convolution_bn(input, (3, 3), 16)
r1_1 = resnet_basic_stack(conv, 16, 3)
r2_1 = resnet_basic_inc(r1_1, 32)
r2_2 = resnet_basic_stack(r2_1, 32, 2)
r3_1 = resnet_basic_inc(r2_2, 64)
r3_2 = resnet_basic_stack(r3_1, 64, 2)
pool = C.layers.AveragePooling(filter_shape=(8, 8), strides=(1, 1))(r3_2)
net = C.layers.Dense(out_dims, init=C.he_normal(), activation=None)(pool)
return net
示例12: placeholder
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def placeholder(
shape=None,
ndim=None,
dtype=None,
sparse=False,
name=None,
dynamic_axis_num=1):
if dtype is None:
dtype = floatx()
if not shape:
if ndim:
shape = tuple([None for _ in range(ndim)])
dynamic_dimension = C.FreeDimension if _get_cntk_version() >= 2.2 else C.InferredDimension
cntk_shape = [dynamic_dimension if s is None else s for s in shape]
cntk_shape = tuple(cntk_shape)
if dynamic_axis_num > len(cntk_shape):
raise ValueError('CNTK backend: creating placeholder with '
'%d dimension is not supported, at least '
'%d dimensions are needed.'
% (len(cntk_shape), dynamic_axis_num))
if name is None:
name = ''
cntk_shape = cntk_shape[dynamic_axis_num:]
x = C.input(
shape=cntk_shape,
dtype=_convert_string_dtype(dtype),
is_sparse=sparse,
name=name)
x._keras_shape = shape
x._uses_learning_phase = False
x._cntk_placeholder = True
return x
示例13: _is_input_shape_compatible
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def _is_input_shape_compatible(input, placeholder):
if hasattr(input, 'shape') and hasattr(placeholder, 'shape'):
num_dynamic = get_num_dynamic_axis(placeholder)
input_shape = input.shape[num_dynamic:]
placeholder_shape = placeholder.shape
for i, p in zip(input_shape, placeholder_shape):
if i != p and p != C.InferredDimension and p != C.FreeDimension:
return False
return True
示例14: _preprocess_conv2d_input
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def _preprocess_conv2d_input(x, data_format):
if data_format == 'channels_last':
# TF uses the last dimension as channel dimension,
# instead of the 2nd one.
# TH input shape: (samples, input_depth, rows, cols)
# TF input shape: (samples, rows, cols, input_depth)
x = C.transpose(x, (2, 0, 1))
return x
示例15: _preprocess_conv3d_input
# 需要導入模塊: import cntk [as 別名]
# 或者: from cntk import input [as 別名]
def _preprocess_conv3d_input(x, data_format):
if data_format == 'channels_last':
# TF uses the last dimension as channel dimension,
# instead of the 2nd one.
# TH input shape: (samples, input_depth, conv_dim1, conv_dim2, conv_dim3)
# TF input shape: (samples, conv_dim1, conv_dim2, conv_dim3,
# input_depth)
x = C.transpose(x, (3, 0, 1, 2))
return x