Giter Club home page Giter Club logo

neoml-lib / neoml Goto Github PK

View Code? Open in Web Editor NEW
758.0 30.0 124.0 74.75 MB

Machine learning framework for both deep learning and traditional algorithms

Home Page: https://www.abbyy.com/neoml/

License: Apache License 2.0

C 2.46% Shell 0.01% Batchfile 0.04% Makefile 0.06% CMake 1.19% Java 0.19% C++ 67.39% Objective-C 0.09% Objective-C++ 1.74% Kotlin 0.28% Swift 0.34% Cuda 2.06% Metal 2.55% Python 5.57% Jupyter Notebook 1.31% Assembly 14.69% BitBake 0.02%
ml machine-learning deep-learning cpp onnx neural-network

neoml's Introduction

NeoML

Desktop Build Status Python Build iOS Build Android Build Documentation Status

NeoML is an end-to-end machine learning framework that allows you to build, train, and deploy ML models. This framework is used by ABBYY engineers for computer vision and natural language processing tasks, including image preprocessing, classification, document layout analysis, OCR, and data extraction from structured and unstructured documents.

Key features:

  • Neural networks with support for over 100 layer types
  • Traditional machine learning: 20+ algorithms (classification, regression, clustering, etc.)
  • CPU and GPU support, fast inference
  • ONNX support
  • Languages: Python, C++, Java, Objective-C
  • Cross-platform: the same code can be run on Windows, Linux, macOS, iOS, and Android

Contents

Build and install

Supported platforms

The full С++ library version has been tested on the platforms:

Target OS Compiler Architecture
Windows 7+ (CPU and GPU) MSVC 2019+ x86, x86_64
Ubuntu 14+ (CPU) gcc 5.4+ x86_64
MacOS 10.11+ (CPU) Apple clang 12+ arm64, x86_64
iOS 11+ (CPU, GPU) Apple clang 12+ arm64-v8a, x86_64
Android 5.0+ (CPU), Android 7.0+ (GPU) clang 7+ armeabi-v7a, arm64-v8a, x86, x86_64

The inference Java and Objective-C library versions have been tested on the platforms:

Target OS Compiler Architecture
iOS 11+ (CPU, GPU) Apple clang 12+ arm64-v8a, x86_64
Android 5.0+ (CPU), Android 7.0+ (GPU) clang 7+ armeabi-v7a, arm64-v8a, x86, x86_64

Third party

The library is built with CMake (recommended versions 3.18 and later).

For best CPU performance on Windows, Linux and macOS we use Intel MKL.

When processing on a GPU, you can optionally use CUDA (version 11.2 upd.1) on Windows or Linux and Vulkan (version 1.1.130 and later) on Windows, Linux or Android.

We also use Google Test for testing and Google Protocol Buffers for working with ONNX model format.

We use very convinous generator of JIT code xbyak for speeding up some convolutions on x86_64 processors.

Build fully functional C++ version

See here for instructions on building the C++ library version for different platforms.

Build inference versions for Java and Objective-C

See here for instructions on building the Java and Objective-C versions that would only run the trained neural networks.

Getting started

Several tutorials with sample code will help you start working with the library:

API description

Basic principles

The library was developed with these principles in mind:

Platform independence

The user interface is completely separated from the low-level calculations implemented by a math engine.

The only thing you have to do is to specify at the start the type of the math engine that will be used for calculations. You can also choose to select the math engine automatically, based on the device configuration detected.

The rest of your machine learning code will be the same regardless of the math engine you choose.

Math engines independence

Each network works with one math engine instance, and all its layers should have been created with the same math engine. If you have chosen a GPU math engine, it will perform all calculations. This means you may not choose to use a CPU for "light" calculations like adding vectors and a GPU for "heavy" calculations like multiplying matrices. We have introduced this restriction to avoid unnecessary synchronizations and data exchange between devices.

Multi-threading support

The math engine interface is thread-safe; the same instance may be used in different networks and different threads.

Note that this may entail some synchronization overhead.

However, the neural network implementation is not thread-safe; the network may run only in one thread.

ONNX support

NeoML library also works with the models created by other frameworks, as long as they support the ONNX format. See the description of import API. However, you cannot export a NeoML-trained model into ONNX format.

Serialization format

The library uses its own binary format (implemented by CArchive, CArchiveFile) to save and load the trained models.

GPU support

Processing on GPU often helps significantly improve performance of mathematical operations. The NeoML library uses GPU both for training and running the models. This is an optional setting and depends on the hardware and software capabilities of your system.

