コード例 #1
0
 def _setup_cntk_layer_def(self, cntk_layer_type, raw_layer, inputs_info):
     cntk_layer_def = cntkmodel.CntkLayersDefinition()
     cntk_layer_def.op_name = raw_layer.name
     cntk_layer_def.op_type = cntk_layer_type
     for input_info in inputs_info:
         cntk_layer_def.inputs.append(input_info.op_name)
     cntk_layer_def.outputs.append(raw_layer.name)
     getattr(SetupCaffeParameters,
             cntk_layer_type.name)(self._get_layer_parameters(raw_layer),
                                   inputs_info, cntk_layer_def)
     return cntk_layer_def
コード例 #2
0
    def _adapt_data_provider(self):
        if not self._raw_net:
            raise KeyError('Invalid net structure\n')
        raw_layers = self._raw_net.layer or self._raw_net.layers
        for raw_layer in raw_layers:
            if raw_layer.type != 'Input':
                continue
            if not self._inclusive_layer(raw_layer):
                continue

            for i in range(0, len(raw_layer.top)):
                data_provider = cntkmodel.CntkLayersDefinition()
                data_provider.op_name = raw_layer.top[i]
                data_provider.tensor = raw_layer.input_param.shape[i].dim[
                    1:]  # cancel mini-batch
                self._uni_model.data_provider.append(data_provider)
コード例 #3
0
def _install_test_layer(op_type, parameters, weights, input_data):
    para_cls_id = 'Cntk' + op_type + 'Parameters'
    para_instance = eval('.'.join(('cntkmodel', para_cls_id)))()
    for key, value in parameters.items():
        setattr(para_instance, key, value)
    layer_def = cntkmodel.CntkLayersDefinition()
    layer_def.parameters = para_instance
    layer_def.op_type = getattr(cntkmodel.CntkLayerType, utils.format.camel_to_snake(op_type))
    layer_def.op_name = '_'.join(('test', op_type))
    layer_def.parameter_tensor = []
    if weights is not None:
        for weight in weights:
            weight_tensor = cntkmodel.CntkTensorDefinition()
            weight_tensor.tensor = np.array(weight).shape
            weight_tensor.data = weight
            layer_def.parameter_tensor.append(weight_tensor)
    inputs_variable = []
    for input_tensor in input_data:
        inputs_variable.append(cntk.input(input_tensor.shape))
    return layer_def, inputs_variable