Microsoft Cognitive Toolkit (CNTK), an open source deep-learning toolkit

Overview

CNTK

Chat Windows build status Linux build status
Join the chat at https://gitter.im/Microsoft/CNTK Build Status Build Status

The Microsoft Cognitive Toolkit (https://cntk.ai) is a unified deep learning toolkit that describes neural networks as a series of computational steps via a directed graph. In this directed graph, leaf nodes represent input values or network parameters, while other nodes represent matrix operations upon their inputs. CNTK allows users to easily realize and combine popular model types such as feed-forward DNNs, convolutional nets (CNNs), and recurrent networks (RNNs/LSTMs). It implements stochastic gradient descent (SGD, error backpropagation) learning with automatic differentiation and parallelization across multiple GPUs and servers. CNTK has been available under an open-source license since April 2015. It is our hope that the community will take advantage of CNTK to share ideas more quickly through the exchange of open source working code.

Installation

Installing nightly packages

If you prefer to use latest CNTK bits from master, use one of the CNTK nightly packages:

Learning CNTK

You can learn more about using and contributing to CNTK with the following resources:

More information

Disclaimer

Dear community,

With our ongoing contributions to ONNX and the ONNX Runtime, we have made it easier to interoperate within the AI framework ecosystem and to access high performance, cross-platform inferencing capabilities for both traditional ML models and deep neural networks. Over the last few years we have been privileged to develop such key open-source machine learning projects, including the Microsoft Cognitive Toolkit, which has enabled its users to leverage industry-wide advancements in deep learning at scale.

Today’s 2.7 release will be the last main release of CNTK. We may have some subsequent minor releases for bug fixes, but these will be evaluated on a case-by-case basis. There are no plans for new feature development post this release.

The CNTK 2.7 release has full support for ONNX 1.4.1, and we encourage those seeking to operationalize their CNTK models to take advantage of ONNX and the ONNX Runtime. Moving forward, users can continue to leverage evolving ONNX innovations via the number of frameworks that support it. For example, users can natively export ONNX models from PyTorch or convert TensorFlow models to ONNX with the TensorFlow-ONNX converter.

We are incredibly grateful for all the support we have received from contributors and users over the years since the initial open-source release of CNTK. CNTK has enabled both Microsoft teams and external users to execute complex and large-scale workloads in all manner of deep learning applications, such as historical breakthroughs in speech recognition achieved by Microsoft Speech researchers, the originators of the framework.

As ONNX is increasingly employed in serving models used across Microsoft products such as Bing and Office, we are dedicated to synthesizing innovations from research with the rigorous demands of production to progress the ecosystem forward.

Above all, our goal is to make innovations in deep learning across the software and hardware stacks as open and accessible as possible. We will be working hard to bring both the existing strengths of CNTK and new state-of-the-art research into other open-source projects to truly broaden the reach of such technologies.

With gratitude,

-- The CNTK Team

Microsoft Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

News

You can find more news on the official project feed

2019-03-29. CNTK 2.7.0

Highlights of this release

  • Moved to CUDA 10 for both Windows and Linux.
  • Support advance RNN loop in ONNX export.
  • Export larger than 2GB models in ONNX format.
  • Support FP16 in Brain Script train action.

CNTK support for CUDA 10

CNTK now supports CUDA 10. This requires an update to build environment to Visual Studio 2017 v15.9 for Windows.

To setup build and runtime environment on Windows:

To setup build and runtime environment on Linux using docker, please build Unbuntu 16.04 docker image using Dockerfiles here. For other Linux systems, please refer to the Dockerfiles to setup dependent libraries for CNTK.

Support advance RNN loop in ONNX export

CNTK models with recursive loops can be exported to ONNX models with scan ops.

Export larger than 2GB models in ONNX format

To export models larger than 2GB in ONNX format, use cntk.Function API: save(self, filename, format=ModelFormat.CNTKv2, use_external_files_to_store_parameters=False) with 'format' set to ModelFormat.ONNX and use_external_files_to_store_parameters set to True. In this case, model parameters are saved in external files. Exported models shall be used with external parameter files when doing model evaluation with onnxruntime.

2018-11-26.
Netron now supports visualizing CNTK v1 and CNTK v2 .model files.

NetronCNTKDark1 NetronCNTKLight1

Project changelog

2018-09-17. CNTK 2.6.0

Efficient group convolution

The implementation of group convolution in CNTK has been updated. The updated implementation moves away from creating a sub-graph for group convolution (using slicing and splicing), and instead uses cuDNN7 and MKL2017 APIs directly. This improves the experience both in terms of performance and model size.

As an example, for a single group convolution op with the following attributes:

  • Input tensor (C, H, W) = (32, 128, 128)
  • Number of output channels = 32 (channel multiplier is 1)
  • Groups = 32 (depth wise convolution)
  • Kernel size = (5, 5)

The comparison numbers for this single node are as follows:

First Header GPU exec. time (in millisec., 1000 run avg.) CPU exec. time (in millisec., 1000 run avg.) Model Size (in KB, CNTK format)
Old implementation 9.349 41.921 38
New implementation 6.581 9.963 5
Speedup/savings Approx. 30% Approx. 65-75% Approx. 87%

Sequential Convolution

The implementation of sequential convolution in CNTK has been updated. The updated implementation creates a separate sequential convolution layer. Different from regular convolution layer, this operation convolves also on the dynamic axis(sequence), and filter_shape[0] is applied to that axis. The updated implementation supports broader cases, such as where stride > 1 for the sequence axis.

For example, a sequential convolution over a batch of one-channel black-and-white images. The images have the same fixed height of 640, but each with width of variable lengths. The width is then represented by sequential axis. Padding is enabled, and strides for both width and height are 2.

 >>> f = SequentialConvolution((3,3), reduction_rank=0, pad=True, strides=(2,2), activation=C.relu)
 >>> x = C.input_variable(**Sequence[Tensor[640]])
 >>> x.shape
     (640,)
 >>> h = f(x)
 >>> h.shape
     (320,)
 >>> f.W.shape
     (1, 1, 3, 3)

Operators

depth_to_space and space_to_depth

There is a breaking change in the depth_to_space and space_to_depth operators. These have been updated to match ONNX specification, specifically the permutation for how the depth dimension is placed as blocks in the spatial dimensions, and vice-versa, has been changed. Please refer to the updated doc examples for these two ops to see the change.

Tan and Atan

Added support for trigonometric ops Tan and Atan.

ELU

Added support for alpha attribute in ELU op.

Convolution

Updated auto padding algorithms of Convolution to produce symmetric padding at best effort on CPU, without affecting the final convolution output values. This update increases the range of cases that could be covered by MKL API and improves the performance, E.g. ResNet50.

Default arguments order

There is a breaking change in the arguments property in CNTK python API. The default behavior has been updated to return arguments in python order instead of in C++ order. This way it will return arguments in the same order as they are fed into ops. If you wish to still get arguments in C++ order, you can simply override the global option. This change should only affect the following ops: Times, TransposeTimes, and Gemm(internal).

Bug fixes

  • Updated doc for Convolution layer to include group and dilation arguments.
  • Added improved input validation for group convolution.
  • Updated LogSoftMax to use more numerically stable implementation.
  • Fixed Gather op's incorrect gradient value.
  • Added validation for 'None' node in python clone substitution.
  • Added validation for padding channel axis in convolution.
  • Added CNTK native default lotusIR logger to fix the "Attempt to use DefaultLogger" error when loading some ONNX models.
  • Added proper initialization for ONNX TypeStrToProtoMap.
  • Updated python doctest to handle different print format for newer version numpy(version >= 1.14).
  • Fixed Pooling(CPU) to produce correct output values when kernel center is on padded input cells.

ONNX

Updates

  • Updated CNTK's ONNX import/export to use ONNX 1.2 spec.
  • Major update to how batch and sequence axes are handled in export and import. As a result, the complex scenarios and edge cases are handled accurately.
  • Updated CNTK's ONNX BatchNormalization op export/import to latest spec.
  • Added model domain to ONNX model export.
  • Improved error reporting during import and export of ONNX models.
  • Updated DepthToSpace and SpaceToDepth ops to match ONNX spec on the permutation for how the depth dimension is placed as block dimension.
  • Added support for exporting alpha attribute in ELU ONNX op.
  • Major overhaul to Convolution and Pooling export. Unlike before, these ops do not export an explicit Pad op in any situation.
  • Major overhaul to ConvolutionTranspose export and import. Attributes such as output_shape, output_padding, and pads are fully supported.
  • Added support for CNTK's StopGradient as a no-op.
  • Added ONNX support for TopK op.
  • Added ONNX support for sequence ops: sequence.slice, sequence.first, sequence.last, sequence.reduce_sum, sequence.reduce_max, sequence.softmax. For these ops, there is no need to expand ONNX spec. CNTK ONNX exporter just builds computation equivalent graphs for these sequence ops.
  • Added full support for Softmax op.
  • Made CNTK broadcast ops compatible with ONNX specification.
  • Handle to_batch, to_sequence, unpack_batch, sequence.unpack ops in CNTK ONNX exporter.
  • ONNX tests to export ONNX test cases for other toolkits to run and to validate.
  • Fixed Hardmax/Softmax/LogSoftmax import/export.
  • Added support for Select op export.
  • Added import/export support for several trigonometric ops.
  • Updated CNTK support for ONNX MatMul op.
  • Updated CNTK support for ONNX Gemm op.
  • Updated CNTK's ONNX MeanVarianceNormalization op export/import to latest spec.
  • Updated CNTK's ONNX LayerNormalization op export/import to latest spec.
  • Updated CNTK's ONNX PRelu op export/import to latest spec.
  • Updated CNTK's ONNX Gather op export/import to latest spec.
  • Updated CNTK's ONNX ImageScaler op export/import to latest spec.
  • Updated CNTK's ONNX Reduce ops export/import to latest spec.
  • Updated CNTK's ONNX Flatten op export/import to latest spec.
  • Added CNTK support for ONNX Unsqueeze op.

Bug or minor fixes:

  • Updated LRN op to match ONNX 1.2 spec where the size attribute has the semantics of diameter, not radius. Added validation if LRN kernel size is larger than channel size.
  • Updated Min/Max import implementation to handle variadic inputs.
  • Fixed possible file corruption when resaving on top of existing ONNX model file.

.Net Support

The Cntk.Core.Managed library has officially been converted to .Net Standard and supports .Net Core and .Net Framework applications on both Windows and Linux. Starting from this release, .Net developers should be able to restore CNTK Nuget packages using new .Net SDK style project file with package management format set to PackageReference.

The following C# code now works on both Windows and Linux:

 >>> var weightParameterName = "weight";
 >>> var biasParameterName = "bias";
 >>> var inputName = "input";
 >>> var outputDim = 2;
 >>> var inputDim = 3;
 >>> Variable inputVariable = Variable.InputVariable(new int[] { inputDim }, DataType.Float, inputName);
 >>> var weightParameter = new Parameter(new int[] { outputDim, inputDim }, DataType.Float, 1, device, weightParameterName);
 >>> var biasParameter = new Parameter(new int[] { outputDim }, DataType.Float, 0, device, biasParameterName);
 >>> 
 >>> Function modelFunc = CNTKLib.Times(weightParameter, inputVariable) + biasParameter;

For example, simply adding an ItemGroup clause in the .csproj file of a .Net Core application is sufficient: >>> >>> >>> >>> netcoreapp2.1 >>> x64 >>> >>> >>> >>> >>> >>> >>>

Bug or minor fixes:

  • Fixed C# string and char to native wstring and wchar UTF conversion issues on Linux.
  • Fixed multibyte and wide character conversions across the codebase.
  • Fixed Nuget package mechanism to pack for .Net Standard.
  • Fixed a memory leak issue in Value class in C# API where Dispose was not called upon object destruction.

Misc

2018-04-16. CNTK 2.5.1

Repack CNTK 2.5 with third party libraries included in the bundles (Python wheel packages)


2018-03-15. CNTK 2.5

Change profiler details output format to be chrome://tracing

Enable per-node timing. Working example here

  • per-node timing creates items in profiler details when profiler is enabled.
  • usage in Python:
import cntk as C
C.debugging.debug.set_node_timing(True)
C.debugging.start_profiler() # optional
C.debugging.enable_profiler() # optional
#<trainer|evaluator|function> executions
<trainer|evaluator|function>.print_node_timing()
C.debugging.stop_profiler()

Example profiler details view in chrome://tracing ProfilerDetailWithNodeTiming

CPU inference performance improvements using MKL

  • Accelerates some common tensor ops in Intel CPU inference for float32, especially for fully connected networks
  • Can be turned on/off by cntk.cntk_py.enable_cpueval_optimization()/cntk.cntk_py.disable_cpueval_optimization()

1BitSGD incorporated into CNTK

  • 1BitSGD source code is now available with CNTK license (MIT license) under Source/1BitSGD/
  • 1bitsgd build target was merged into existing gpu target

New loss function: hierarchical softmax

  • Thanks @yaochengji for the contribution!

Distributed Training with Multiple Learners

  • Trainer now accepts multiple parameter learners for distributed training. With this change, different parameters of a network can be learned by different learners in a single training session. This also facilitates distributed training for GANs. For more information, please refer to the Basic_GAN_Distributed.py and the cntk.learners.distributed_multi_learner_test.py

Operators

  • Added MeanVarianceNormalization operator.

Bug fixes

  • Fixed convergence issue in Tutorial 201B
  • Fixed pooling/unpooling to support free dimension for sequences
  • Fixed crash in CNTKBinaryFormat deserializer when crossing sweep boundary
  • Fixed shape inference bug in RNN step function for scalar broadcasting
  • Fixed a build bug when mpi=no
  • Improved distributed training aggregation speed by increasing packing threshold, and expose the knob in V2
  • Fixed a memory leak in MKL layout
  • Fixed a bug in cntk.convert API in misc.converter.py, which prevents converting complex networks.

ONNX

  • Updates
    • CNTK exported ONNX models are now ONNX.checker compliant.
    • Added ONNX support for CNTK’s OptimizedRNNStack operator (LSTM only).
    • Added support for LSTM and GRU operators
    • Added support for experimental ONNX op MeanVarianceNormalization.
    • Added support for experimental ONNX op Identity.
    • Added support for exporting CNTK’s LayerNormalization layer using ONNX MeanVarianceNormalization op.
  • Bug or minor fixes:
    • Axis attribute is optional in CNTK’s ONNX Concat operator.
    • Bug fix in ONNX broadcasting for scalars.
    • Bug fix in ONNX ConvTranspose operator.
    • Backward compatibility bug fix in LeakyReLu (argument ‘alpha’ reverted to type double).

Misc

  • Added a new API find_by_uid() under cntk.logging.graph.

2018-02-28. CNTK supports nightly build

If you prefer to use latest CNTK bits from master, use one of the CNTK nightly package.

Alternatively, you can also click corresponding build badge to land to nightly build page.


2018-01-31. CNTK 2.4

Highlights:

  • Moved to CUDA9, cuDNN 7 and Visual Studio 2017.
  • Removed Python 3.4 support.
  • Added Volta GPU and FP16 support.
  • Better ONNX support.
  • CPU perf improvement.
  • More OPs.

OPs

  • top_k operation: in the forward pass it computes the top (largest) k values and corresponding indices along the specified axis. In the backward pass the gradient is scattered to the top k elements (an element not in the top k gets a zero gradient).
  • gather operation now supports an axis argument
  • squeeze and expand_dims operations for easily removing and adding singleton axes
  • zeros_like and ones_like operations. In many situations you can just rely on CNTK correctly broadcasting a simple 0 or 1 but sometimes you need the actual tensor.
  • depth_to_space: Rearranges elements in the input tensor from the depth dimension into spatial blocks. Typical use of this operation is for implementing sub-pixel convolution for some image super-resolution models.
  • space_to_depth: Rearranges elements in the input tensor from the spatial dimensions to the depth dimension. It is largely the inverse of DepthToSpace.
  • sum operation: Create a new Function instance that computes element-wise sum of input tensors.
  • softsign operation: Create a new Function instance that computes the element-wise softsign of a input tensor.
  • asinh operation: Create a new Function instance that computes the element-wise asinh of a input tensor.
  • log_softmax operation: Create a new Function instance that computes the logsoftmax normalized values of a input tensor.
  • hard_sigmoid operation: Create a new Function instance that computes the hard_sigmoid normalized values of a input tensor.
  • element_and, element_not, element_or, element_xor element-wise logic operations
  • reduce_l1 operation: Computes the L1 norm of the input tensor's element along the provided axes.
  • reduce_l2 operation: Computes the L2 norm of the input tensor's element along the provided axes.
  • reduce_sum_square operation: Computes the sum square of the input tensor's element along the provided axes.
  • image_scaler operation: Alteration of image by scaling its individual values.

ONNX

  • There have been several improvements to ONNX support in CNTK.
  • Updates
    • Updated ONNX Reshape op to handle InferredDimension.
    • Adding producer_name and producer_version fields to ONNX models.
    • Handling the case when neither auto_pad nor pads atrribute is specified in ONNX Conv op.
  • Bug fixes
    • Fixed bug in ONNX Pooling op serialization
    • Bug fix to create ONNX InputVariable with only one batch axis.
    • Bug fixes and updates to implementation of ONNX Transpose op to match updated spec.
    • Bug fixes and updates to implementation of ONNX Conv, ConvTranspose, and Pooling ops to match updated spec.

Operators

  • Group convolution
    • Fixed bug in group convolution. Output of CNTK Convolution op will change for groups > 1. More optimized implementation of group convolution is expected in the next release.
    • Better error reporting for group convolution in Convolution layer.

Halide Binary Convolution

  • The CNTK build can now use optional Halide libraries to build Cntk.BinaryConvolution.so/dll library that can be used with the netopt module. The library contains optimized binary convolution operators that perform better than the python based binarized convolution operators. To enable Halide in the build, please download Halide release and set HALIDE_PATH environment varibale before starting a build. In Linux, you can use ./configure --with-halide[=directory] to enable it. For more information on how to use this feature, please refer to How_to_use_network_optimization.

See more in the Release Notes. Get the Release from the CNTK Releases page.

Issues
  • Regression Network with Multiple Outputs and UCI Fast Reader

    Regression Network with Multiple Outputs and UCI Fast Reader

    Hi, I am unable to get a regression network with multiple outputs to work using UCIFastReader. Is this possible?

    If I define a network with 2 output nodes like: SimpleNetworkBuilder = [ layerSizes = 12:2 ...

    and a UCIFastReader reader labels section as: labels = [ labelType = "regression" dim = 2 start = 12 labelMappingFile = "$DataDir$/label-mapping.txt" ]

    ...where label-mapping.txt is an empty file.

    When I run the train command it ends with the following: EXCEPTION occurred: NotifyFunctionValuesMBSizeModified: labels InputValue operation had its row dimension 2 changed by the reader to 1.

    If I change config to a network with one output node and change the reader section to dim = 1, then it works, so I think this somehow has to do with not being able to use the UCIFastReader for regression with multiple outputs, if that is the case - is there a way to do this with some different reader?

    area reader 
    opened by amirbegan 58
  • Iteration Plan (September - October 2017)

    Iteration Plan (September - October 2017)

    This plan captures our work from mid September to end of October. We will ship around November 22nd. Major work items of this iteration include ONNX support in CNTK, MKL integration, and many others.

    Endgame

    • November 8: Code freeze for the end game
    • November 22: Release date

    Planned items

    We plan to ship these items at the end of this iteration.

    Legend of annotations:

    | Icon | Description | |----------------- |----------------------------| |

  • [ ] | Item not started | |
  • [x] | Item finished | | 🏃 | Work in progress | | ✋ | Blocked | | 💪 | Stretch |

    Documentation

    • [ ] Finalize learner design and fix related documentation

    System

    • [x] Support import/export ONNX format models
    • [ ] A network optimization API that helps model compression via SVD, quantization, etc.
    • [ ] 16bit support for training on Volta GPU (limited functionality)
    • [ ] C# high-level API design (no implementation)
    • [ ] Reader improvement for large data sets (sequential reader)

    Examples

    • [ ] Faster R-CNN object detection
      • [ ] Clean up the code to use arbitrary input image size
      • [ ] C++ implementation of some Python layers
      • [ ] Usability improvement
    • [ ] New example for natural language processing (NLP)
    • [x] New tutorial on WGAN and LS-GAN
    • [ ] Semantic segmentation (stretch goal)

    Operations

    • [ ] Specify frequency in the number of epochs and minibatches for progress report, validation, checkpoints
    • [ ] Improve statistics for distributed evaluation

    Performance

    • [ ] Intel MKL update to improve inference speed on CPU by around 2x on AlexNet

    Others

    iteration plan 
  • opened by cha-zhang 49
  • Iteration Plan (August - September 2017)

    Iteration Plan (August - September 2017)

    This plan captures our work from early August to mid September. We will ship around September 15th. Major work items of this iteration include Volta 16bit support and C#/.NET API. There will also be numerous other improvements we will make as detailed below.

    Endgame

    • September 11: Code freeze for the end game
    • September 15: Release date

    Planned items

    We plan to ship these items at the end of this iteration.

    Legend of annotations:

    | Icon | Description | |----------------- |----------------------------| |

  • [ ] | Item not started | |
  • [x] | Item finished | | 🏃 | Work in progress | | ✋ | Blocked | | 💪 | Stretch |

    Documentation

    • [ ] Add HTML version of tutorials and manuals so that they can be searchable
    • [ ] Add missing evaluation documents

    System

    ✋ 16bit support for training on Volta GPU (limited functionality)

    • [ ] Update learner interface to simplify parameter setting and adding new learners (Potential breaking change)
    • [x] A preliminary C#/.NET API that enables people to train simple networks such as ConvNet on MNIST.
    • [ ] R-binding for training and evaluation (will be published in a separate repository) ✋ Improve statistics for distributed evaluation

    Examples

    • [ ] Faster R-CNN object detection
      • [ ] Enable arbitrary input image size via free static axis for convolution
      • [ ] C++ implementation of some Python layers
      • [ ] Usability improvement ✋ New example for natural language processing (NLP)
    • [ ] Semantic segmentation (stretch goal)

    Operations

    • [x] Noise contrastive estimation node
    • [ ] Aggregation on sparse gradient for embedded layer
    • [ ] Gradient as an operator (stretch goal)
    • [ ] Reduced rank for convolution in C++ to enable convolution on 1D data
    • [x] Dilated convolution

    Performance

    • [ ] Asynchronous evaluation API (Python and C#) ✋ Intel MKL update to improve inference speed on CPU by around 2x on AlexNet

    Keras and Tensorboard

    • [ ] Example on Keras and SKLearn multi-GPU support on CNTK
    • [ ] Image feature support with Tensorboard for CNTK

    Others

    iteration plan 
  • opened by cha-zhang 40
  • ND convolution and pooling

    ND convolution and pooling

    Hi all, thanks again for releasing this very powerful toolkit. I read the doc and run the MNIST example. In this example the "mnist_convert.py" resizes the 2d digit images in a feature vector of length 28x28. How can I implement something similar for 3d datasets? Would it work out of the box if I transform my data in a feature vector of length NX x NY x NZ? Is 3d convolution already supported?

    area samples area documentation 
    opened by Madgeeno 31
  • How to predict my images using trained-model file??

    How to predict my images using trained-model file??

    I am using ImageNet-sample python code.

    My main code is as follows,

    modelpath = 'BN-Inception_99.model'
    network = create_bn_inception_by_exist_model(modelpath)
    trainer = create_trainer(network, epoch_size, max_epochs, minibatch_size)
    train_source = create_image_mb_source(train_data, mean_data, True, total_number_of_samples=max_epochs * epoch_size)
    test_source = create_image_mb_source(test_data, mean_data, False, total_number_of_samples=FULL_DATA_SWEEP)
    train_re_source = create_image_mb_source(train_re_data, mean_data, False, total_number_of_samples=FULL_DATA_SWEEP)
    

    prediction_TRAIN_AND_TEST_existingmodel(network, trainer, train_source, test_source, train_re_source, progress_printer, max_epochs, minibatch_size, epoch_size, restore, profiler_dir, testing_parameters)

    And, "create_bn_inception_by_exist_model" function is this. def create_bn_inception_by_exist_model(modelpath):

    # Input variables denoting the features and label data
    feature_var = input_variable((NUM_CHANNELS, IMAGE_HEIGHT, IMAGE_WIDTH))
    label_var = input_variable((NUM_CLASSES))
    
    bn_time_const = 4096
    z = load_model(modelpath)
    
    # loss and metric
    ce  = cross_entropy_with_softmax(z, label_var)
    pe  = classification_error(z, label_var)
    pe5 = classification_error(z, label_var, topN=5)
    
    log_number_of_parameters(z)
    print()
    
    return {
        'feature': feature_var,
        'label'  : label_var,
        'ce'     : ce,
        'pe'     : pe,
        'pe5'    : pe5,
        'output' : z
    }
    

    And, "prediction_TRAIN_AND_TEST_existingmodel" function is this. def prediction_TRAIN_AND_TEST_existingmodel(network, trainer, train_source, test_source, train_re_source, progress_printer, max_epochs, minibatch_size, epoch_size, restore, profiler_dir, testing_parameters):

    # define mapping from intput streams to network inputs
    input_map = {
        network['feature']: train_source.streams.features,
        network['label']: train_source.streams.labels
    }
    # process minibatches and evaluate the model
    metric_numer    = 0
    metric_denom    = 0
    sample_count    = 0
    minibatch_index = 0
    
    top_k = 5    # top-5
    
    while sample_count < epoch_size:
        current_minibatch = min(minibatch_size, epoch_size - sample_count)
        # Fetch next test min batch for train data.
        data = train_re_source.next_minibatch(current_minibatch, input_map=input_map)
        # minibatch data to be trained with
        metric_numer += trainer.test_minibatch(data) * current_minibatch      ###### <- error code
    
        ## added edward.cho
        out = cntk.softmax(network['output'])
        print ("out :", out)
        predicted_label_probs = out.eval(data)
    

    BTW, I met some error(###### <- error code) in "prediction_TRAIN_AND_TEST_by_existingmodel" function.

    This is error message. metric_numer += trainer.test_minibatch(data) * current_minibatch File "/home/mirero/anaconda2/lib/python2.7/site-packages/cntk/train/trainer.py", line 223, in test_minibatch return super(Trainer, self).test_minibatch(arguments, device) File "/home/mirero/anaconda2/lib/python2.7/site-packages/cntk/cntk_py.py", line 2466, in test_minibatch return _cntk_py.Evaluator_test_minibatch(self, *args) ValueError: Values for 1 required arguments 'Input('Input3', [#], [3 x 224 x 224])', that the requested output(s) 'Output('aggregateEvalMetric', [], []), Output('Block4979_Output_0', [#], [1])' depend on, have not been provided.

    How should I do modify this code??

    opened by edwardcho 30
  • MPI error while compiling

    MPI error while compiling

    Hello,

    I'm facing an issue while I compile CNTK with MPI on a Ubuntu 14.04 machine. Here the steps I did:

    ../../configure --1bitsgd=yes
    Defaulting to --with-buildtype=release
    Found cuda at /usr/local/cuda-7.5
    Found gdk at /usr/.
    Found CUB at /usr/local/cub-1.4.1
    Found cuDNN at /usr/local
    Found OpenCV at /usr/local/opencv-3.0.0
    Cannot locate libzip files
    ImageReader will be built without zip container support.
    Generating /home/plu/git/CNTK/build/release/Config.make
    Generating /home/plu/git/CNTK/build/release/Makefile
    run
    >make -j all
    to build
    make all
    

    The error during the make is the following:

    creating /home/plu/git/CNTK/build/release/.build/Source/SGDLib/SGD.o for with build type release
    mpic++ -c Source/SGDLib/SGD.cpp -o /home/plu/git/CNTK/build/release/.build/Source/SGDLib/SGD.o -D_POSIX_SOURCE -D_XOPEN_SOURCE=600 -D__USE_XOPEN2K -std=c++11 -DUSE_CUDNN -DUSE_ACML -DNDEBUG -DNO_SYNC -DQUANTIZED_GRADIENT_AGGREGATION  -msse3 -std=c++0x -fopenmp -fpermissive -fPIC -Werror -fcheck-new -Wno-error=literal-suffix -g -O4 -ISource/Common/Include -ISource/Math -ISource/CNTK -ISource/ActionsLib -ISource/ComputationNetworkLib -ISource/SGDLib -ISource/SequenceTrainingLib -ISource/CNTK/BrainScript -ISource/Readers/ReaderLib -I/usr/./include/nvidia/gdk -I/usr/local/cub-1.4.1 -I/usr/local/cuda-7.5/include -I/usr/local/cuda/include -I/usr/local/acml5.3.1/ifort64_mp/include -I/usr/local/opencv-3.0.0/include -ISource/1BitSGD -MD -MP -MF /home/plu/git/CNTK/build/release/.build/Source/SGDLib/SGD.d
    Source/SGDLib/SGD.cpp: In instantiation of 'void Microsoft::MSR::CNTK::SGD<ElemType>::InitDistGradAgg(int, int) [with ElemType = float]':
    Source/SGDLib/SGD.cpp:2283:16:   required from here
    Source/SGDLib/SGD.cpp:1846:27: error: no matching function for call to 'Microsoft::MSR::CNTK::AllReduceDistGradAggregator<float>::AllReduceDistGradAggregator(std::shared_ptr<Microsoft::MSR::CNTK::MPIWrapper>&, int&, bool&, bool, bool&, int&, int&)'
                 m_distGradAgg = new AllReduceDistGradAggregator<ElemType>(m_mpi, m_numGradientBits, m_zeroThresholdFor1Bit, true /*useQuantizationForSelfStripe*/, m_bufferedAsyncGradientAggregation, traceLevel, m_syncStatsTrace);
                               ^
    Source/SGDLib/SGD.cpp:1846:27: note: candidate is:
    In file included from Source/SGDLib/SGD.cpp:12:0:
    Source/1BitSGD/AllReduceDistGradAggregator.h:43:5: note: Microsoft::MSR::CNTK::AllReduceDistGradAggregator<ElemType>::AllReduceDistGradAggregator(Microsoft::MSR::CNTK::MPIWrapper*, int, bool, bool, bool, int, int) [with ElemType = float]
         AllReduceDistGradAggregator(MPIWrapper* mpi, int nBits, bool zeroThresholdFor1Bit, bool useQuantizationForSelfStripe, bool useAsyncAggregation, int traceLevel, int syncStatsTrace)
         ^
    Source/1BitSGD/AllReduceDistGradAggregator.h:43:5: note:   no known conversion for argument 1 from 'std::shared_ptr<Microsoft::MSR::CNTK::MPIWrapper>' to 'Microsoft::MSR::CNTK::MPIWrapper*'
    Source/SGDLib/SGD.cpp: In instantiation of 'void Microsoft::MSR::CNTK::SGD<ElemType>::InitDistGradAgg(int, int) [with ElemType = double]':
    Source/SGDLib/SGD.cpp:2284:16:   required from here
    Source/SGDLib/SGD.cpp:1846:27: error: no matching function for call to 'Microsoft::MSR::CNTK::AllReduceDistGradAggregator<double>::AllReduceDistGradAggregator(std::shared_ptr<Microsoft::MSR::CNTK::MPIWrapper>&, int&, bool&, bool, bool&, int&, int&)'
                 m_distGradAgg = new AllReduceDistGradAggregator<ElemType>(m_mpi, m_numGradientBits, m_zeroThresholdFor1Bit, true /*useQuantizationForSelfStripe*/, m_bufferedAsyncGradientAggregation, traceLevel, m_syncStatsTrace);
                               ^
    Source/SGDLib/SGD.cpp:1846:27: note: candidate is:
    In file included from Source/SGDLib/SGD.cpp:12:0:
    Source/1BitSGD/AllReduceDistGradAggregator.h:43:5: note: Microsoft::MSR::CNTK::AllReduceDistGradAggregator<ElemType>::AllReduceDistGradAggregator(Microsoft::MSR::CNTK::MPIWrapper*, int, bool, bool, bool, int, int) [with ElemType = double]
         AllReduceDistGradAggregator(MPIWrapper* mpi, int nBits, bool zeroThresholdFor1Bit, bool useQuantizationForSelfStripe, bool useAsyncAggregation, int traceLevel, int syncStatsTrace)
         ^
    Source/1BitSGD/AllReduceDistGradAggregator.h:43:5: note:   no known conversion for argument 1 from 'std::shared_ptr<Microsoft::MSR::CNTK::MPIWrapper>' to 'Microsoft::MSR::CNTK::MPIWrapper*'
    In file included from Source/SGDLib/SimpleEvaluator.h:16:0,
                     from Source/SGDLib/SGD.h:9,
                     from Source/SGDLib/SGD.cpp:6:
    Source/SGDLib/SimpleDistGradAggregator.h: In instantiation of 'void Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradientsImpl(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, bool) [with ElemType = double]':
    Source/SGDLib/SimpleDistGradAggregator.h:110:129:   required from 'Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradients(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, int) [with ElemType = double]::__lambda23'
    Source/SGDLib/SimpleDistGradAggregator.h:110:112:   required from 'struct Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradients(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, int) [with ElemType = double]::__lambda23'
    Source/SGDLib/SimpleDistGradAggregator.h:111:57:   required from 'bool Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradients(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, int) [with ElemType = double]'
    Source/SGDLib/SGD.cpp:2608:3:   required from here
    Source/SGDLib/SimpleDistGradAggregator.h:283:186: error: 'MPI_Iallreduce' was not declared in this scope
                 MPI_Iallreduce(MPI_IN_PLACE, reductionBuffer, gradients[i]->GetNumElements(), MPIWrapper::GetDataType(reductionBuffer), MPI_SUM, m_mpi->Communicator(), &allReduceRequests[i]) || MpiFail("MPI_Iallreduce");
                                                                                                                                                                                              ^
    Source/SGDLib/SimpleDistGradAggregator.h: In instantiation of 'void Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradientsImpl(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, bool) [with ElemType = float]':
    Source/SGDLib/SimpleDistGradAggregator.h:110:129:   required from 'Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradients(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, int) [with ElemType = float]::__lambda23'
    Source/SGDLib/SimpleDistGradAggregator.h:110:112:   required from 'struct Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradients(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, int) [with ElemType = float]::__lambda23'
    Source/SGDLib/SimpleDistGradAggregator.h:111:57:   required from 'bool Microsoft::MSR::CNTK::SimpleDistGradAggregator<ElemType>::AggregateGradients(const std::vector<Microsoft::MSR::CNTK::Matrix<ElemType>*>&, Microsoft::MSR::CNTK::DistGradHeader*, int) [with ElemType = float]'
    Source/SGDLib/SGD.cpp:2608:3:   required from here
    Source/SGDLib/SimpleDistGradAggregator.h:283:186: error: 'MPI_Iallreduce' was not declared in this scope
    make[1]: *** [/home/plu/git/CNTK/build/release/.build/Source/SGDLib/SGD.o] Error 1
    make[1]: Leaving directory `/home/plu/git/CNTK'
    make: *** [all] Error 2
    

    My $LD_LIBRARY_PATH variable looks like this:

    /usr/local/cuda/lib64:/usr/local/acml5.3.1/ifort64/lib/:/usr/local/acml5.3.1/ifort64_mp/lib/:/usr/local/mpi/lib/
    

    The path where MPI is, is the same than the one proposed here

    Thanks for any help you can provide.

    opened by jplu 27
  • FastRCNN with CSEvalClient Rois question

    FastRCNN with CSEvalClient Rois question

    Hi,

    I'm working on CSEvalClient and I some questions regarding this piece of code:

    EvaluateObjectDetectionModel(); https://github.com/Microsoft/CNTK/commit/7eefb18dce9a6f8bf4e020f0dde37acb403e16dd

    1. This rois are the selective search rois from the original image projected to the resize image(1000x1000) and divide by 1000 to get the float values, right? The original image is WIN_20160803_11_28_42_Pro.jpg with 1080x1920

    // parse rois: groups of 4 floats corresponding to (x, y, w, h) for an ROI string roiCoordinates = "0.219 0.0 0.165 0.29 0.329 0.025 0.07 0.115 0.364 0.0 0.21 0.13 …....

    1. Where can I get the values of the rois obtain by?

    outputs = model.Evaluate(inputs, outDims.First().Key);

    “Outcome for ROI 31: 6 (gerkin) …”
    
    I want the values left,top,width,heigth of ROI number 31!
    

    Thks

    opened by pmfcdb 27
  • ValueError: Specified GPU device id (0) is invalid

    ValueError: Specified GPU device id (0) is invalid

    Hi, i have built CNTK GPU successfully, and i can run the FeedForwardNet.py example. However when i try to run the same example using GPU (try_set_default_device(cntk.device.gpu(0))) I get the following error :

    Traceback (most recent call last): File "FeedForwardNet.py", line 82, in try_set_default_device(cntk.device.gpu(0)) File "/CNTK/bindings/python/cntk/internal/swig_helper.py", line 69, in wrapper result = f(*args, **kwds) File "/CNTK/bindings/python/cntk/device.py", line 94, in gpu return cntk_py.DeviceDescriptor.gpu_device(device_id) ValueError: Specified GPU device id (0) is invalid.

    Build info:

    	Built time: May  1 2017 22:44:50
    	Last modified date: Mon May  1 12:04:32 2017
    	Build type: release
    	Build target: GPU
    	With 1bit-SGD: no
    	With ASGD: no
    	Math lib: mkl
    	CUDA_PATH: /usr/local/cuda-8.0/
    	CUB_PATH: /usr/local/cub-1.4.1
    	CUDNN_PATH: /usr/local/cudnn-5.1
    	Build Branch: master
    	Build SHA1: 4b9f8739c72068d70279f91b4b59923b2ae1fc3a (modified)
    

    +-----------------------------------------------------------------------------+ | NVIDIA-SMI 375.39 Driver Version: 375.39 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | |===============================+======================+======================| | 0 GeForce GTX 675M Off | 0000:01:00.0 N/A | N/A | | 0% 59C P0 N/A / N/A | 357MiB / 1984MiB | N/A Default | +-------------------------------+----------------------+----------------------+

    +-----------------------------------------------------------------------------+ | Processes: GPU Memory | | GPU PID Type Process name Usage | |=============================================================================| | 0 Not Supported | +-----------------------------------------------------------------------------+

    Anyone has faced this issue ? Thanks.

    opened by youssefhb 27
  • parallelTrain seems do not work

    parallelTrain seems do not work

    Hi, I use about 80 hours speech data to train a two hidden layer neural network with four gpus. There are 2048 nodes in each hidden layer. However, epochtime is almost two and a half hours. It takes too long time to finish an epoch. I wonder if I am doing something wrong. Here is my log file:

       SGD = [
        epochSize = 0
        minibatchSize = 1024
        learningRatesPerSample = 0.000078
        momentumPerMB = 0.9
        dropoutRate = 0.1
        maxEpochs = 50
        L2RegWeight = 0.00001
    
    ParallelTrain = [
    	parallelizationMethod = BlockMomentumSGD
    	distributedMBReading = true
    parallelizationStartEpoch = 1 
    	syncPerfStats = 5
    	BlockMomentumSGD=[
        syncPeriod = 120000
    blockMomentumAsTimeConstant = 1920000
        resetSGDMomentum = true
        useNesterovMomentum = true
        ]
       ]
    
      ]
    

    randomize is set to 1728000 in reader. The command line is: mpiexec -np 4 cntk configFile=config/cntk.config When I use about 10 hours data to train the same DNN, epochtime is only about 10 minutes by a single gpu. I have four kinds of features in the input layer, and two kinds of targets in the output layer. Does the feature reading and error calculating take so much time? Or am I doing something wrong during my training? GPU version is K40m. Thank you.

    opened by xqustc 26
  • BrainScript extension for Visual Studio Code

    BrainScript extension for Visual Studio Code

    Visual Studio Code is getting a huge momentum. It would be extremely nice if BrainScript had its own VS Code extension. BrainScript is amazing, however, it's still lacking support in the IDE that are actually used by the broader Microsoft dev community. An VS Code extension would significantly boost adoption of BrainScript, the software effort being modest.

    opened by vermorel 26
  • Request for a no-opencv dotnet release

    Request for a no-opencv dotnet release

    The opencv library gets included in the CNTK.CPUOnly release, but for apps which don't use it, it's large bloat. (40+MB currently) It would be great if you released a nuget package without it.

    opened by viraptor 0
  • Value goes invalid when using TestMinibatch

    Value goes invalid when using TestMinibatch

    I'm running an issue when calling trainer.PreviousMinibatchLossAverage() after a TestMinibatch run:

    var minibatchDataTest = minibatchTest.GetNextMinibatch(10, device);
    var mbData = new UnorderedMapVariableMinibatchData();
    mbData.Add(features, minibatchDataTest[featureTestStreamInfo]);
    mbData.Add(labels, minibatchDataTest[labelTestStreamInfo]);
    var testRes = trainer.TestMinibatch(mbData, device);
    Console.WriteLine($"test loss {trainer.PreviousMinibatchLossAverage()}");  // this raises exception
    

    The printed stack is:

    [CALL STACK]
        > CNTK::Internal::  UseSparseGradientAggregationInDataParallelSGD
        - CNTK::Value::  Create
        - CNTK::Internal::  UseSparseGradientAggregationInDataParallelSGD
        - CNTK::TrainingParameterSchedule<unsigned __int64>::  Transform
        - CNTK::Trainer::  PreviousMinibatchLossAverage
        - CSharp_CNTK_Trainer_PreviousMinibatchLossAverage
        - 00007FFDE9FB695B (SymFromAddr() error: The specified module could not be found.)
    

    I'm not even sure which value it is, since both minibatchDataTest[featureTestStreamInfo] and minibatchDataTest[labelTestStreamInfo] are valid both before and after the TestMinibatch call. (as reported by data.IsValid)

    opened by viraptor 0
  • CNTK Crash: No computation node mapping exists for Variable Placeholder

    CNTK Crash: No computation node mapping exists for Variable Placeholder

    When I am using keras with CNTK backend to load and predict on a LSTM model, CNTK crash with the following bug trace:

    About to throw exception 'Function 'Composite(Combine): Input('lstm_1_copy_LA_copy_LA_copy_LA_copy_CP_input', [#], [49 x 1]) -> Output('Plus1481_Output_0', [#], [1])': No computation node mapping exists for Variable Placeholder('Placeholder1594', [#, toSequence_Minus537_Output_0], [100]).'
    Traceback (most recent call last):
      File "exp1/job0/scripts/generation/script_prediction.py", line 121, in <module>
        _get_prediction(bk=bk, model_path=flags.model_path, batch_size=batch_size)
      File "exp1/job0/scripts/generation/script_prediction.py", line 42, in _get_prediction
        pred = model.predict(x,batch_size=batch_size)
      File "lib/python3.6/site-packages/keras/engine/training.py", line 1169, in predict
        steps=steps)
      File "lib/python3.6/site-packages/keras/engine/training_arrays.py", line 294, in predict_loop
        batch_outs = f(ins_batch)
      File "lib/python3.6/site-packages/keras/backend/cntk_backend.py", line 2016, in __call__
        output_values = self.metrics_func.eval(input_dict, as_numpy=False)
      File "cntk/cntk/bindings/python/cntk/ops/functions.py", line 733, in eval
        _, output_map = self.forward(arguments, outputs, device=device, as_numpy=as_numpy)
      File "cntk/cntk/bindings/python/cntk/internal/swig_helper.py", line 69, in wrapper
        result = f(*args, **kwds)
      File "cntk/cntk/bindings/python/cntk/ops/functions.py", line 867, in forward
        keep_for_backward)
      File "cntk/cntk/bindings/python/cntk/cntk_py.py", line 1980, in _forward
        return _cntk_py.Function__forward(self, *args)
    RuntimeError: Function 'Composite(Combine): Input('lstm_1_copy_LA_copy_LA_copy_LA_copy_CP_input', [#], [49 x 1]) -> Output('Plus1481_Output_0', [#], [1])': No computation node mapping exists for Variable Placeholder('Placeholder1594', [#, toSequence_Minus537_Output_0], [100]).
    
    

    Steps to reproduce: Please access the json configuration of the used lstm model from: https://drive.google.com/file/d/1BwXQEpnmutqW1sQOUhTP1e6StlqMh9uU/view?usp=sharing save the configuration file as model.json and then use the following script to reproduce bug:

    import os
    import argparse
    import sys
    import warnings
    import configparser
    import redis
    import pickle
    
    
    if __name__ == "__main__":
        parse = argparse.ArgumentParser()
        parse.add_argument("--backend", type=str, help="specify the backend")
        flags, _ = parse.parse_known_args(sys.argv[1:])
    
        bk = flags.backend
        os.environ["KERAS_BACKEND"] = bk
        os.environ["CUDA_VISIBLE_DEVICES"] = "0,1"
        warnings.filterwarnings("ignore", category=DeprecationWarning)
        warnings.filterwarnings("ignore", category=UserWarning)
        warnings.filterwarnings("ignore", category=FutureWarning)
        warnings.filterwarnings("ignore")
    
        if bk == "cntk":
            from cntk.device import try_set_default_device, gpu
            try_set_default_device(gpu(0))
        import numpy as np
        import keras
        model_path = "model.json"
        print("start loading the model")
        model = keras.models.model_from_json(open(model_path, "r").read())
        model.summary()
        input_shape = model.layers[0].input_shape
        input_shape = list(input_shape)
        input_shape[0] = 3
        input_shape = tuple(input_shape)
        x = np.random.rand(*input_shape)
        pred = model.predict(x)
        json = model.to_json()
        print(pred)
        print("successfully get the prediction result")
        del model
    

    Note that when I use the different backend of Keras such as TensorFlow and Theano, this model can be successfully loaded and predicted.

    opened by maybeLee 0
  • Revert

    Revert "disable fp16 test for poolWithSequenceAxis (#3810)"

    This reverts commit e9396480025b9ca457d26b6f33dd07c474c6aa04.

    opened by mahmoudallahham 0
  • Inconsistency in Gradients Calculation of reduce_max

    Inconsistency in Gradients Calculation of reduce_max

    Hi, I found that the gradients calculation of reduce_max in CNTK is different from other deep learning libraries such as tensorflow. And I want to know is it a bug?

    Here is an example code using CNTK2.7:

    import numpy as np
    import cntk as C
    
    x = C.input_variable(shape=(1, 3, 1), needs_gradient=True)
    x_val = np.array([[[0.6],
                       [0.6],
                       [0.3]]])
    
    y = C.reduce_max(x)
    g = y.grad({x: x_val})
    
    
    print("gradients of max: ", g)
    

    The result is:

    gradients of max:  [[[[1.]
                          [1.]
                          [0.]]]]
    

    And this is the code using TensorFlow2.6.0:

    import numpy as np
    import tensorflow as tf
    
    with tf.GradientTape() as tape:
        x = tf.Variable([[[0.6],
                          [0.6],
                          [0.3]]])
    
        y = tf.reduce_max(x)
    g = tape.gradient(y, x)
    
    
    print("gradients of max: ", g.numpy())
    

    The result is:

    gradients of max:  [[[0.5]
                         [0.5]
                         [0. ]]]
    

    The inconsistency exists when there are multiple max elements.

    Any replies will be appreciated.

    opened by River861 0
  • Sqrt of a negative value return zero instead of NaN

    Sqrt of a negative value return zero instead of NaN

    Hi, I found that sqrt function in cntk returns 0 instead of NaN for negative numbers, which is different from other deep learning libraries, such as tensorflow and theano. I'm not sure if this is a bug?

    >>> import cntk as C
    >>> C.sqrt(-1).eval()
    array(0., dtype=float32)
    >>> C.sqrt(-2).eval()
    array(0., dtype=float32)
    >>> C.sqrt(-4).eval()
    array(0., dtype=float32)
    

    Windows 10 x64, cntk 2.7.0, CPU only.

    opened by River861 1
  • C# CNTK Transfer Learning input reshape

    C# CNTK Transfer Learning input reshape

    Dear Sirs,

    I build program to apply Transfer Learning in C#. Problem I face is to reshape input layer for Resnet CNNs. Default input is [224x224x3] whereas I want to apply [32x32x3] input, but it could be any size.

    I wonder how I can reshape input layer dimension?

    Also I wonder if there is different way later to replace that input? I do it now like: Function clonedModel = baseModel.Clone(ParameterCloningMethod.Freeze, new Dictionary<Variable, Variable>() { { oldFeatureNode, normalizedNewNode } });

    Regards, Chris

    opened by KBS91 0
  • Which version of the CNTK to use for video cards 3070

    Which version of the CNTK to use for video cards 3070

    Hello! I tried to use version 2.7, but when I run the train model, the program freezes. Or when trying to use a model in C ++ after going into "model-> Evaluate (inputDataMap, outputDataMap, device);" the program also freezes.

    OS windows 10 x64, nvidia 3070, cntk 2.7.0 (also tried to use v2.8.0-rc0.dev20200201, same problems)

    opened by andreyiva111 1
  • Changing weight parameter in loss function and how to use weighted_binary_cross_entropy

    Changing weight parameter in loss function and how to use weighted_binary_cross_entropy

    Hi,

    So far getting good results on image segmentation with cntk, and I tried different loss functions to tweak the desired result. Using fixed class weights is simple enough, (unless I want to change the weight during training - as I don't see how to do this). My output is a per class propability map shape [numclasses, height,width]

    for example dice coeff weighted per class: weight is hwere a np array shape: [numclasses]

    def wdice_coefficient(x, y,weight,smooth=1.0): intersection = C.reduce_sum(x * y, axis=(1,2)) weighted = ((2.0 * intersection+smooth) / (C.reduce_sum(x, axis=(1,2)) + C.reduce_sum(y, axis=(1,2)) + smooth))*weight return C.reduce_sum(weighted)

    But I want to use a weight map per pixel. The only way I can make that work is to compute the map in the loss function from label map. it would be better to precompute the weight maps and give the weight image as input to the batch when training.

    def w_map_logistic(x, y,weight): # weight is now a [numclasses] array w_map = yweight+1 w_map=w_map/C.reduce_mean(w_map,axis=(1,2)) perclasslogistic=C.reduce_sum((yC.log(x)+(1-y)*C.log(1-x))*w_map,axis=(1,2)) return -C.reduce_sum(perclasslogistic)

    I want it to be like this instead: def w_map_logistic(x, y,w_map): # w_mapis here a [numclasses,h,w] array perclasslogistic=C.reduce_sum((y*C.log(x)+(1-y)*C.log(1-x))*w_map,axis=(1,2)) return -C.reduce_sum(perclasslogistic)

    where w_map is updated with each call to train_minibatch results=[] for i in range(0, int(numsamples / minibatch_size)): data_x, data_y = subslice_minibatch(trimages, trlabels,i, minibatch_size) data_x, data_y = augment( data_x.copy(), data_y.copy(),AugmentPercent ) #assign new weight maps here somehow trainer.train_minibatch({x: data_x, y: data_y}) results.append(trainer.previous_minibatch_loss_average)

    I also tried to use the builtin function weighted_binary_cross_entropy which accepts a weight map with shape [1, h, w] and [numclasses,h,w] as you define the loss function but it gives errors during training - dynamic axis error. Assuming this is due to not giving it the batch-related maps before calling train_minibatch. I cannot find an example how to do that. I tried making the weight map as a C.constant with a name (instead of numpy array) and assigning a new weight to this constant , and different variations of using unpack_batch, reconsolidate dynamic axis, (so I get [batchsize,numclass,h,w] arrays) but I just cant make it work as I get different variations of dynamic axis error and matrix dimension error.

    opened by sequoiagrove 1
Releases(v2.7)
Owner
Microsoft
Open source projects and samples from Microsoft
Microsoft
MMdnn is a set of tools to help users inter-operate among different deep learning frameworks. E.g. model conversion and visualization. Convert models between Caffe, Keras, MXNet, Tensorflow, CNTK, PyTorch Onnx and CoreML.

MMdnn MMdnn is a comprehensive and cross-framework tool to convert, visualize and diagnose deep learning (DL) models. The "MM" stands for model manage

Microsoft 5.4k Oct 22, 2021
Best Practices on Recommendation Systems

Recommenders What's New (February 4, 2021) We have a new relase Recommenders 2021.2! It comes with lots of bug fixes, optimizations and 3 new algorith

Microsoft 11.5k Oct 25, 2021
Azua - build AI algorithms to aid efficient decision-making with minimum data requirements.

Project Azua 0. Overview Many modern AI algorithms are known to be data-hungry, whereas human decision-making is much more efficient. The human can re

Microsoft 45 Oct 19, 2021
UniLM AI - Large-scale Self-supervised Pre-training across Tasks, Languages, and Modalities

Pre-trained (foundation) models across tasks (understanding, generation and translation), languages (100+ languages), and modalities (language, image, audio, vision + language, audio + language, etc.)

Microsoft 3.4k Oct 22, 2021
A fast, distributed, high performance gradient boosting (GBT, GBDT, GBRT, GBM or MART) framework based on decision tree algorithms, used for ranking, classification and many other machine learning tasks.

Light Gradient Boosting Machine LightGBM is a gradient boosting framework that uses tree based learning algorithms. It is designed to be distributed a

Microsoft 13.1k Oct 17, 2021
Malmo Collaborative AI Challenge - Team Pig Catcher

The Malmo Collaborative AI Challenge - Team Pig Catcher Approach The challenge involves 2 agents who can either cooperate or defect. The optimal polic

Kai Arulkumaran 65 Jun 29, 2021
A Dataset of Python Challenges for AI Research

Python Programming Puzzles (P3) This repo contains a dataset of python programming puzzles which can be used to teach and evaluate an AI's programming

Microsoft 744 Oct 19, 2021
Advanced Deep Learning with TensorFlow 2 and Keras (Updated for 2nd Edition)

Advanced Deep Learning with TensorFlow 2 and Keras (Updated for 2nd Edition)

Packt 1.1k Oct 21, 2021
All course materials for the Zero to Mastery Deep Learning with TensorFlow course.

All course materials for the Zero to Mastery Deep Learning with TensorFlow course.

Daniel Bourke 1.7k Oct 24, 2021
A comprehensive list of published machine learning applications to cosmology

ml-in-cosmology This github attempts to maintain a comprehensive list of published machine learning applications to cosmology, organized by subject ma

George Stein 211 Oct 15, 2021
The Incredible PyTorch: a curated list of tutorials, papers, projects, communities and more relating to PyTorch.

This is a curated list of tutorials, projects, libraries, videos, papers, books and anything related to the incredible PyTorch. Feel free to make a pu

Ritchie Ng 8.5k Oct 22, 2021
DeepSpeed is a deep learning optimization library that makes distributed training easy, efficient, and effective.

DeepSpeed is a deep learning optimization library that makes distributed training easy, efficient, and effective.

Microsoft 5.7k Oct 24, 2021
TAPEX: Table Pre-training via Learning a Neural SQL Executor

TAPEX: Table Pre-training via Learning a Neural SQL Executor The official repository which contains the code and pre-trained models for our paper TAPE

Microsoft 47 Oct 18, 2021
Code for the paper Language as a Cognitive Tool to Imagine Goals in Curiosity Driven Exploration

IMAGINE: Language as a Cognitive Tool to Imagine Goals in Curiosity Driven Exploration This repo contains the code base of the paper Language as a Cog

Flowers Team 15 Jul 6, 2021
Code for "LoRA: Low-Rank Adaptation of Large Language Models"

LoRA: Low-Rank Adaptation of Large Language Models This repo contains the implementation of LoRA in GPT-2 and steps to replicate the results in our re

Microsoft 154 Oct 20, 2021
🗣️ Microsoft Edge TTS for Home Assistant, no need for app_key

Microsoft Edge TTS for Home Assistant This component is based on the TTS service of Microsoft Edge browser, no need to apply for app_key. Install Down

null 29 Oct 21, 2021
The story of Chicken for Club Bing

Chicken Story tl;dr: The time when Microsoft banned my entire country for cheating at Club Bing. (A lot of the details are from memory so I've recreat

Eyal 140 Sep 10, 2021
TorchGeo is a PyTorch domain library, similar to torchvision, that provides datasets, transforms, samplers, and pre-trained models specific to geospatial data.

TorchGeo is a PyTorch domain library, similar to torchvision, that provides datasets, transforms, samplers, and pre-trained models specific to geospatial data.

Microsoft 80 Oct 19, 2021
Multiple paper open-source codes of the Microsoft Research Asia DKI group

?? Paper Code Collection (MSRA DKI Group) This repo hosts multiple open-source codes of the Microsoft Research Asia DKI Group. You could find the corr

Microsoft 158 Oct 13, 2021