Skip to content

Commit e4b8e85

Browse files
author
Manik Jindal
committed
Remove OpenCV dependency from CNTK core
commit aecc380 Author: Manik Jindal <[email protected]> Date: Thu Nov 16 15:03:13 2017 -0800 Remove OpenCV dependency from CNTK core Tensorboard's Image feature has a hard dependency on OpenCV and Tensorboard is a part of CNTK core. Removing this hard dependency by creating a new DLL ImageWriter just to write an image an PNG.
1 parent db2e817 commit e4b8e85

13 files changed

+334
-45
lines changed

CNTK.sln

+19
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EvalDll", "Source\EvalDll\E
369369
{EAD17188-072C-4726-B840-A769C36DAD1B} = {EAD17188-072C-4726-B840-A769C36DAD1B}
370370
EndProjectSection
371371
EndProject
372+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImageWriterDll", "Source\ImageWriterDll\ImageWriterDll.vcxproj", "{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}"
373+
ProjectSection(ProjectDependencies) = postProject
374+
{86883653-8A61-4038-81A0-2379FAE4200A} = {86883653-8A61-4038-81A0-2379FAE4200A}
375+
EndProjectSection
376+
EndProject
372377
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Math", "Source\Math\Math.vcxproj", "{60BDB847-D0C4-4FD3-A947-0C15C08BCDB5}"
373378
ProjectSection(ProjectDependencies) = postProject
374379
{86883653-8A61-4038-81A0-2379FAE4200A} = {86883653-8A61-4038-81A0-2379FAE4200A}
@@ -854,6 +859,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CNTKv2LibraryDll", "Source\
854859
{86883653-8A61-4038-81A0-2379FAE4200A} = {86883653-8A61-4038-81A0-2379FAE4200A}
855860
{F0A9637C-20DA-42F0-83D4-23B4704DE602} = {F0A9637C-20DA-42F0-83D4-23B4704DE602}
856861
{EAD17188-072C-4726-B840-A769C36DAD1B} = {EAD17188-072C-4726-B840-A769C36DAD1B}
862+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D} = {2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}
857863
EndProjectSection
858864
EndProject
859865
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "V2LibraryTests", "Tests\UnitTests\V2LibraryTests\V2LibraryTests.vcxproj", "{F4CC3AB2-0DB2-4281-929A-2E68E30F0F6E}"
@@ -1733,6 +1739,18 @@ Global
17331739
{482999D1-B7E2-466E-9F8D-2119F93EAFD9}.Release_UWP|x64.ActiveCfg = Release_CpuOnly|x64
17341740
{482999D1-B7E2-466E-9F8D-2119F93EAFD9}.Release|x64.ActiveCfg = Release|x64
17351741
{482999D1-B7E2-466E-9F8D-2119F93EAFD9}.Release|x64.Build.0 = Release|x64
1742+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Debug_CpuOnly|x64.ActiveCfg = Debug_CpuOnly|x64
1743+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Debug_CpuOnly|x64.Build.0 = Debug_CpuOnly|x64
1744+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Debug_UWP|x64.ActiveCfg = Debug_CpuOnly|x64
1745+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Debug|x64.ActiveCfg = Debug|x64
1746+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Debug|x64.Build.0 = Debug|x64
1747+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release_CpuOnly|x64.ActiveCfg = Release_CpuOnly|x64
1748+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release_CpuOnly|x64.Build.0 = Release_CpuOnly|x64
1749+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release_NoOpt|x64.ActiveCfg = Release_NoOpt|x64
1750+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release_NoOpt|x64.Build.0 = Release_NoOpt|x64
1751+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release_UWP|x64.ActiveCfg = Release_NoOpt|x64
1752+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release|x64.ActiveCfg = Release|x64
1753+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D}.Release|x64.Build.0 = Release|x64
17361754
{60BDB847-D0C4-4FD3-A947-0C15C08BCDB5}.Debug_CpuOnly|x64.ActiveCfg = Debug_CpuOnly|x64
17371755
{60BDB847-D0C4-4FD3-A947-0C15C08BCDB5}.Debug_CpuOnly|x64.Build.0 = Debug_CpuOnly|x64
17381756
{60BDB847-D0C4-4FD3-A947-0C15C08BCDB5}.Debug_UWP|x64.ActiveCfg = Debug_UWP|x64
@@ -2360,6 +2378,7 @@ Global
23602378
{3CE841C0-02E5-46DB-B401-6F8784880173} = {47755F2E-D674-4175-9E38-8EA053455072}
23612379
{A4FC3467-4787-43E8-BBC0-D79AE56B468D} = {6F19321A-65E7-4829-B00C-3886CD6C6EDE}
23622380
{482999D1-B7E2-466E-9F8D-2119F93EAFD9} = {DD043083-71A4-409A-AA91-F9C548DCF7EC}
2381+
{2ECE5AEB-F471-4A1D-9BAD-963D5C8A8A1D} = {DD043083-71A4-409A-AA91-F9C548DCF7EC}
23632382
{60BDB847-D0C4-4FD3-A947-0C15C08BCDB5} = {DD043083-71A4-409A-AA91-F9C548DCF7EC}
23642383
{B3DD765E-694E-4494-BAD7-37BBF2942517} = {DD043083-71A4-409A-AA91-F9C548DCF7EC}
23652384
{D667AF32-028A-4A5D-BE19-F46776F0F6B2} = {33EBFE78-A1A8-4961-8938-92A271941F94}