To work on GPU, the library requires:

  • Windows: NVIDIA® GPU card with CUDA® 11.2 upd. 1 support.
  • iOS: Apple GPU A7+.
  • Android: devices with Vulkan 1.0 support.
  • Linux/macOS: no support for GPU processing as yet.

FineObj

The NeoML library originates in ABBYY internal infrastructure. For various reasons ABBYY uses a cross-platform framework called FineObj. Because of this, the open library version uses some of this framework primitives. See the common classes description.

C++ interface

NeoML contains two C++ libraries:

Algorithms library NeoML

The library provides C++ objects that implement various high-level algorithms. It consists of several parts:

NeoMathEngine

The math engine used for calculations is a separate module that implements the low-level mathematical functions used in the algorithms library. The user can also call these functions but usually never needs to.

This module has different implementations for different platforms. In particular, there is an implementation that uses a GPU for calculations.

The math engine is also a set of C++ interfaces described here.

Python module

See the extensive documentation of the Python module on readthedocs.io.

Java interface

To work with the inference version of the library in Java and Kotlin we provide a Java interface.

Objective-C interface

To work with the inference version of the library in Swift and Objective-C we provide an Objective-C interface.

License

Copyright © 2016-2020 ABBYY Production LLC. Licensed under the Apache License, Version 2.0. See the license file.

neoml's People

Contributors

alekseylebedev avatar black-boomerang avatar daniyalaliev avatar dependabot[bot] avatar dmitrysolntsev avatar eaglemango avatar favorart avatar fedyuninv avatar kalyakinaad avatar kartonstyle avatar kkvadrat289 avatar lordnn avatar masepi avatar nadyag avatar ndrewl avatar neoml-maintainer avatar nismohl2 avatar nvalerij avatar reisei avatar sangeliuk avatar sansanch5 avatar slon872 avatar templatevoid avatar timuriskahov avatar valinurovdenis avatar voropz avatar yekatkov avatar yuryvatlin avatar zigrazor avatar zimka avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

neoml's Issues

Simple NN example issue

Hello! I'm trying to recreate simple net example, but I'm stuck here:

for( int epoch = 1; epoch < 15; ++epoch ) {
    float epochLoss = 0; // total loss for the epoch
    for( int iter = 0; iter < iterationPerEpoch; ++iter ) {
        // trainData methods are used to transmit the data into the blob
        trainData.GetSamples( iter * batchSize, dataBlob );
        trainData.GetLabels( iter * batchSize, labelBlob );

        net.RunAndLearnOnce(); // run the learning iteration
        epochLoss += loss->GetLastLoss(); // add the loss value on the last step
    }

    ::printf( "Epoch #%02d    avg loss: %f\n", epoch, epochLoss / iterationPerEpoch );
    trainData.ReShuffle( random ); // reshuffle the data
}

I don't understand what class is trainData (and testData) and can't find GetSamples and GetLabels functions on my own. Please help.

.NET Core Support

Is there any chance of supporting .net core?
For C++ integration is possible to use the C++ CLR which can wrap C++ and make all classes available in the .NET environment.

Now there are very few normal libraries for .net, despite the fact that it has long been cross-platform.

Inconsistent naming

// MathEngine blob data types
enum TBlobType {
CT_Invalid = 0,
CT_Float,
CT_Int,
};

CT_* -> BT_*

Clamp proposal

Раз PR вы не принимаете, оформлю как issue.
Сделайте в namespace NeoML себе что-то такое и перестаньте писать многоэтажные сравнения:

#if __cplusplus >= 201703L
using std::clamp;
#else
template<typename T, typename Compare = std::less<T>> constexpr const T& clamp(const T &v, const T &lo, const T &hi, Compare comp = Compare()) {
    return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
}
#endif

Code style

Why do you use both keywords 'virtual' and 'override' in methods definition? It's redundantly and hard to read, because semantics for this keywords are different.

Using overflow safe softplus calculation in binary focal loss layer.

This code is not overflow safe because of e^(-y*r):

// entropyValues = log(1 + e^(-y*r))

Overflow safe code:

