diff --git a/doc/js_tutorials/js_assets/js_style_transfer_model_info.json b/doc/js_tutorials/js_assets/js_style_transfer_model_info.json
index 9cc66018a0..04258298dc 100644
--- a/doc/js_tutorials/js_assets/js_style_transfer_model_info.json
+++ b/doc/js_tutorials/js_assets/js_style_transfer_model_info.json
@@ -1,76 +1,44 @@
{
- "torch": [
+ "onnx": [
{
- "model": "candy.t7",
+ "model": "mosaic-9.onnx",
"inputSize": "224, 224",
- "mean": "104, 117, 123",
+ "mean": "0, 0, 0",
"std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//instance_norm/candy.t7"
+ "swapRB": "true",
+ "modelUrl": "https://media.githubusercontent.com/media/onnx/models/main/vision/style_transfer/fast_neural_style/model/mosaic-9.onnx"
},
{
- "model": "composition_vii.t7",
+ "model": "candy-9.onnx",
"inputSize": "224, 224",
- "mean": "104, 117, 123",
+ "mean": "0, 0, 0",
"std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//eccv16/composition_vii.t7"
+ "swapRB": "true",
+ "modelUrl": "https://media.githubusercontent.com/media/onnx/models/main/vision/style_transfer/fast_neural_style/model/candy-9.onnx"
},
{
- "model": "feathers.t7",
+ "model": "rain-princess-9.onnx",
"inputSize": "224, 224",
- "mean": "104, 117, 123",
+ "mean": "0, 0, 0",
"std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//instance_norm/feathers.t7"
+ "swapRB": "true",
+ "modelUrl": "https://media.githubusercontent.com/media/onnx/models/main/vision/style_transfer/fast_neural_style/model/rain-princess-9.onnx"
},
{
- "model": "la_muse.t7",
+ "model": "udnie-9.onnx",
"inputSize": "224, 224",
- "mean": "104, 117, 123",
+ "mean": "0, 0, 0",
"std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//instance_norm/la_muse.t7"
+ "swapRB": "true",
+ "modelUrl": "https://media.githubusercontent.com/media/onnx/models/main/vision/style_transfer/fast_neural_style/model/udnie-9.onnx"
},
{
- "model": "mosaic.t7",
+ "model": "pointilism-9.onnx",
"inputSize": "224, 224",
- "mean": "104, 117, 123",
+ "mean": "0, 0, 0",
"std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//instance_norm/mosaic.t7"
- },
- {
- "model": "starry_night.t7",
- "inputSize": "224, 224",
- "mean": "104, 117, 123",
- "std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//eccv16/starry_night.t7"
- },
- {
- "model": "the_scream.t7",
- "inputSize": "224, 224",
- "mean": "104, 117, 123",
- "std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//instance_norm/the_scream.t7"
- },
- {
- "model": "the_wave.t7",
- "inputSize": "224, 224",
- "mean": "104, 117, 123",
- "std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//eccv16/the_wave.t7"
- },
- {
- "model": "udnie.t7",
- "inputSize": "224, 224",
- "mean": "104, 117, 123",
- "std": "1",
- "swapRB": "false",
- "modelUrl": "https://cs.stanford.edu/people/jcjohns/fast-neural-style/models//instance_norm/udnie.t7"
+ "swapRB": "true",
+ "modelUrl": "https://media.githubusercontent.com/media/onnx/models/main/vision/style_transfer/fast_neural_style/model/pointilism-9.onnx"
}
]
-}
\ No newline at end of file
+}
diff --git a/modules/dnn/CMakeLists.txt b/modules/dnn/CMakeLists.txt
index 5963eb68d3..681625816c 100644
--- a/modules/dnn/CMakeLists.txt
+++ b/modules/dnn/CMakeLists.txt
@@ -209,7 +209,7 @@ set(dnn_plugin_srcs ${dnn_srcs} ${dnn_int_hdrs})
ocv_list_filterout_ex(dnn_plugin_srcs
"/src/dnn.cpp$|/src/dnn_utils.cpp$|/src/dnn_utils.cpp$|/src/dnn_read.cpp$|/src/registry.cpp$|/src/backend.cpp$"
# importers
- "/src/(caffe|darknet|onnx|tensorflow|torch)/"
+ "/src/(caffe|darknet|onnx|tensorflow)/"
# executors
"/src/(cuda|cuda4dnn|ocl4dnn|vkcom|webnn)/"
)
diff --git a/modules/dnn/include/opencv2/dnn/all_layers.hpp b/modules/dnn/include/opencv2/dnn/all_layers.hpp
index 587eda102f..2f2bc6b548 100644
--- a/modules/dnn/include/opencv2/dnn/all_layers.hpp
+++ b/modules/dnn/include/opencv2/dnn/all_layers.hpp
@@ -55,9 +55,9 @@ CV__DNN_INLINE_NS_BEGIN
Classes listed here, in fact, provides C++ API for creating instances of built-in layers.
In addition to this way of layers instantiation, there is a more common factory API (see @ref dnnLayerFactory), it allows to create layers dynamically (by name) and register new ones.
- You can use both API, but factory API is less convenient for native C++ programming and basically designed for use inside importers (see @ref readNetFromCaffe(), @ref readNetFromTorch(), @ref readNetFromTensorflow()).
+ You can use both API, but factory API is less convenient for native C++ programming and basically designed for use inside importers (see @ref readNetFromCaffe(), @ref readNetFromTensorflow()).
- Built-in layers partially reproduce functionality of corresponding Caffe and Torch7 layers.
+ Built-in layers partially reproduce functionality of corresponding ONNX, TensorFlow and Caffe layers.
In particular, the following layers and Caffe importer were tested to reproduce Caffe functionality:
- Convolution
- Deconvolution
diff --git a/modules/dnn/include/opencv2/dnn/dnn.hpp b/modules/dnn/include/opencv2/dnn/dnn.hpp
index 39ef6435e4..76bf277bc1 100644
--- a/modules/dnn/include/opencv2/dnn/dnn.hpp
+++ b/modules/dnn/include/opencv2/dnn/dnn.hpp
@@ -934,41 +934,12 @@ CV__DNN_INLINE_NS_BEGIN
*/
CV_EXPORTS Net readNetFromTFLite(const char *bufferModel, size_t lenModel);
- /**
- * @brief Reads a network model stored in Torch7 framework's format.
- * @param model path to the file, dumped from Torch by using torch.save() function.
- * @param isBinary specifies whether the network was serialized in ascii mode or binary.
- * @param evaluate specifies testing phase of network. If true, it's similar to evaluate() method in Torch.
- * @returns Net object.
- *
- * @note Ascii mode of Torch serializer is more preferable, because binary mode extensively use `long` type of C language,
- * which has various bit-length on different systems.
- *
- * The loading file must contain serialized nn.Module object
- * with importing network. Try to eliminate a custom objects from serialazing data to avoid importing errors.
- *
- * List of supported layers (i.e. object instances derived from Torch nn.Module class):
- * - nn.Sequential
- * - nn.Parallel
- * - nn.Concat
- * - nn.Linear
- * - nn.SpatialConvolution
- * - nn.SpatialMaxPooling, nn.SpatialAveragePooling
- * - nn.ReLU, nn.TanH, nn.Sigmoid
- * - nn.Reshape
- * - nn.SoftMax, nn.LogSoftMax
- *
- * Also some equivalents of these classes from cunn, cudnn, and fbcunn may be successfully imported.
- */
- CV_EXPORTS_W Net readNetFromTorch(const String &model, bool isBinary = true, bool evaluate = true);
-
/**
* @brief Read deep learning network represented in one of the supported formats.
* @param[in] model Binary file contains trained weights. The following file
* extensions are expected for models from different frameworks:
* * `*.caffemodel` (Caffe, http://caffe.berkeleyvision.org/)
* * `*.pb` (TensorFlow, https://www.tensorflow.org/)
- * * `*.t7` | `*.net` (Torch, http://torch.ch/)
* * `*.weights` (Darknet, https://pjreddie.com/darknet/)
* * `*.bin` (DLDT, https://software.intel.com/openvino-toolkit)
* * `*.onnx` (ONNX, https://onnx.ai/)
@@ -982,8 +953,8 @@ CV__DNN_INLINE_NS_BEGIN
* @returns Net object.
*
* This function automatically detects an origin framework of trained model
- * and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow,
- * @ref readNetFromTorch or @ref readNetFromDarknet. An order of @p model and @p config
+ * and calls an appropriate function such @ref readNetFromCaffe, @ref readNetFromTensorflow
+ * or @ref readNetFromDarknet. An order of @p model and @p config
* arguments does not matter.
*/
CV_EXPORTS_W Net readNet(const String& model, const String& config = "", const String& framework = "");
@@ -1000,11 +971,6 @@ CV__DNN_INLINE_NS_BEGIN
CV_EXPORTS_W Net readNet(const String& framework, const std::vector& bufferModel,
const std::vector& bufferConfig = std::vector());
- /** @brief Loads blob which was serialized as torch.Tensor object of Torch7 framework.
- * @warning This function has the same limitations as readNetFromTorch().
- */
- CV_EXPORTS_W Mat readTorchBlob(const String &filename, bool isBinary = true);
-
/** @brief Load a network from Intel's Model Optimizer intermediate representation.
* @param[in] xml XML configuration file with network's topology.
* @param[in] bin Binary file with trained weights.
diff --git a/modules/dnn/perf/perf_net.cpp b/modules/dnn/perf/perf_net.cpp
index 46484e82c5..96c4aea124 100644
--- a/modules/dnn/perf/perf_net.cpp
+++ b/modules/dnn/perf/perf_net.cpp
@@ -109,32 +109,11 @@ PERF_TEST_P_(DNNTestNetwork, Inception_5h)
processNet("dnn/tensorflow_inception_graph.pb", "", cv::Size(224, 224), "softmax2");
}
-PERF_TEST_P_(DNNTestNetwork, ENet)
-{
- if ((backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && target != DNN_TARGET_CPU) ||
- (backend == DNN_BACKEND_OPENCV && target == DNN_TARGET_OPENCL_FP16))
- throw SkipTestException("");
-#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_GE(2021010000)
- if (backend == DNN_BACKEND_INFERENCE_ENGINE_NGRAPH)
- throw SkipTestException("");
-#endif
- processNet("dnn/Enet-model-best.net", "", cv::Size(512, 256));
-}
-
PERF_TEST_P_(DNNTestNetwork, SSD)
{
processNet("dnn/VGG_ILSVRC2016_SSD_300x300_iter_440000.caffemodel", "dnn/ssd_vgg16.prototxt", cv::Size(300, 300));
}
-PERF_TEST_P_(DNNTestNetwork, OpenFace)
-{
-#if defined(INF_ENGINE_RELEASE) && INF_ENGINE_VER_MAJOR_EQ(2018050000)
- if (backend == DNN_BACKEND_INFERENCE_ENGINE_NN_BUILDER_2019 && (target == DNN_TARGET_MYRIAD || target == DNN_TARGET_HDDL))
- throw SkipTestException("");
-#endif
- processNet("dnn/openface_nn4.small2.v1.t7", "", cv::Size(96, 96));
-}
-
PERF_TEST_P_(DNNTestNetwork, MobileNet_SSD_Caffe)
{
processNet("dnn/MobileNetSSD_deploy_19e3ec3.caffemodel", "dnn/MobileNetSSD_deploy_19e3ec3.prototxt", cv::Size(300, 300));
@@ -248,7 +227,7 @@ PERF_TEST_P_(DNNTestNetwork, EAST_text_detection)
PERF_TEST_P_(DNNTestNetwork, FastNeuralStyle_eccv16)
{
- processNet("dnn/fast_neural_style_eccv16_starry_night.t7", "", cv::Size(320, 240));
+ processNet("", "dnn/mosaic-9.onnx", cv::Size(224, 224));
}
PERF_TEST_P_(DNNTestNetwork, Inception_v2_Faster_RCNN)
diff --git a/modules/dnn/src/dnn_read.cpp b/modules/dnn/src/dnn_read.cpp
index 9c06ced3c4..437d19559c 100644
--- a/modules/dnn/src/dnn_read.cpp
+++ b/modules/dnn/src/dnn_read.cpp
@@ -33,10 +33,6 @@ Net readNet(const String& _model, const String& _config, const String& _framewor
{
return readNetFromTFLite(model);
}
- if (framework == "torch" || modelExt == "t7" || modelExt == "net" || configExt == "t7" || configExt == "net")
- {
- return readNetFromTorch(model.empty() ? config : model);
- }
if (framework == "darknet" || modelExt == "weights" || configExt == "weights" || modelExt == "cfg" || configExt == "cfg")
{
if (modelExt == "cfg" || configExt == "weights")
@@ -66,8 +62,6 @@ Net readNet(const String& _framework, const std::vector& bufferModel,
return readNetFromTensorflow(bufferModel, bufferConfig);
else if (framework == "darknet")
return readNetFromDarknet(bufferConfig, bufferModel);
- else if (framework == "torch")
- CV_Error(Error::StsNotImplemented, "Reading Torch models from buffers");
else if (framework == "dldt")
return readNetFromModelOptimizer(bufferConfig, bufferModel);
else if (framework == "tflite")
diff --git a/modules/dnn/src/torch/COPYRIGHT.txt b/modules/dnn/src/torch/COPYRIGHT.txt
deleted file mode 100644
index bc002b78ab..0000000000
--- a/modules/dnn/src/torch/COPYRIGHT.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert)
-Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu)
-Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu)
-Copyright (c) 2011-2013 NYU (Clement Farabet)
-Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston)
-Copyright (c) 2006 Idiap Research Institute (Samy Bengio)
-Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz)
-
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-3. Neither the names of Deepmind Technologies, NYU, NEC Laboratories America
- and IDIAP Research Institute nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
diff --git a/modules/dnn/src/torch/THDiskFile.cpp b/modules/dnn/src/torch/THDiskFile.cpp
deleted file mode 100644
index bede95e021..0000000000
--- a/modules/dnn/src/torch/THDiskFile.cpp
+++ /dev/null
@@ -1,530 +0,0 @@
-#include "../precomp.hpp"
-#include "THGeneral.h"
-#include "THDiskFile.h"
-#include "THFilePrivate.h"
-
-namespace TH
-{
-
-typedef struct THDiskFile__
-{
- THFile file;
-
- FILE *handle;
- int isNativeEncoding;
- int longSize;
-
-} THDiskFile;
-
-static int THDiskFile_isOpened(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)self;
- return (dfself->handle != NULL);
-}
-
-/* workaround mac osx lion ***insane*** fread bug */
-#ifdef __APPLE__
-static size_t fread__(void *ptr, size_t size, size_t nitems, FILE *stream)
-{
- size_t nread = 0;
- while(!feof(stream) && !ferror(stream) && (nread < nitems))
- nread += fread((char*)ptr+nread*size, size, std::min(2147483648UL/size, nitems-nread), stream);
- return nread;
-}
-#else
-#define fread__ fread
-#endif
-
-#define READ_WRITE_METHODS(TYPE, TYPEC, ASCII_READ_ELEM, ASCII_WRITE_ELEM) \
- static long THDiskFile_read##TYPEC(THFile *self, TYPE *data, long n) \
- { \
- THDiskFile *dfself = (THDiskFile*)(self); \
- long nread = 0L; \
- \
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file"); \
- THArgCheck(dfself->file.isReadable, 1, "attempt to read in a write-only file"); \
- \
- if(dfself->file.isBinary) \
- { \
- nread = fread__(data, sizeof(TYPE), n, dfself->handle); \
- if(!dfself->isNativeEncoding && (sizeof(TYPE) > 1) && (nread > 0)) \
- THDiskFile_reverseMemory(data, data, sizeof(TYPE), nread); \
- } \
- else \
- { \
- long i; \
- for(i = 0; i < n; i++) \
- { \
- ASCII_READ_ELEM; /* increment here result and break if wrong */ \
- } \
- if(dfself->file.isAutoSpacing && (n > 0)) \
- { \
- int c = fgetc(dfself->handle); \
- if( (c != '\n') && (c != EOF) ) \
- ungetc(c, dfself->handle); \
- } \
- } \
- \
- if(nread != n) \
- { \
- dfself->file.hasError = 1; /* shouldn't we put hasError to 0 all the time ? */ \
- if(!dfself->file.isQuiet) \
- THError("read error: read %ld blocks instead of %ld", nread, n);\
- } \
- \
- return nread; \
- }
-
-static int THDiskFile_mode(const char *mode, int *isReadable, int *isWritable)
-{
- *isReadable = 0;
- *isWritable = 0;
- if(strlen(mode) == 1)
- {
- if(*mode == 'r')
- {
- *isReadable = 1;
- return 1;
- }
- else if(*mode == 'w')
- {
- *isWritable = 1;
- return 1;
- }
- }
- else if(strlen(mode) == 2)
- {
- if(mode[0] == 'r' && mode[1] == 'w')
- {
- *isReadable = 1;
- *isWritable = 1;
- return 1;
- }
- }
- return 0;
-}
-
-static void THDiskFile_seek(THFile *self, long position)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
-
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
-
-#if defined(_WIN64)
- if(_fseeki64(dfself->handle, (__int64)position, SEEK_SET) < 0)
-#elif defined(_WIN32)
- if(fseek(dfself->handle, (long)position, SEEK_SET) < 0)
-#else
- if(fseeko(dfself->handle, (off_t)position, SEEK_SET) < 0)
-#endif
- {
- dfself->file.hasError = 1;
- if(!dfself->file.isQuiet)
- THError("unable to seek at position %ld", position);
- }
-}
-
-static void THDiskFile_seekEnd(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
-
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
-
-#if defined(_WIN64)
- if(_fseeki64(dfself->handle, 0L, SEEK_END) < 0)
-#elif defined(_WIN32)
- if(fseek(dfself->handle, 0L, SEEK_END) < 0)
-#else
- if(fseeko(dfself->handle, 0L, SEEK_END) < 0)
-#endif
- {
- dfself->file.hasError = 1;
- if(!dfself->file.isQuiet)
- THError("unable to seek at end of file");
- }
-}
-
-static long THDiskFile_position(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
-
-#if defined(_WIN64)
- __int64 offset = _ftelli64(dfself->handle);
-#elif defined(_WIN32)
- long offset = ftell(dfself->handle);
-#else
- off_t offset = ftello(dfself->handle);
-#endif
- if (offset > -1)
- return (long)offset;
- else if(!dfself->file.isQuiet)
- THError("unable to obtain disk file offset (maybe a long overflow occurred)");
-
- return 0;
-}
-
-static void THDiskFile_close(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- fclose(dfself->handle);
- dfself->handle = NULL;
-}
-
-/* Little and Big Endian */
-
-static void THDiskFile_reverseMemory(void *dst, const void *src, long blockSize, long numBlocks)
-{
- if(blockSize != 1)
- {
- long halfBlockSize = blockSize/2;
- char *charSrc = (char*)src;
- char *charDst = (char*)dst;
- long b, i;
- for(b = 0; b < numBlocks; b++)
- {
- for(i = 0; i < halfBlockSize; i++)
- {
- char z = charSrc[i];
- charDst[i] = charSrc[blockSize-1-i];
- charDst[blockSize-1-i] = z;
- }
- charSrc += blockSize;
- charDst += blockSize;
- }
- }
-}
-
-int THDiskFile_isLittleEndianCPU(void)
-{
- int x = 7;
- char *ptr = (char *)&x;
-
- if(ptr[0] == 0)
- return 0;
- else
- return 1;
-}
-
-int THDiskFile_isBigEndianCPU(void)
-{
- return(!THDiskFile_isLittleEndianCPU());
-}
-
-void THDiskFile_nativeEndianEncoding(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- dfself->isNativeEncoding = 1;
-}
-
-void THDiskFile_littleEndianEncoding(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- dfself->isNativeEncoding = THDiskFile_isLittleEndianCPU();
-}
-
-void THDiskFile_bigEndianEncoding(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- dfself->isNativeEncoding = !THDiskFile_isLittleEndianCPU();
-}
-
-/* End of Little and Big Endian Stuff */
-
-void THDiskFile_longSize(THFile *self, int size)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- THArgCheck(size == 0 || size == 4 || size == 8, 1, "Invalid long size specified");
- dfself->longSize = size;
-}
-
-void THDiskFile_noBuffer(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- if (setvbuf(dfself->handle, NULL, _IONBF, 0)) {
- THError("error: cannot disable buffer");
- }
-}
-
-static void THDiskFile_free(THFile *self)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- if(dfself->handle)
- fclose(dfself->handle);
- THFree(dfself);
-}
-
-/* Note that we do a trick */
-READ_WRITE_METHODS(unsigned char, Byte,
- nread = fread(data, 1, n, dfself->handle); break,
- nwrite = fwrite(data, 1, n, dfself->handle); break)
-
-READ_WRITE_METHODS(char, Char,
- nread = fread(data, 1, n, dfself->handle); break,
- nwrite = fwrite(data, 1, n, dfself->handle); break)
-
-READ_WRITE_METHODS(short, Short,
- int ret = fscanf(dfself->handle, "%hd", &data[i]); if(ret <= 0) break; else nread++,
- int ret = fprintf(dfself->handle, "%hd", data[i]); if(ret <= 0) break; else nwrite++)
-
-READ_WRITE_METHODS(int, Int,
- int ret = fscanf(dfself->handle, "%d\n\r", &data[i]); if(ret <= 0) break; else nread++,
- int ret = fprintf(dfself->handle, "%d", data[i]); if(ret <= 0) break; else nwrite++)
-
-/*READ_WRITE_METHODS(long, Long,
- int ret = fscanf(dfself->handle, "%ld", &data[i]); if(ret <= 0) break; else nread++,
- int ret = fprintf(dfself->handle, "%ld", data[i]); if(ret <= 0) break; else nwrite++)*/
-
-READ_WRITE_METHODS(float, Float,
- int ret = fscanf(dfself->handle, "%g", &data[i]); if(ret <= 0) break; else nread++,
- int ret = fprintf(dfself->handle, "%.9g", data[i]); if(ret <= 0) break; else nwrite++)
-
-READ_WRITE_METHODS(double, Double,
- int ret = fscanf(dfself->handle, "%lg", &data[i]); if(ret <= 0) break; else nread++,
- int ret = fprintf(dfself->handle, "%.17g", data[i]); if(ret <= 0) break; else nwrite++)
-
-
-/* For Long we need to rewrite everything, because of the special management of longSize */
-static long THDiskFile_readLong(THFile *self, int64 *data, long n)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- long nread = 0L;
-
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- THArgCheck(dfself->file.isReadable, 1, "attempt to read in a write-only file");
-
- if(dfself->file.isBinary)
- {
- if(dfself->longSize == 0 || dfself->longSize == sizeof(int64))
- {
- nread = fread__(data, sizeof(int64), n, dfself->handle);
- if(!dfself->isNativeEncoding && (sizeof(int64) > 1) && (nread > 0))
- THDiskFile_reverseMemory(data, data, sizeof(int64), nread);
- } else if(dfself->longSize == 4)
- {
- nread = fread__(data, 4, n, dfself->handle);
- if(!dfself->isNativeEncoding && (nread > 0))
- THDiskFile_reverseMemory(data, data, 4, nread);
- long i;
- for(i = nread; i > 0; i--)
- data[i-1] = ((int *)data)[i-1];
- }
- else /* if(dfself->longSize == 8) */
- {
- int big_endian = !THDiskFile_isLittleEndianCPU();
- int32_t *buffer = (int32_t*)THAlloc(8*n);
- if (!buffer)
- THError("can not allocate buffer");
- nread = fread__(buffer, 8, n, dfself->handle);
- long i;
- for(i = nread; i > 0; i--)
- data[i-1] = buffer[2*(i-1) + big_endian];
- THFree(buffer);
- if(!dfself->isNativeEncoding && (nread > 0))
- THDiskFile_reverseMemory(data, data, 4, nread);
- }
- }
- else
- {
- long i;
- for(i = 0; i < n; i++)
- {
- long d;
- int ret = fscanf(dfself->handle, "%ld", &d); if(ret <= 0) break; else nread++;
- data[i] = d;
- }
- if(dfself->file.isAutoSpacing && (n > 0))
- {
- int c = fgetc(dfself->handle);
- if( (c != '\n') && (c != EOF) )
- ungetc(c, dfself->handle);
- }
- }
-
- if(nread != n)
- {
- dfself->file.hasError = 1; /* shouldn't we put hasError to 0 all the time ? */
- if(!dfself->file.isQuiet)
- THError("read error: read %ld blocks instead of %ld", nread, n);
- }
-
- return nread;
-}
-
-
-static long THDiskFile_readString(THFile *self, const char *format, char **str_)
-{
- THDiskFile *dfself = (THDiskFile*)(self);
- THArgCheck(dfself->handle != NULL, 1, "attempt to use a closed file");
- THArgCheck(dfself->file.isReadable, 1, "attempt to read in a write-only file");
- THArgCheck((strlen(format) >= 2 ? (format[0] == '*') && (format[1] == 'a' || format[1] == 'l') : 0), 2, "format must be '*a' or '*l'");
-
-/* note: the string won't survive long, as it is copied into lua */
-/* so 1024 is not that big... */
-#define TBRS_BSZ 1024L
-
- if(format[1] == 'a')
- {
- char *p = (char*)THAlloc(TBRS_BSZ);
- long total = TBRS_BSZ;
- long pos = 0L;
-
- if (p == NULL)
- THError("read error: failed to allocate buffer");
- for (;;)
- {
- if(total-pos == 0) /* we need more space! */
- {
- total += TBRS_BSZ;
- char *new_p = (char*)THRealloc(p, total);
- if (new_p == NULL)
- {
- THFree(p);
- THError("read error: failed to reallocate buffer");
- }
- p = new_p;
- }
- pos += fread(p+pos, 1, total-pos, dfself->handle);
- if (pos < total) /* eof? */
- {
- if(pos == 0L)
- {
- THFree(p);
- dfself->file.hasError = 1;
- if(!dfself->file.isQuiet)
- THError("read error: read 0 blocks instead of 1");
-
- *str_ = NULL;
- return 0;
- }
- *str_ = p;
- return pos;
- }
- }
- }
- else
- {
- char *p = (char*)THAlloc(TBRS_BSZ);
- long total = TBRS_BSZ;
- long pos = 0L;
- long size;
-
- if (p == NULL)
- THError("read error: failed to allocate buffer");
- for (;;)
- {
- if(total-pos <= 1) /* we can only write '\0' in there! */
- {
- total += TBRS_BSZ;
- char *new_p = (char*)THRealloc(p, total);
- if (new_p == NULL)
- {
- THFree(p);
- THError("read error: failed to reallocate buffer");
- }
- p = new_p;
- }
- if (fgets(p+pos, total-pos, dfself->handle) == NULL) /* eof? */
- {
- if(pos == 0L)
- {
- THFree(p);
- dfself->file.hasError = 1;
- if(!dfself->file.isQuiet)
- THError("read error: read 0 blocks instead of 1");
-
- *str_ = NULL;
- return 0;
- }
- *str_ = p;
- return pos;
- }
- size = strlen(p+pos);
- if (size == 0L || (p+pos)[size-1] != '\n')
- {
- pos += size;
- }
- else
- {
- pos += size-1L; /* do not include `eol' */
- *str_ = p;
- return pos;
- }
- }
- }
-
- *str_ = NULL;
- return 0;
-}
-
-THFile *THDiskFile_new(const std::string &name, const char *mode, int isQuiet)
-{
- static struct THFileVTable vtable = {
- THDiskFile_isOpened,
-
- THDiskFile_readByte,
- THDiskFile_readChar,
- THDiskFile_readShort,
- THDiskFile_readInt,
- THDiskFile_readLong,
- THDiskFile_readFloat,
- THDiskFile_readDouble,
- THDiskFile_readString,
-
- THDiskFile_seek,
- THDiskFile_seekEnd,
- THDiskFile_position,
- THDiskFile_close,
- THDiskFile_free
- };
-
- int isReadable;
- int isWritable;
- FILE *handle;
- THDiskFile *self;
-
- THArgCheck(THDiskFile_mode(mode, &isReadable, &isWritable), 2, "file mode should be 'r','w' or 'rw'");
-
- CV_Assert(isReadable && !isWritable);
-
-#ifdef _MSC_VER
- if (fopen_s(&handle, name.c_str(), "rb") != 0)
- handle = NULL;
-#else
- handle = fopen(name.c_str(),"rb");
-#endif
-
- if(!handle)
- {
- if(isQuiet)
- return 0;
- else
- THError("cannot open <%s> in mode %c%c", name.c_str(), (isReadable ? 'r' : ' '), (isWritable ? 'w' : ' '));
- }
-
- self = (THDiskFile*)THAlloc(sizeof(THDiskFile));
- if (!self)
- THError("cannot allocate memory for self");
-
- self->handle = handle;
- self->isNativeEncoding = 1;
- self->longSize = 0;
-
- self->file.vtable = &vtable;
- self->file.isQuiet = isQuiet;
- self->file.isReadable = isReadable;
- self->file.isWritable = isWritable;
- self->file.isBinary = 0;
- self->file.isAutoSpacing = 1;
- self->file.hasError = 0;
-
- return (THFile*)self;
-}
-
-}
diff --git a/modules/dnn/src/torch/THDiskFile.h b/modules/dnn/src/torch/THDiskFile.h
deleted file mode 100644
index 68d1141e09..0000000000
--- a/modules/dnn/src/torch/THDiskFile.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef TH_DISK_FILE_INC
-#define TH_DISK_FILE_INC
-
-#include "THFile.h"
-#include
-
-namespace TH
-{
-
-TH_API THFile *THDiskFile_new(const std::string &name, const char *mode, int isQuiet);
-
-TH_API int THDiskFile_isLittleEndianCPU(void);
-TH_API int THDiskFile_isBigEndianCPU(void);
-TH_API void THDiskFile_nativeEndianEncoding(THFile *self);
-TH_API void THDiskFile_littleEndianEncoding(THFile *self);
-TH_API void THDiskFile_bigEndianEncoding(THFile *self);
-TH_API void THDiskFile_longSize(THFile *self, int size);
-TH_API void THDiskFile_noBuffer(THFile *self);
-
-} // namespace
-
-#endif
diff --git a/modules/dnn/src/torch/THFile.cpp b/modules/dnn/src/torch/THFile.cpp
deleted file mode 100644
index 5f7fe1cf03..0000000000
--- a/modules/dnn/src/torch/THFile.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-#include "../precomp.hpp"
-#include "THFile.h"
-#include "THFilePrivate.h"
-
-namespace TH {
-
-#define IMPLEMENT_THFILE_RW(TYPEC, TYPE) \
- long THFile_read##TYPEC##Raw(THFile *self, TYPE *data, long n) \
- { \
- return (*self->vtable->read##TYPEC)(self, data, n); \
- }
-
-IMPLEMENT_THFILE_RW(Byte, unsigned char)
-IMPLEMENT_THFILE_RW(Char, char)
-IMPLEMENT_THFILE_RW(Short, short)
-IMPLEMENT_THFILE_RW(Int, int)
-IMPLEMENT_THFILE_RW(Long, int64)
-IMPLEMENT_THFILE_RW(Float, float)
-IMPLEMENT_THFILE_RW(Double, double)
-
-long THFile_readStringRaw(THFile *self, const char *format, char **str_)
-{
- return self->vtable->readString(self, format, str_);
-}
-
-void THFile_seek(THFile *self, long position)
-{
- self->vtable->seek(self, position);
-}
-
-void THFile_seekEnd(THFile *self)
-{
- self->vtable->seekEnd(self);
-}
-
-long THFile_position(THFile *self)
-{
- return self->vtable->position(self);
-}
-
-void THFile_close(THFile *self)
-{
- self->vtable->close(self);
-}
-
-void THFile_free(THFile *self)
-{
- self->vtable->free(self);
-}
-
-int THFile_isOpened(THFile *self)
-{
- return self->vtable->isOpened(self);
-}
-
-#define IMPLEMENT_THFILE_FLAGS(FLAG) \
- int THFile_##FLAG(THFile *self) \
- { \
- return self->FLAG; \
- }
-
-IMPLEMENT_THFILE_FLAGS(isQuiet)
-IMPLEMENT_THFILE_FLAGS(isReadable)
-IMPLEMENT_THFILE_FLAGS(isWritable)
-IMPLEMENT_THFILE_FLAGS(isBinary)
-IMPLEMENT_THFILE_FLAGS(isAutoSpacing)
-IMPLEMENT_THFILE_FLAGS(hasError)
-
-void THFile_binary(THFile *self)
-{
- self->isBinary = 1;
-}
-
-void THFile_ascii(THFile *self)
-{
- self->isBinary = 0;
-}
-
-void THFile_autoSpacing(THFile *self)
-{
- self->isAutoSpacing = 1;
-}
-
-void THFile_noAutoSpacing(THFile *self)
-{
- self->isAutoSpacing = 0;
-}
-
-void THFile_quiet(THFile *self)
-{
- self->isQuiet = 1;
-}
-
-void THFile_pedantic(THFile *self)
-{
- self->isQuiet = 0;
-}
-
-void THFile_clearError(THFile *self)
-{
- self->hasError = 0;
-}
-
-#define IMPLEMENT_THFILE_SCALAR(TYPEC, TYPE) \
- TYPE THFile_read##TYPEC##Scalar(THFile *self) \
- { \
- TYPE scalar; \
- THFile_read##TYPEC##Raw(self, &scalar, 1); \
- return scalar; \
- }
-
-IMPLEMENT_THFILE_SCALAR(Byte, unsigned char)
-IMPLEMENT_THFILE_SCALAR(Char, char)
-IMPLEMENT_THFILE_SCALAR(Short, short)
-IMPLEMENT_THFILE_SCALAR(Int, int)
-IMPLEMENT_THFILE_SCALAR(Long, int64)
-IMPLEMENT_THFILE_SCALAR(Float, float)
-IMPLEMENT_THFILE_SCALAR(Double, double)
-
-} // namespace
diff --git a/modules/dnn/src/torch/THFile.h b/modules/dnn/src/torch/THFile.h
deleted file mode 100644
index 14e3fbf1e5..0000000000
--- a/modules/dnn/src/torch/THFile.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef TH_FILE_INC
-#define TH_FILE_INC
-
-//#include "THStorage.h"
-#include "opencv2/core/hal/interface.h"
-#include "THGeneral.h"
-
-namespace TH
-{
-typedef struct THFile__ THFile;
-
-TH_API int THFile_isOpened(THFile *self);
-TH_API int THFile_isQuiet(THFile *self);
-TH_API int THFile_isReadable(THFile *self);
-TH_API int THFile_isWritable(THFile *self);
-TH_API int THFile_isBinary(THFile *self);
-TH_API int THFile_isAutoSpacing(THFile *self);
-TH_API int THFile_hasError(THFile *self);
-
-TH_API void THFile_binary(THFile *self);
-TH_API void THFile_ascii(THFile *self);
-TH_API void THFile_autoSpacing(THFile *self);
-TH_API void THFile_noAutoSpacing(THFile *self);
-TH_API void THFile_quiet(THFile *self);
-TH_API void THFile_pedantic(THFile *self);
-TH_API void THFile_clearError(THFile *self);
-
-/* scalar */
-TH_API unsigned char THFile_readByteScalar(THFile *self);
-TH_API char THFile_readCharScalar(THFile *self);
-TH_API short THFile_readShortScalar(THFile *self);
-TH_API int THFile_readIntScalar(THFile *self);
-TH_API int64 THFile_readLongScalar(THFile *self);
-TH_API float THFile_readFloatScalar(THFile *self);
-TH_API double THFile_readDoubleScalar(THFile *self);
-
-/* raw */
-TH_API long THFile_readByteRaw(THFile *self, unsigned char *data, long n);
-TH_API long THFile_readCharRaw(THFile *self, char *data, long n);
-TH_API long THFile_readShortRaw(THFile *self, short *data, long n);
-TH_API long THFile_readIntRaw(THFile *self, int *data, long n);
-TH_API long THFile_readLongRaw(THFile *self, int64 *data, long n);
-TH_API long THFile_readFloatRaw(THFile *self, float *data, long n);
-TH_API long THFile_readDoubleRaw(THFile *self, double *data, long n);
-TH_API long THFile_readStringRaw(THFile *self, const char *format, char **str_); /* you must deallocate str_ */
-
-TH_API void THFile_seek(THFile *self, long position);
-TH_API void THFile_seekEnd(THFile *self);
-TH_API long THFile_position(THFile *self);
-TH_API void THFile_close(THFile *self);
-TH_API void THFile_free(THFile *self);
-} // namespace
-#endif //TH_FILE_INC
diff --git a/modules/dnn/src/torch/THFilePrivate.h b/modules/dnn/src/torch/THFilePrivate.h
deleted file mode 100644
index af3890d8e6..0000000000
--- a/modules/dnn/src/torch/THFilePrivate.h
+++ /dev/null
@@ -1,37 +0,0 @@
-namespace TH {
-
-struct THFile__
-{
- struct THFileVTable *vtable;
-
- int isQuiet;
- int isReadable;
- int isWritable;
- int isBinary;
- int isAutoSpacing;
- int hasError;
-};
-
-/* virtual table definition */
-
-struct THFileVTable
-{
- int (*isOpened)(THFile *self);
-
- long (*readByte)(THFile *self, unsigned char *data, long n);
- long (*readChar)(THFile *self, char *data, long n);
- long (*readShort)(THFile *self, short *data, long n);
- long (*readInt)(THFile *self, int *data, long n);
- long (*readLong)(THFile *self, int64 *data, long n);
- long (*readFloat)(THFile *self, float *data, long n);
- long (*readDouble)(THFile *self, double *data, long n);
- long (*readString)(THFile *self, const char *format, char **str_);
-
- void (*seek)(THFile *self, long position);
- void (*seekEnd)(THFile *self);
- long (*position)(THFile *self);
- void (*close)(THFile *self);
- void (*free)(THFile *self);
-};
-
-} // namespace
diff --git a/modules/dnn/src/torch/THGeneral.cpp b/modules/dnn/src/torch/THGeneral.cpp
deleted file mode 100644
index 0c27edc6fb..0000000000
--- a/modules/dnn/src/torch/THGeneral.cpp
+++ /dev/null
@@ -1,2 +0,0 @@
-#include "../precomp.hpp"
-#include "THGeneral.h"
diff --git a/modules/dnn/src/torch/THGeneral.h b/modules/dnn/src/torch/THGeneral.h
deleted file mode 100644
index cdcbe3d905..0000000000
--- a/modules/dnn/src/torch/THGeneral.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#ifndef TH_GENERAL_INC
-#define TH_GENERAL_INC
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-#define TH_API
-
-#define THError(...) CV_Error(cv::Error::StsError, cv::format(__VA_ARGS__))
-#define THArgCheck(cond, ...) CV_Assert(cond)
-
-#define THAlloc malloc
-#define THRealloc realloc
-#define THFree free
-
-#endif
diff --git a/modules/dnn/src/torch/torch_importer.cpp b/modules/dnn/src/torch/torch_importer.cpp
deleted file mode 100644
index 3a46c8f7c0..0000000000
--- a/modules/dnn/src/torch/torch_importer.cpp
+++ /dev/null
@@ -1,1267 +0,0 @@
-/*M///////////////////////////////////////////////////////////////////////////////////////
-//
-// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
-//
-// By downloading, copying, installing or using the software you agree to this license.
-// If you do not agree to this license, do not download, install,
-// copy or use the software.
-//
-//
-// License Agreement
-// For Open Source Computer Vision Library
-//
-// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
-// Third party copyrights are property of their respective owners.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// * Redistribution's of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// * Redistribution's in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation
-// and/or other materials provided with the distribution.
-//
-// * The name of the copyright holders may not be used to endorse or promote products
-// derived from this software without specific prior written permission.
-//
-// This software is provided by the copyright holders and contributors "as is" and
-// any express or implied warranties, including, but not limited to, the implied
-// warranties of merchantability and fitness for a particular purpose are disclaimed.
-// In no event shall the Intel Corporation or contributors be liable for any direct,
-// indirect, incidental, special, exemplary, or consequential damages
-// (including, but not limited to, procurement of substitute goods or services;
-// loss of use, data, or profits; or business interruption) however caused
-// and on any theory of liability, whether in contract, strict liability,
-// or tort (including negligence or otherwise) arising in any way out of
-// the use of this software, even if advised of the possibility of such damage.
-//
-//M*/
-
-#include "../precomp.hpp"
-
-#include
-
-#include
-#include
-#include