Documentation/current_iteration.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# CNTK v2.3 Release Notes
22

3+
### Highlights of this Release
4+
- OpenCV is not required to install CNTK but to use Tensorboard Image feature.
5+
36
### Python-binding for CNTK
47
Support for Python 3.4 will be removed from CNTK releases later than v2.3.
58

Makefile

+33-9
Original file line numberDiff line numberDiff line change
@@ -531,13 +531,11 @@ PYTHON_LIBS+=$(CNTKLIBRARY_LIB)
531531
JAVA_LIBS+=$(CNTKLIBRARY_LIB)
532532
SRC+=$(CNTKLIBRARY_SRC)
533533
534-
OPENCV_LIBS:=-lopencv_core -lopencv_imgproc -lopencv_imgcodecs
535-
536534
$(CNTKLIBRARY_LIB): $(CNTKLIBRARY_OBJ) | $(CNTKMATH_LIB)
537535
@echo $(SEPARATOR)
538536
@mkdir -p $(dir $@)
539537
@echo building $@ for $(ARCH) with build type $(BUILDTYPE)
540-
$(CXX) $(LDFLAGS) -shared $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINDIR) $(LIBPATH)) -o $@ $^ $(LIBS) $(OPENCV_LIBS) -l$(CNTKMATH) $(PROTOBUF_PATH)/lib/libprotobuf.a -ldl -fopenmp
538+
$(CXX) $(LDFLAGS) -shared $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINDIR) $(LIBPATH)) -o $@ $^ $(LIBS) -l$(CNTKMATH) $(PROTOBUF_PATH)/lib/libprotobuf.a -ldl -fopenmp
541539
542540
543541
########################################
@@ -600,7 +598,7 @@ $(PROPOSAL_LAYER_LIB): $(PROPOSAL_LAYER_LIBRARY_OBJ) | $(CNTKLIBRARY_LIB)
600598
@echo $(SEPARATOR)
601599
@echo creating $@ for $(ARCH) with build type $(BUILDTYPE)
602600
@mkdir -p $(dir $@)
603-
$(CXX) $(LDFLAGS) -shared $(patsubst %,-L%, $(LIBDIR) $(LIBPATH)) $(patsubst %,$(RPATH)%, $(LIBDIR) $(LIBPATH) $(ORIGINDIR)) -o $@ $^ -l$(CNTKLIBRARY) $(OPENCV_LIBS)
601+
$(CXX) $(LDFLAGS) -shared $(patsubst %,-L%, $(LIBDIR) $(LIBPATH)) $(patsubst %,$(RPATH)%, $(LIBDIR) $(LIBPATH) $(ORIGINDIR)) -o $@ $^ -l$(CNTKLIBRARY)
604602
605603
606604
########################################
@@ -665,7 +663,7 @@ $(EVAL_CLIENT): $(EVAL_CLIENT_OBJ) | $(EVAL_LIB) $(READER_LIBS)
665663
@echo $(SEPARATOR)
666664
@mkdir -p $(dir $@)
667665
@echo building $(EVAL_CLIENT) for $(ARCH) with build type $(BUILDTYPE)
668-
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH)) -o $@ $^ $(LIBS) -l$(EVAL) $(L_READER_LIBS) $(lMULTIVERSO) $(OPENCV_LIBS)
666+
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH)) -o $@ $^ $(LIBS) -l$(EVAL) $(L_READER_LIBS) $(lMULTIVERSO)
669667
670668
EVAL_EXTENDED_CLIENT:=$(BINDIR)/cppevalextendedclient
671669
@@ -681,7 +679,7 @@ $(EVAL_EXTENDED_CLIENT): $(EVAL_EXTENDED_CLIENT_OBJ) | $(EVAL_LIB) $(READER_LIBS
681679
@echo $(SEPARATOR)
682680
@mkdir -p $(dir $@)
683681
@echo building $(EVAL_EXTENDED_CLIENT) for $(ARCH) with build type $(BUILDTYPE)
684-
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH)) -o $@ $^ $(LIBS) -l$(EVAL) $(L_READER_LIBS) $(lMULTIVERSO) $(OPENCV_LIBS)
682+
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH)) -o $@ $^ $(LIBS) -l$(EVAL) $(L_READER_LIBS) $(lMULTIVERSO)
685683
686684
########################################
687685
# Eval V2 Sample client
@@ -1009,6 +1007,32 @@ $(IMAGEREADER): $(IMAGEREADER_OBJ) | $(CNTKMATH_LIB)
10091007
endif
10101008
endif
10111009
1010+
########################################
1011+
# ImageWriter plugin
1012+
########################################
1013+
1014+
ifdef OPENCV_PATH
1015+
IMAGEWRITER_LIBS_LIST := opencv_core opencv_imgproc opencv_imgcodecs
1016+
IMAGEWRITER_LIBS:= $(addprefix -l,$(IMAGEWRITER_LIBS_LIST))
1017+
1018+
IMAGEWRITER_SRC =\
1019+
$(SOURCEDIR)/ImageWriterDll/ImageWriter.cpp \
1020+
1021+
IMAGEWRITER_OBJ := $(patsubst %.cpp, $(OBJDIR)/%.o, $(IMAGEWRITER_SRC))
1022+
1023+
IMAGEWRITER:=$(LIBDIR)/Cntk.ImageWriter-$(CNTK_COMPONENT_VERSION).so
1024+
ALL_LIBS += $(IMAGEWRITER)
1025+
PYTHON_LIBS += $(IMAGEWRITER)
1026+
SRC+=$(IMAGEWRITER_SRC)
1027+
1028+
INCLUDEPATH += $(OPENCV_PATH)/include
1029+
LIBPATH += $(OPENCV_PATH)/lib $(OPENCV_PATH)/release/lib
1030+
1031+
$(IMAGEWRITER): $(IMAGEWRITER_OBJ)
1032+
@echo $(SEPARATOR)
1033+
$(CXX) $(LDFLAGS) -shared $(patsubst %,-L%, $(LIBDIR) $(LIBPATH)) $(patsubst %,$(RPATH)%, $(ORIGINDIR) $(LIBPATH)) -o $@ $^ $(IMAGEWRITER_LIBS)
1034+
endif
1035+
10121036
########################################
10131037
# 1bit SGD setup
10141038
########################################
@@ -1131,7 +1155,7 @@ $(CNTK): $(CNTK_OBJ) | $(READER_LIBS) $(MULTIVERSO_LIB)
11311155
@echo $(SEPARATOR)
11321156
@mkdir -p $(dir $@)
11331157
@echo building $@ for $(ARCH) with build type $(BUILDTYPE)
1134-
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH)) -o $@ $^ $(LIBS) $(L_READER_LIBS) $(lMULTIVERSO) -ldl -fopenmp $(PROTOBUF_PATH)/lib/libprotobuf.a $(OPENCV_LIBS)
1158+
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH)) $(patsubst %,$(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH)) -o $@ $^ $(LIBS) $(L_READER_LIBS) $(lMULTIVERSO) -ldl -fopenmp $(PROTOBUF_PATH)/lib/libprotobuf.a
11351159
11361160
# deployable resources: standard library of BS
11371161
CNTK_CORE_BS:=$(BINDIR)/cntk.core.bs
@@ -1204,7 +1228,7 @@ $(UNITTEST_EVAL) : $(UNITTEST_EVAL_OBJ) | $(EVAL_LIB) $(READER_LIBS)
12041228
@echo $(SEPARATOR)
12051229
@mkdir -p $(dir $@)
12061230
@echo building $@ for $(ARCH) with build type $(BUILDTYPE)
1207-
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH) $(BOOSTLIB_PATH)) $(patsubst %, $(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH) $(BOOSTLIB_PATH)) -o $@ $^ $(BOOSTLIBS) $(LIBS) -l$(EVAL) $(L_READER_LIBS) $(lMULTIVERSO) $(OPENCV_LIBS)
1231+
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH) $(BOOSTLIB_PATH)) $(patsubst %, $(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH) $(BOOSTLIB_PATH)) -o $@ $^ $(BOOSTLIBS) $(LIBS) -l$(EVAL) $(L_READER_LIBS) $(lMULTIVERSO)
12081232
12091233
#TODO: create project specific makefile or rules to avoid adding project specific path to the global path
12101234
INCLUDEPATH += $(SOURCEDIR)/Readers/CNTKTextFormatReader
@@ -1271,7 +1295,7 @@ $(UNITTEST_NETWORK): $(UNITTEST_NETWORK_OBJ) | $(READER_LIBS) $(CNTKTEXTFORMATRE
12711295
@echo $(SEPARATOR)
12721296
@mkdir -p $(dir $@)
12731297
@echo building $@ for $(ARCH) with build type $(BUILDTYPE)
1274-
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH) $(BOOSTLIB_PATH)) $(patsubst %, $(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH) $(BOOSTLIB_PATH)) -o $@ $^ $(BOOSTLIBS) $(LIBS) $(lMULTIVERSO) $(L_READER_LIBS) -ldl -fopenmp $(PROTOBUF_PATH)/lib/libprotobuf.a $(OPENCV_LIBS)
1298+
$(CXX) $(LDFLAGS) $(patsubst %,-L%, $(LIBDIR) $(LIBPATH) $(GDK_NVML_LIB_PATH) $(BOOSTLIB_PATH)) $(patsubst %, $(RPATH)%, $(ORIGINLIBDIR) $(LIBPATH) $(BOOSTLIB_PATH)) -o $@ $^ $(BOOSTLIBS) $(LIBS) $(lMULTIVERSO) $(L_READER_LIBS) -ldl -fopenmp $(PROTOBUF_PATH)/lib/libprotobuf.a
12751299
12761300
UNITTEST_MATH_SRC = \
12771301
$(SOURCEDIR)/../Tests/UnitTests/MathTests/BatchNormalizationEngineTests.cpp \