//calculates log(1 + e^x)
void CalculateSoftPlus( const CConstFloatHandle& firstHandle,
	const CFloatHandle& resultHandle, int batchSize ) const
{
        //log(1 + e^x) = log( 1 + e^-|x| ) + max( 0, x ) 

	CFloatHandleStackVar temp( MathEngine(), batchSize );

	// |x|
	MathEngine().VectorAbs( firstHandle, temp, batchSize );

	// -|x|
	CFloatHandleStackVar one( MathEngine() );
	one.SetValue( 1.f );
	MathEngine().VectorNegMultiply( temp, temp, batchSize, one );

	// e^(-|x|)
	MathEngine().VectorExp( temp, temp, batchSize );

	CFloatHandleStackVar onesVector( MathEngine(), batchSize );
	MathEngine().VectorFill( onesVector, 1.0f, batchSize );

	// 1 + e^(-|x|)
	MathEngine().VectorAdd( onesVector, temp, temp, batchSize );
	//log(1 + e^(-|x|)) = 
	MathEngine().VectorLog( temp, temp, batchSize );

	CFloatHandleStackVar zero( MathEngine() );
	zero.SetValue( 0.f );
        //max( 0, x )
	MathEngine().VectorReLU( firstHandle, resultHandle, batchSize, zero );
        //log(1 + e^x) = log( 1 + e^-|x| ) + max( 0, x ) 
	MathEngine().VectorAdd( temp, resultHandle, resultHandle, batchSize );
}

Error?

Seems like in backward stage sign of inputDiffBlobs[1] must be negative.

void CEltwiseSubLayer::BackwardOnce()
{
for( int i = 0; i < inputDiffBlobs.Size(); ++i ) {
MathEngine().VectorCopy( inputDiffBlobs[i]->GetData(), outputDiffBlobs[0]->GetData(),
inputDiffBlobs[i]->GetDataSize() );
}
}

Non-const arguments for const params

virtual void BlobChannelwiseConvolution( const CChannelwiseConvolutionDesc& desc, const CConstFloatHandle& source,
	const CConstFloatHandle& filter, const CConstFloatHandle* freeTerm, const CFloatHandle& result ) = 0;
  • ok, const handles for filter and free term.
virtual void BlobConvolution( const CConvolutionDesc& desc, const CFloatHandle& source,
	const CFloatHandle& filter, const CFloatHandle* freeTerm, const CFloatHandle& result ) = 0;
  • why?!

protobuf errors on Astra Linux on master

