Cuda-Chen / SRCNN-cpp

C++ implementation of SRCNN (Super-Resolution Convolutional Neural Network)
MIT License
4 stars 1 forks source link

Segmentation fault #1

Closed masc4ii closed 4 years ago

masc4ii commented 4 years ago

I tried to run your code, but ended with a "Segmentation fault: 11". I am on OSX 10.13, and use openCV4.2.0. The program compiled without problem. This is the output when running:

$./SRCNN_cpp lenna.bmp 
prepare data
input width height 512 512
output width height 512 512
assign input and output value
read conv and bias weights
kernelDim
biasDim
finish setting bias dim
finish allocating conv and bias weights' space
weight[0]
weight[1]
weight[2]
weight[3]
weight[4]
weight[5]
conv1
conv2
Segmentation fault: 11

Any idea? Thanks for your help!

masc4ii commented 4 years ago

This is the line, where the crash happens:

Bildschirmfoto 2020-01-29 um 15 33 04
Cuda-Chen commented 4 years ago

Hi masc4ii,

This project is incomplete, and I am trying my best on conv2 segmentation fault. I will fix this issue as soon as possible :)

masc4ii commented 4 years ago

Great! :)

Cuda-Chen commented 4 years ago

Fixed in commit 242c98a.

Cuda-Chen commented 4 years ago

Hi @masc4ii , I have fixed seg fault issue. However, the output presents ringing effect. If you have any idea about solving this, it would be glad :)

masc4ii commented 4 years ago

Thank you for fixing. The program runs now without crash, but needs around 30min for lenna.bmp. Maybe I could have a look to accelerate with openMP (parallel for loop). I can see the ringing effect but so far I don't know how to solve this. Do you process only B/W at the moment?

Cuda-Chen commented 4 years ago

Current my SRCNN can only support grayscale image (color image will be transformed to grayscale before super-resolution).

Of course, adding openMP is quite welcome :)

By the way, on my computer it takes about 4min for lenna.bmp. I am curious about your environment.

masc4ii commented 4 years ago

I have problems to integrate openMP into the cmake project file. Do you know how to get it included there? In other projects (Qt projects) I do this:

    QMAKE_CC = /usr/local/opt/llvm/bin/clang
    QMAKE_CXX = /usr/local/opt/llvm/bin/clang++
    QMAKE_LINK = /usr/local/opt/llvm/bin/clang++
    QMAKE_CFLAGS += -fopenmp
    QMAKE_CXXFLAGS += -fopenmp
    INCLUDEPATH += -I/usr/local/opt/llvm/include
    LIBS += -L/usr/local/opt/llvm/lib -lgomp

Could you try to translate this to cmake? This code is for OSX, maybe it also works for Linux. On Windows the paths should be different - sure. Maybe there is also an easier way to integrate openMP with cmake - no idea.

I tried your project on a MBP2013, i5 DualCore 2.4GHz.

Cuda-Chen commented 4 years ago

I will try to add OpenMP with Cmake later soon. edit: I create an example of OpenMP with CMake. Feel free to use it: https://github.com/Cuda-Chen/openmp_practice/blob/master/hello_cmake/CMakeLists.txt

By the way, maybe you can check im2col() function. I think it is the reason why it runs slowly.

masc4ii commented 4 years ago

Thank you. Unfortunately I get this with that:

CMake Error at /usr/local/Cellar/cmake/3.16.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:146 (message):
  Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
Call Stack (most recent call first):
  /usr/local/Cellar/cmake/3.16.3/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:393 (_FPHSA_FAILURE_MESSAGE)
  /usr/local/Cellar/cmake/3.16.3/share/cmake/Modules/FindOpenMP.cmake:511 (find_package_handle_standard_args)
  CMakeLists.txt:22 (find_package)

On the first view I can't see something bad in im2col(). What makes you think it could be the reason?

masc4ii commented 4 years ago

I wrote a Qt project file (without Qt dependencies, just as automatism to create a makefile, instead of cmake), got openMP and openCV working with it. I made some little changes to the code and now it processes in ~8.x min (~30 min before), so the 4 threads multithreading (DualCore + HT) seem to work here nicely. The final image looks identically (so multithreading seems not to create additional problems). I should clone your project and do a pull request.

masc4ii commented 4 years ago

If you like to try: https://github.com/masc4ii/SRCNN-cpp (You should insert openMP in the cmake for your system. I did not do this yet.)

Cuda-Chen commented 4 years ago

I have visited your work, and it's pretty awesome! On my 8-core mac, openMP version takes about 1min compared to 4min with single-core. Pretty huge speed up.

I think I can merge the qmake for another compilation option.

At last, I have been working on the weight format this month, and today I let the result to be 'correct'. But the code changes a lot, so I think I will take some time to merge the work.

Anyway, remember to write your name on README for this honorable moment!

Cuda-Chen commented 4 years ago

Hi @masc4ii , I merged your pull request and develop branch yesterday. I will work on using OpenMP with CMake as an option later.

Also, I added your name in README. Cheers!