Source/CNTKv2LibraryDll/CNTKv2LibraryDll.vcxproj

+4-6
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,14 @@
6767
</ItemDefinitionGroup>
6868
<ItemDefinitionGroup>
6969
<ClCompile>
70-
<AdditionalIncludeDirectories>.\API;.\proto;$(BOOST_INCLUDE_PATH);$(SolutionDir)\Source\CNTKv2LibraryDll;$(SolutionDir)Source\SGDLib;$(SolutionDir)Source\Readers\ReaderLib;$(SolutionDir)Source\ComputationNetworkLib;$(SolutionDir)Source\SequenceTrainingLib;$(SolutionDir)Source\Math;$(SolutionDir)Source\Common\Include;$(SolutionDir)Source\CNTK\BrainScript;$(SolutionDir)Source\ActionsLib;$(MSMPI_INC);$(NvmlInclude);$(ProtobufInclude);$(SolutionDir)Source\PerformanceProfilerDll;$(OpenCvInclude)</AdditionalIncludeDirectories>
70+
<AdditionalIncludeDirectories>.\API;.\proto;$(BOOST_INCLUDE_PATH);$(SolutionDir)\Source\CNTKv2LibraryDll;$(SolutionDir)Source\SGDLib;$(SolutionDir)Source\Readers\ReaderLib;$(SolutionDir)Source\ComputationNetworkLib;$(SolutionDir)Source\SequenceTrainingLib;$(SolutionDir)Source\Math;$(SolutionDir)Source\Common\Include;$(SolutionDir)Source\CNTK\BrainScript;$(SolutionDir)Source\ActionsLib;$(MSMPI_INC);$(NvmlInclude);$(ProtobufInclude);$(SolutionDir)Source\PerformanceProfilerDll</AdditionalIncludeDirectories>
7171
<AdditionalIncludeDirectories Condition="'$(CNTK_ENABLE_1BitSGD)'=='true' and '!$(IsUWP)'">$(SolutionDir)Source\1BitSGD;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
7272
<PreprocessorDefinitions Condition="'$(CNTK_ENABLE_1BitSGD)'=='true' and '!$(IsUWP)'">CNTK_PARALLEL_TRAINING_SUPPORT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
7373
<OpenMPSupport>true</OpenMPSupport>
7474
</ClCompile>
7575
<Link>
7676
<AdditionalLibraryDirectories>$(SolutionDir)Source\ComputationNetworkLib;$(SolutionDir)Source\Math;$(MSMPI_LIB64);$(SolutionDir)$(Platform)\$(Configuration);$(NvmlLibPath);$(ProtobufLibPath)</AdditionalLibraryDirectories>
77-
<AdditionalLibraryDirectories Condition="!$(IsUWP)">$(OpenCvLibPath);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
7877
<AdditionalDependencies>$(ReaderLibs);Cntk.Common$(OutputSuffix)-$(CntkComponentVersion).lib;Cntk.ComputationNetwork$(OutputSuffix)-$(CntkComponentVersion).lib;Cntk.SequenceTrainingLib$(OutputSuffix)-$(CntkComponentVersion).lib;$(ProtobufLib);%(AdditionalDependencies)</AdditionalDependencies>
79-
<AdditionalDependencies Condition="!$(IsUWP)">$(OpenCvLib);%(AdditionalDependencies)</AdditionalDependencies>
8078
</Link>
8179
<PreBuildEvent>
8280
<Command>prebuild.bat "$(Configuration)" "$(CNTK_MKL_SEQUENTIAL)" "$(CNTK_ENABLE_1BitSGD)" "$(CudaPath)" "$(CUDNN_PATH)" "$(CUB_PATH)" "$(CNTK_ENABLE_ASGD)"</Command>
@@ -96,7 +94,7 @@
9694
<SubSystem>Console</SubSystem>
9795
<GenerateDebugInformation>true</GenerateDebugInformation>
9896
<DelayLoadDLLs>Cntk.Math$(OutputSuffix)-$(CntkComponentVersion).dll; nvml.dll; $(CudaRuntimeDll); msmpi.dll;</DelayLoadDLLs>
99-
<DelayLoadDLLs Condition="!$(IsUWP)">%(DelayLoadDLLs); Cntk.PerformanceProfiler-$(CntkComponentVersion).dll</DelayLoadDLLs>
97+
<DelayLoadDLLs Condition="!$(IsUWP)">%(DelayLoadDLLs); Cntk.PerformanceProfiler-$(CntkComponentVersion).dll;Cntk.ImageWriter-$(CntkComponentVersion).dll</DelayLoadDLLs>
10098
</Link>
10199
</ItemDefinitionGroup>
102100
<ItemDefinitionGroup Condition="$(ReleaseBuild)">
@@ -114,7 +112,7 @@
114112
<SubSystem>Console</SubSystem>
115113
<GenerateDebugInformation>true</GenerateDebugInformation>
116114
<DelayLoadDLLs>Cntk.Math$(OutputSuffix)-$(CntkComponentVersion).dll; nvml.dll; $(CudaRuntimeDll); msmpi.dll;</DelayLoadDLLs>
117-
<DelayLoadDLLs Condition="!$(IsUWP)">%(DelayLoadDLLs); Cntk.PerformanceProfiler-$(CntkComponentVersion).dll</DelayLoadDLLs>
115+
<DelayLoadDLLs Condition="!$(IsUWP)">%(DelayLoadDLLs); Cntk.PerformanceProfiler-$(CntkComponentVersion).dll;Cntk.ImageWriter-$(CntkComponentVersion).dll</DelayLoadDLLs>
118116
</Link>
119117
</ItemDefinitionGroup>
120118
<ItemDefinitionGroup Condition="$(CpuOnlyBuild)">
@@ -125,7 +123,7 @@
125123
</ClCompile>
126124
<Link>
127125
<DelayLoadDLLs>Cntk.Math$(OutputSuffix)-$(CntkComponentVersion).dll; msmpi.dll;</DelayLoadDLLs>
128-
<DelayLoadDLLs Condition="!$(IsUWP)">%(DelayLoadDLLs); Cntk.PerformanceProfiler-$(CntkComponentVersion).dll</DelayLoadDLLs>
126+
<DelayLoadDLLs Condition="!$(IsUWP)">%(DelayLoadDLLs); Cntk.PerformanceProfiler-$(CntkComponentVersion).dll;Cntk.ImageWriter-$(CntkComponentVersion).dll</DelayLoadDLLs>
129127
<OptimizeReferences Condition="'$(Configuration)|$(Platform)'=='Debug_CpuOnly|x64'">false</OptimizeReferences>
130128
</Link>
131129
</ItemDefinitionGroup>