/usr/bin/ld: /usr/lib/x86_64-linux-gnu/libprotobuf.a(arena.o): relocation R_X86_64_TPOFF32 against symbol `_ZN6google8protobuf5Arena13thread_cache_E' can not be used when making a shared object; перекомпилируйте с параметром -fPIC
/usr/bin/ld: final link failed: Раздел, непредставимый для вывода
collect2: error: ld returned 1 exit status
NeoOnnx/src/CMakeFiles/NeoOnnx.dir/build.make:581: ошибка выполнения рецепта для цели «NeoOnnx/src/libNeoOnnx.so»
make[2]: *** [NeoOnnx/src/libNeoOnnx.so] Ошибка 1
CMakeFiles/Makefile2:266: ошибка выполнения рецепта для цели «NeoOnnx/src/CMakeFiles/NeoOnnx.dir/all»
make[1]: *** [NeoOnnx/src/CMakeFiles/NeoOnnx.dir/all] Ошибка 2
Makefile:160: ошибка выполнения рецепта для цели «all»
make: *** [all] Ошибка 2

L1 loss

BatchCalculateLossAndGradient( int batchSize, NeoML::CConstFloatHandle data,
	int vectorSize, NeoML::CConstFloatHandle label, int labelSize, NeoML::CFloatHandle lossValue, NeoML::CFloatHandle lossGradient )
{
	assert( isInitialized );
	assert( vectorSize == 1 );
	assert( vectorSize == labelSize );

	const int totalSize = batchSize * vectorSize;

	MathEngine().VectorSub( data, label, lossValue, totalSize );

	if( !lossGradient.IsNull() ) {
		CFloatHandleStackVar onesVector( MathEngine(), totalSize );
		MathEngine().VectorFill( onesVector, 1.0f, totalSize );

		MathEngine().VectorAbsDiff( lossValue, onesVector, lossGradient, totalSize );
	}

	MathEngine().VectorAbs( lossValue, lossValue, totalSize );
}

Please add OHEM

Please add online hard example mining (OHEM) based on BCE, L1, L2 and other losses for binary classification.

Loss = SumOfPositiveClassLosses / + alpha* SumOfNegativeClassLosses / + beta * SumOfHARDNegativeClassLosses / <number of hard negative class examples>

hard negatives are top K negative class elements with highest loss value.

alpha, beta, K are external parameters.

Unexpected Source Layer

All layers as layers, placed to Dnn/Layers/..., and are called CDnnConvLayer, CDnnPoolingLayer. But the Source layer placed to Dnn/Dnn.h and is called CSourceLayer. Not cool.

error LNK2019 when building the library NeoOnnx.dll

Hello.
I am building a library on windows 10, MSVC 2019 x64, protobuf 3.18.1 . I get two errors:

onnx.pb.obj : error LNK2019: ссылка на неразрешенный внешний символ "class google::protobuf::internal::ExplicitlyConstr
ucted<class std::basic_string<char,struct std::char_traits,class std::allocator > > google::protobuf::inter
nal::fixed_address_empty_string" (?fixed_address_empty_string@internal@protobuf@google@@3v?$ExplicitlyConstructed@V?$basic_string@DU?$char_traits@D@std@@v?$allocator@D@2@@std@@@123@A) в функции "public: virtual class onnx::ValueInfoProto* __cdecl onnx::ValueInfoProto::New(void)const " (?New@ValueInfoProto@onnx@@UEBAPEAV12@XZ). [H:\libs\neoml2.0.22.0\Build\NeoOnnx\src\NeoOnnx.vcxproj]

onnx.pb.obj : error LNK2019: ссылка на неразрешенный внешний символ "struct std::atomic google::protobuf::interna
l::init_protobuf_defaults_state" (?init_protobuf_defaults_state@internal@protobuf@google@@3u?$atomic@_N@std@@A) в функции "public: virtual unsigned char * __cdecl onnx::TensorShapeProto_Dimension::_InternalSerialize(unsigned char *,class
google::protobuf::io::EpsCopyOutputStream *)const " (?_InternalSerialize@TensorShapeProto_Dimension@onnx@@UEBAPEAEPEAEPEAVEpsCopyOutputStream@io@protobuf@google@@@z). [H:\libs\neoml2.0.22.0\Build\NeoOnnx\src\NeoOnnx.vcxproj]

H:\libs\neoml2.0.22.0\Build\NeoOnnx\src\Release\NeoOnnx.dll : fatal error LNK1120: неразрешенных внешних элементов: 2 [
H:\libs\neoml2.0.22.0\Build\NeoOnnx\src\NeoOnnx.vcxproj]

How fix it?
Thank you!

Incorrect assert in CFirstComeClustering

This assert in deleteTinyClusters seems incorrect. Because of why number of features (matrix.Width ) affects on cluster size to be deleted? According to classic ML algorithm, it shouldn't. Fix it, please.

// Deletes the clusters that are too small
void CFirstComeClustering::deleteTinyClusters( const CSparseFloatMatrixDesc& matrix, const CArray<double>& weights,
	CObjectArray<CCommonCluster>& clusters )
{
	int threshold = Round( init.MinClusterSizeRatio * matrix.Width );

	NeoAssert( threshold <= matrix.Height ); // a cluster may not have more than the total number of elements
...
}

Calling virtual method from class destructor.

Class CDnn::DeleteLayerImpl method must be marked as 'final'. Because in case of overriding it after inheritance it will work in a wrong way when called from CDnn destructor. Same issue with the CCompositeLayer::DeleteLayerImpl.

Condition is always false

In CVulkanMathEngine::MultiplyMatrixByDiagMatrix method, const variable toAdd used as a condition in ternary operator (two times).

build fails on AArch64, Fedora 33

[jw@cn05 build]$ cmake --build . --target install
...
In file included from /data/jw/neoml/NeoMathEngine/src/CPU/CpuMathEngineDnn3dConv.cpp:25:
/data/jw/neoml/NeoMathEngine/src/CPU/CpuMathEnginePrivate.h:29:10: fatal error: CpuArm.h: No such file or directory
29 | #include <CpuArm.h>
| ^~~~~~~~~~
compilation terminated.
[12/83] Building CXX object NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnTimeConv.cpp.o
FAILED: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnTimeConv.cpp.o
/usr/bin/c++ -DBUILD_NEOMATHENGINE -DNEOML_USE_AVX -DNEOML_USE_OMP -DNeoMathEngine_EXPORTS -D_FINAL -D_LINUX -I/data/jw/neoml/NeoMathEngine/src/../include -I/data/jw/neoml/NeoMathEngine/src -I/data/jw/neoml/NeoMathEngine/src/CPU -I/data/jw/neoml/NeoMathEngine/src/CPU/x86 -O2 -DNDEBUG -fPIC -fvisibility=hidden -fopenmp -Wall -Wextra -Wpedantic -Wno-deprecated-declarations -Wno-unused-value -Wno-unknown-pragmas -Wno-strict-overflow -MD -MT NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnTimeConv.cpp.o -MF NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnTimeConv.cpp.o.d -o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnTimeConv.cpp.o -c /data/jw/neoml/NeoMathEngine/src/CPU/CpuMathEngineDnnTimeConv.cpp
In file included from /data/jw/neoml/NeoMathEngine/src/CPU/CpuMathEngineDnnTimeConv.cpp:24:
/data/jw/neoml/NeoMathEngine/src/CPU/CpuMathEnginePrivate.h:29:10: fatal error: CpuArm.h: No such file or directory
29 | #include <CpuArm.h>
| ^~~~~~~~~~
compilation terminated.
[40/83] Building CXX object _deps/googletest-build/googletest/CMakeFiles/gtest.dir/src/gtest-all.cc.o
ninja: build stopped: subcommand failed.
[jw@cn05 build]$

Two instances of Platforms.h

NeoML and NeoMathEngine both contains identically Platforms.h files. Will be better to use only one instance.

Possible missing includes, for openblas and Intel's MKL libs

Hi. Performed my build attempt on Ubuntu 20 x86_64, with Clang 11.0 RC2 + Ninja 1.10.0 + CMake 3.18.2:
$ cmake -G Ninja -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DMKL_CORE_LIB="/media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/intel_mkl_install/mkl/lib" -DMKL_INCLUDE_DIR="/media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/intel_mkl_install/mkl/include" -DMKL_SEQUENTIAL_LIB="/media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/intel_mkl_install/mkl/lib" -DMKL_INTEL_LIB="/media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/intel_mkl_install/mkl/lib" ../NeoML
-- The CXX compiler identification is Clang 11.0.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - NOTFOUND
-- No CUDA support.
-- Found OpenMP_CXX: -fopenmp=libomp (found version "5.0")
-- Found OpenMP: TRUE (found version "5.0")
-- Found MKL: /media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/intel_mkl_install/mkl/include
-- Looking for C++ include pthread.h
-- Looking for C++ include pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Found Protobuf: /usr/lib/x86_64-linux-gnu/libprotobuf.a;-pthread (found version "3.6.1")
-- Found protoc compiler: /usr/bin/protoc
-- Configuring done
WARNING: Target "NeoMathEngine" requests linking to directory "/media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/intel_mkl_install/mkl/lib". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
-- Build files have been written to: /media/ubuntu/4d5fa4ce-dc9b-4cb0-934c-72533ffc1586/neoml-master/build1

$ninja

[1/36] Linking CXX shared library NeoMathEngine/src/libNeoMathEngine.so
FAILED: NeoMathEngine/src/libNeoMathEngine.so
: && /usr/bin/clang++ -fPIC -Wl,--no-undefined -shared -Wl,-soname,libNeoMathEngine.so -o NeoMathEngine/src/libNeoMathEngine.so NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/common.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineBlas.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnn3dConv.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnConv.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnChannelwiseConv.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnDropout.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnn.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnPooling.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnRleConv.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineDnnTimeConv.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngine.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngineVectorMath.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CrtAllocatedObject.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/DllLoader.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/MathEngineDeviceStackAllocator.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/MathEngineDnnDropout.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/MathEngine.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/MathEngineHostStackAllocator.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/MemoryPool.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/PerformanceCountersCpuLinux.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlas.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineDnn.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMath.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineDnn3dConv.cpp.o -Wl,-rpath,:::::::::::::::::::::: /usr/lib/libomp.so /usr/lib/x86_64-linux-gnu/libpthread.so -Wl,--start-group -Wl,--end-group -pthread -ldl && :
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngine.cpp.o: in function .omp_outlined.': CpuMathEngine.cpp:(.text+0x251): undefined reference to MKL_Thread_Free_Buffers'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/CpuMathEngine.cpp.o: in function NeoML::CCpuMathEngine::~CCpuMathEngine()': CpuMathEngine.cpp:(.text+0x11ee): undefined reference to MKL_Free_Buffers'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::multiplyMatrixByMatrix(NeoML::CTypedMemoryHandle<float const> const&, int, int, int, NeoML::CTypedMemoryHandle<float const> const&, int, int, NeoML::CTypedMemoryHandle<float> const&, int, int)': CpuX86MathEngineBlasMkl.cpp:(.text+0x3a6): undefined reference to cblas_sgemm'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::multiplyMatrixByMatrixAndAdd(NeoML::CTypedMemoryHandle<float const> const&, int, int, int, NeoML::CTypedMemoryHandle<float const> const&, int, int, NeoML::CTypedMemoryHandle<float> const&, int, int)': CpuX86MathEngineBlasMkl.cpp:(.text+0x6f7): undefined reference to cblas_sgemm'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::multiplyMatrixByTransposedMatrix(NeoML::CTypedMemoryHandle<float const> const&, int, int, int, NeoML::CTypedMemoryHandle<float const> const&, int, int, NeoML::CTypedMemoryHandle<float> const&, int, int)': CpuX86MathEngineBlasMkl.cpp:(.text+0xa05): undefined reference to cblas_sgemm'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::multiplyMatrixByTransposedMatrixAndAdd(float const*, int, int, int, float const*, int, int, float*, int)': CpuX86MathEngineBlasMkl.cpp:(.text+0xaea): undefined reference to cblas_sgemm'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::MultiplySparseMatrixByTransposedMatrix(int, int, int, NeoML::CSparseMatrixDesc const&, NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&)': CpuX86MathEngineBlasMkl.cpp:(.text+0xfbb): undefined reference to mkl_sparse_s_create_csr'
/usr/bin/ld: CpuX86MathEngineBlasMkl.cpp:(.text+0x1133): undefined reference to mkl_sparse_s_mm' /usr/bin/ld: CpuX86MathEngineBlasMkl.cpp:(.text+0x1219): undefined reference to MKL_Simatcopy'
/usr/bin/ld: CpuX86MathEngineBlasMkl.cpp:(.text+0x1225): undefined reference to mkl_sparse_destroy' /usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::MultiplyTransposedMatrixBySparseMatrixAndAdd(int, int, int, NeoML::CTypedMemoryHandle const&, NeoML::CSparseMatrixDesc const&, NeoML::CTypedMemoryHandle const&)':
CpuX86MathEngineBlasMkl.cpp:(.text+0x1844): undefined reference to MKL_Somatcopy' /usr/bin/ld: CpuX86MathEngineBlasMkl.cpp:(.text+0x1894): undefined reference to mkl_sparse_s_create_csr'
/usr/bin/ld: CpuX86MathEngineBlasMkl.cpp:(.text+0x1a82): undefined reference to mkl_sparse_s_mm' /usr/bin/ld: CpuX86MathEngineBlasMkl.cpp:(.text+0x1b74): undefined reference to mkl_sparse_destroy'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::multiplyTransposedMatrixByMatrix(NeoML::CTypedMemoryHandle<float const> const&, int, int, NeoML::CTypedMemoryHandle<float const> const&, int, NeoML::CTypedMemoryHandle<float> const&, int)': CpuX86MathEngineBlasMkl.cpp:(.text+0x1e07): undefined reference to cblas_sgemm'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineBlasMkl.cpp.o: in function NeoML::CCpuMathEngine::multiplyTransposedMatrixByMatrixAndAdd(NeoML::CTypedMemoryHandle<float const> const&, int, int, int, NeoML::CTypedMemoryHandle<float const> const&, int, int, NeoML::CTypedMemoryHandle<float> const&, int, int)': CpuX86MathEngineBlasMkl.cpp:(.text+0x21ff): undefined reference to cblas_sgemm'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o: in function NeoML::CCpuMathEngine::VectorExp(NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&, int)': CpuX86MathEngineVectorMathMkl.cpp:(.text+0x31e): undefined reference to vsExp'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o: in function NeoML::CCpuMathEngine::VectorLog(NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&, int)': CpuX86MathEngineVectorMathMkl.cpp:(.text+0x6be): undefined reference to vsLn'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o: in function NeoML::CCpuMathEngine::VectorMultiplyAndAdd(NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&, int, NeoML::CTypedMemoryHandle<float const> const&)': CpuX86MathEngineVectorMathMkl.cpp:(.text+0xae1): undefined reference to cblas_saxpy'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o: in function NeoML::CCpuMathEngine::VectorTanh(NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&, int)': CpuX86MathEngineVectorMathMkl.cpp:(.text+0xcd2): undefined reference to vsTanh'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o: in function NeoML::CCpuMathEngine::VectorPower(float, NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&, int)': CpuX86MathEngineVectorMathMkl.cpp:(.text+0xeb9): undefined reference to vsPowx'
/usr/bin/ld: NeoMathEngine/src/CMakeFiles/NeoMathEngine.dir/CPU/x86/CpuX86MathEngineVectorMathMkl.cpp.o: in function NeoML::CCpuMathEngine::VectorEltwiseLogSumExp(NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float const> const&, NeoML::CTypedMemoryHandle<float> const&, int)': CpuX86MathEngineVectorMathMkl.cpp:(.text+0x1706): undefined reference to vsLog1p'
clang-11: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

override Layer::Serialize in wrong manner

Very often you override Serialize() method for SomeLayer class only for setting SerializeVersion to archive. Better to add some virtual method to setup correct SerializeVersion. In some over cases you override it to add some suffix info, but you have working mechanism for it in CCompositeLayer, you may expand serializationHook idea to whole Layers hierarchy.

Better to use '__ANDROID__'

Platforms.h (both instances)
Better to use predefined macro '__ANDROID__', because '_ANDROID' is not so stable (not sure about past, looks like it's absent in latest NDK's).

Mismatch '_ITERATOR_DEBUG_LEVEL'

Have a bunch mkl related linker errors when compiling NeoMathEngine. Could someone help me and tell what is this all about, since I can't look inside mkl dll? Neo ML was build with FineObjects option turned off (if it makes any difference).

Severity Code Description Project File Line Suppression State
Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in common.obj NeoMathEngine K:\NeoML\build\NeoMathEngine\src\mkl_core.lib(_avx512_jit_destroy.obj) 1
Severity Code Description Project File Line Suppression State
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in common.obj NeoMathEngine K:\NeoML\build\NeoMathEngine\src\mkl_core.lib(_avx512_jit_destroy.obj) 1
Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in common.obj NeoMathEngine K:\NeoML\build\NeoMathEngine\src\mkl_core.lib(_avx2_jit_destroy.obj) 1
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in common.obj NeoMathEngine K:\NeoML\build\NeoMathEngine\src\mkl_core.lib(_avx2_jit_destroy.obj) 1
Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in common.obj NeoMathEngine K:\NeoML\build\NeoMathEngine\src\mkl_core.lib(_avx_jit_destroy.obj) 1
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in common.obj NeoMathEngine K:\NeoML\build\NeoMathEngine\src\mkl_core.lib(_avx_jit_destroy.obj) 1

Cannot open NeoMathEngine.x64.Debug.lib

NeoML showing linker error. In Qt it looks like this:

:-1: error: LNK1104: cannot open file 'NeoMathEngine.x64.Debug.lib'

And in built libraries there is nowhere to be found NeoMathEngine.x64.Debug.lib.
When I'm trying with Visual studio, I'm getting following output:

Severity	Code	Description	Project	File	Line	Suppression State
Error	C3861	'NOT_FOUND': identifier not found	NeoMLTest2	K:\NeoML\build64\debug\include\NeoML\TraditionalML\LdGraph.h	438	

Code snippet where error is located seems to be some kind of assertion, but I can't understand what's wrong:

inline void CLdGraph<Arc>::DetachArc( Arc* arc )
{
	// Delete the arcs from the starting node
	CLdGraphVertex* initial = vertices[arc->InitialCoord() - begin];
	NeoPresume( initial != 0 );
	int i = initial->OutgoingArcs.Find(arc);
	NeoAssert( i != NOT_FOUND ); //     PROBLEM IS HERE
	initial->OutgoingArcs.DeleteAt(i);
	// Delete the hanging node
	if( initial->OutgoingArcs.Size() == 0
		&&  initial->IncomingArcs.Size() == 0 )
	{
		delete initial;
		vertices[arc->InitialCoord() - begin] = 0;
	}

I have 4 of those errors.

What's the difference?

I see no difference between VectorMultiplyAndAdd.comp and VectorMultiplyAndSub.comp. Is this correct?

Speed issue of precision-recall quality control layer

Please implement calculation of positivesCorrect, positivesTotal, negativesCorrect, negativesTotal on device side.

void CPrecisionRecallLayer::RunOnceAfterReset()
{
CPtr<CDnnBlob> inputBlob = inputBlobs[0];
CPtr<CDnnBlob> expectedLabelsBlob = inputBlobs[1];
CArray<float> labels;
labels.SetSize( expectedLabelsBlob->GetObjectCount() );
expectedLabelsBlob->CopyTo( labels.GetPtr(), labels.Size() );
CArray<float> networkOutputs;
networkOutputs.SetSize( inputBlob->GetObjectCount() );
inputBlob->CopyTo( networkOutputs.GetPtr(), networkOutputs.Size() );
for( int i = 0; i < inputBlob->GetObjectCount(); i++ ) {
if( labels[i] > 0 ) {
if( networkOutputs[i] >= 0 ) {
positivesCorrect++;
}
positivesTotal++;
} else {
if( networkOutputs[i] < 0 ) {
negativesCorrect++;
}
negativesTotal++;
}
}

Bug in CCrossValidationSubProblem

Hello

In the CCrossValidationSubProblem::GetMatrix() code returns matrix of original problem.
Code:

virtual CSparseFloatMatrixDesc GetMatrix() const { return problem->GetMatrix(); }

It is wrong in case it has wrong number of vectors.

It leads to the problems whyle training gradient bosting classifier, because it builds IProblem wrappes inside (those wrappers use GetMatrix while constructing)

May be can be fixed by 'return matrix'

Undefined weights blob dimensions

**CFullyConnectedLayer:**

// The dimensions of the blob are NumOfElements * InputHeight * InputWidth * InputChannelsCount
CPtr<CDnnBlob> GetWeightsData() const;

// The free term blob should be of NumOfElements size
CPtr<CDnnBlob> GetFreeTermData() const;

**CBaseConvLayer:**


// A filter blob has the FilterCount * FilterHeight * FilterWidth * FilterDepth * InputChannelsCount dimensions
// (or InputChannelsCount * FilterHeight * FilterWidth * FilterDepth * FilterCount dimensions for transposed filters)
virtual CPtr<CDnnBlob> GetFilterData() const;
// The blob should be of FilterCount size
virtual CPtr<CDnnBlob> GetFreeTermData() const;

CDnnBlob has 7 dimensions, and there are no clues which dimension is FilterCount, FilterWidth, FilterHeight etc.
Please, clarify it via adding ones, for example:

// A filter blob has the 1 * FilterCount * FilterHeight * FilterWidth * FilterDepth * 1 * InputChannelsCount dimensions

PS: Why CFullyConnectedLayer has Weights but CBaseConvLayer has Filter?

CMatchingGenerator misses some obvious matches

For some inputs CMatchingGenerator generates suboptimal matchings. Certain objects are effectively left unmatched, even though they have a match in the other set.
Here is a test I wrote that should pass but is currently failing. I found a few "bad" examples, this is one of the smallest. Here, two checks are passing, but the last one is failing: EXPECT_EQ( 7, FindMatchForLeft( 5 ) ). Instead, left no.5 is matched to a different element with a score of 0.

TEST( CMatchingGenerator, UniqueMatches6x8 )
{
    struct CMyPair {
        typedef int Quality;

        int LeftIndex = -1;
        int RightIndex = -1;
        Quality Score = 0;

        Quality Penalty() const { return 1 - Score; }
    };
    const int numLeft = 6;
    const int numRight = 8;
    const int pairScores[numRight][numLeft] = {
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0},
        {0, 0, 0, 1, 0, 0},  // Left #3 matches right #5
        {0, 0, 0, 0, 1, 0},  // Left #4 matches right #6
        {0, 0, 0, 0, 0, 1}   // Left #5 matches right #7
    };
    NeoML::CMatchingGenerator< CMyPair > generator( numLeft, numRight, 0, INT_MAX );
    for( int leftInd = 0; leftInd < numLeft; ++leftInd ) {
        for( int rightInd = 0; rightInd < numRight; ++rightInd ) {
            CMyPair& pair = generator.PairMatrix()(leftInd, rightInd);
            pair.LeftIndex = leftInd;
            pair.RightIndex = rightInd;
            pair.Score = pairScores[rightInd][leftInd];
        }
    }
    generator.Build();
    CArray<CMyPair> matching;
    generator.GetNextMatching( matching );
    const auto& FindMatchForLeft = [&matching]( int leftInd )
    {
        for( const CMyPair& pair : matching ) {
            if( pair.LeftIndex == leftInd ) {
                return pair.RightIndex;
            }
        }
        return NotFound;
    };
    EXPECT_EQ( 5, FindMatchForLeft( 3 ) );
    EXPECT_EQ( 6, FindMatchForLeft( 4 ) );
    EXPECT_EQ( 7, FindMatchForLeft( 5 ) );
}

Bug in CCrossValidationSubProblem::GetMatrix()

Hello

In the CCrossValidationSubProblem::GetMatrix() code returns matrix of original problem.
Code:

virtual CSparseFloatMatrixDesc GetMatrix() const { return problem->GetMatrix(); }

It is wrong in case it has wrong number of vectors.

It leads to the problems whyle training gradient bosting classifier, because it builds IProblem wrappes inside (those wrappers use GetMatrix while constructing)

May be can be fixed by 'return matrix'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.