Source/CNTKv2LibraryDll/tensorboard/TensorBoardFileWriter.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,8 @@ namespace CNTK
200200
extent.push_back(width);
201201
extent.push_back(depth);
202202
extent.push_back(1);
203-
const int compression = -1;
204203

205204
const std::vector<size_t> imageDim({height, width, depth});
206-
NDShape imageShape(imageDim);
207205

208206
for (size_t i = 0; i < batch_size; i++) {
209207
tensorflow::Summary::Value* summaryValue = summary->add_value();
@@ -215,16 +213,16 @@ namespace CNTK
215213
summaryImage->set_colorspace(depth);
216214
start.back() = static_cast<size_t>(i);
217215
auto image = imageData->SliceView(start, extent)->AsShape(imageDim);
218-
vector<uchar> buffer;
216+
vector<unsigned char> buffer;
219217

220218
switch (dtype)
221219
{
222220
case DataType::Float:
223-
WriteImageToBuffer(image->WritableDataBuffer<float>(), height, width, CV_32FC(depth), buffer);
221+
WriteImageToBuffer(image->WritableDataBuffer<float>(), dtype, height, width, depth, buffer);
224222
break;
225223

226224
case DataType::Double:
227-
WriteImageToBuffer(image->WritableDataBuffer<double>(), height, width, CV_64FC(depth), buffer);
225+
WriteImageToBuffer(image->WritableDataBuffer<double>(), dtype, height, width, depth, buffer);
228226
break;
229227

230228
default:
@@ -238,7 +236,8 @@ namespace CNTK
238236

239237
WriteRecord(Serialize(event));
240238
}
241-
#endif
239+
240+
#endif // !CNTK_UWP
242241

243242
void TensorBoardFileWriter::WriteVersion(time_t time)
244243
{

Source/CNTKv2LibraryDll/tensorboard/TensorBoardUtils.cpp

+11-17
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#pragma warning(pop)
1212

1313
#include "Utils.h"
14+
#include "Basics.h"
1415

1516
namespace CNTK
1617
{
@@ -264,27 +265,20 @@ namespace CNTK
264265

265266
#ifndef CNTK_UWP
266267

267-
// Ensure OpenCV's imgproc library appears as direct dependency at link
268-
// time so rpath will apply (Linux). // TODO find a better way
269-
void _dummyRefForOpenCVImgProc()
268+
void WriteImageToBuffer(void* matrix, DataType dtype, int height, int width, int depth, std::vector<unsigned char>& buffer)
270269
{
271-
cvThreshHist(0, 0.0);
272-
}
270+
typedef void(*EncodeImageAsPNG)(void* matrix, DataType dtype, int height, int width, int depth, std::vector<unsigned char>& buffer);
271+
static EncodeImageAsPNG encodeImageAsPNG = nullptr;
273272

274-
void WriteImageToBuffer(void* matrix, int height, int weight, int dataType, std::vector<uchar>& buffer)
275-
{
276-
assert(matrix != nullptr);
277-
assert(&buffer != nullptr);
278-
vector<int> parameters = vector<int>(2);
279-
parameters[0] = CV_IMWRITE_PNG_COMPRESSION;
280-
parameters[1] = 3;//default(3) 0-9
281-
cv::Mat source = cv::Mat(height, weight, dataType, matrix);
282-
283-
if (!imencode(".png", source, buffer, parameters)) {
284-
fprintf(stderr, "TensorBoardFileWriter: PNG encoding failed. ");
285-
return;
273+
if (encodeImageAsPNG == nullptr)
274+
{
275+
Microsoft::MSR::CNTK::Plugin plugin;
276+
encodeImageAsPNG = (EncodeImageAsPNG)plugin.Load(L"ImageWriter", "EncodeImageAsPNG");
286277
}
278+
279+
encodeImageAsPNG(matrix, dtype, height, width, depth, buffer);
287280
}
281+
288282
#endif // !CNTK_UWP
289283
}
290284
}

Source/CNTKv2LibraryDll/tensorboard/TensorBoardUtils.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88
#include "stdafx.h"
99
#include "CNTKLibrary.h"
1010

11-
#ifndef CNTK_UWP
12-
#include <opencv2/core/mat.hpp>
13-
#include <opencv2/opencv.hpp>
14-
#include "opencv2/core/types.hpp"
15-
#endif
16-
1711
namespace tensorflow
1812
{
1913
class GraphDef;
@@ -29,7 +23,7 @@ namespace CNTK
2923
void CreateTensorBoardGraph(const FunctionPtr& src, tensorflow::GraphDef& dst);
3024

3125
#ifndef CNTK_UWP
32-
void WriteImageToBuffer(void* matrix, int height, int weight, int dataType, std::vector<uchar>& buffer);
26+
void WriteImageToBuffer(void* matrix, DataType dtype, int height, int width, int depth, std::vector<unsigned char>& buffer);
3327
#endif // !CNTK_UWP
3428

3529
}

Source/Common/File.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,9 @@ static const std::unordered_map<std::wstring, std::wstring> s_deprecatedReaderWr
10131013
{ L"CNTKTextFormatReader", L"Cntk.Deserializers.TextFormat" },
10141014
{ L"CNTKBinaryReader", L"Cntk.Deserializers.Binary" },
10151015
{ L"ImageReader", L"Cntk.Deserializers.Image" },
1016+
1017+
// Image writer
1018+
{ L"ImageWriter", L"Cntk.ImageWriter" },
10161019
};
10171020

10181021
#ifdef _WIN32

0 commit comments

Comments
 (0)