luanfujun/deep-photo-styletransfer

Matio can't load CSR files

themightyoarfish opened this issue ยท 12 comments

When I try running step 4 (after having generated the intermediate for in1 and tra1 successfully), I get this

th deepmatting_seg.lua -content_image examples/input/in1.png -style_image examples/style/tar1.png -content_seg examples/segmentation/in1.png -style_seg examples/segmentation/tar1.png -init_image serial_example/out1_t_1000.png -serial outputs -f_radius 15 -f_edge 0.01
gpu, idx =      0       1
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:505] Reading dangerously large protocol message.  If the message turns out to be larger than 1073741824 bytes, parsing will be halted for security reasons.  To increase the limit (or to disable these warnings), see CodedInputStream::SetTotalBytesLimit() in google/protobuf/io/coded_stream.h.
[libprotobuf WARNING google/protobuf/io/coded_stream.cc:78] The total number of bytes read was 574671192
Successfully loaded models/VGG_ILSVRC_19_layers.caffemodel
conv1_1: 64 3 3 3
conv1_2: 64 64 3 3
conv2_1: 128 64 3 3
conv2_2: 128 128 3 3
conv3_1: 256 128 3 3
conv3_2: 256 256 3 3
conv3_3: 256 256 3 3
conv3_4: 256 256 3 3
conv4_1: 512 256 3 3
conv4_2: 512 512 3 3
conv4_3: 512 512 3 3
conv4_4: 512 512 3 3
conv5_1: 512 512 3 3
conv5_2: 512 512 3 3
conv5_3: 512 512 3 3
conv5_4: 512 512 3 3
fc6: 1 1 25088 4096
fc7: 1 1 4096 4096
fc8: 1 1 4096 1000
loading matting laplacian...    gen_laplacian/Input_Laplacian_3x3_1e-7_CSR1.mat
File could not be opened: gen_laplacian/Input_Laplacian_3x3_1e-7_CSR1.mat
/home/ubuntu/torch/install/bin/luajit: deepmatting_seg.lua:119: attempt to index a nil value
stack traceback:
        deepmatting_seg.lua:119: in function 'main'
        deepmatting_seg.lua:606: in main chunk
        [C]: in function 'dofile'
        ...untu/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
        [C]: at 0x00406670

The CSR file is generated with octave 4.0. There's an issue here, that hints at Matlab version compatibility issues. I don't know if this prevents use of Octave.

I had the same problem. I rewrote the MATLAB bit in Python and made a PR, but you can also pick up the fork here: https://github.com/martinbenson/deep-photo-styletransfer

I'm seeing the same issue when using Octave

Same issue, with Octave.
GNU Octave, version 4.0.2
Ubuntu 16.04

Here's one workaround to be able to read your Octave produced laplacian data in matio, you can use Octave to load and resave it in a matlab compatible format. First, load your existing .mat file in Ocatave using:

data = load('gen_laplacian/Input_Laplacian_3x3_1e-7_CSR1.mat')

Don't forget to back up the .mat file since they take forever to generate. Now save in a matlab (and matio) compatible format using:

save "-mat7-binary" gen_laplacian/Input_Laplacian_3x3_1e-7_CSR1.mat data

More info on loading/saving here. Now you can see your data:

image

The row count is correct for my test image at the time of the screenshot (different from the final image however, this process took a few troubleshooting trials). Note mat7data.data.CSR, this is what we want to pass to cuda() in this line of deepmatting_seg.lua. So that line changes from:

local CSR = matio.load(CSR_fn).CSR:cuda()
to
local CSR = matio.load(CSR_fn).data.CSR:cuda()

Here is my resulting test image. I chose perhaps the most unremarkable example image from this repo's collection, but you can see it looks about how we'd expect when compared to the promo photos in the main README:

image

Thanks @jogleasonjr ! It worked perflectly for me :)

I did compile all the gen_laplacian with Octave then tried out @jogleasonjr .mat approach. However it didn't seem to work for me, I keep getting this error, any thoughts?

loading matting laplacian...	gen_laplacian/Input_Laplacian_3x3_1e-7_CSR1.mat	
Segmentation fault (core dumped)

Thanks

@jogleasonjr Your approach is also useful for me. Thank you very much. But I am a little confused about how do you know that "The row count is correct for my test images. "?

For the test image in1.png, the size of my data is 7613426x3, not 12208036x3 shown in your figure. So do you change the script file, which is used to generate the "Input_Laplacian_3x3_1e-7_CSR1.mat"?

@John-HW-Cao Apologies for the confusion. The screenshots I took were from disjointed trial runs using different images, where at the end I tested the provided in1.png end-to-end. So when I said "The row count is correct for my test images", I should have said "The row count is correct for my test image at the time of the screenshot (different from the final image however, this process took a few troubleshooting trials). "

I've updated my comment. Thanks for pointing this out!

@jogleasonjr Thank you for your quick response!

@John-HW-Cao How to do that?Can you help me?Where is the file 'Input_Laplacian_3x3_1e-7_CSR1.mat'

It works well by jogleasonjr 's method. But when we want to run a dataset, it will cost much manual operation. I change the code in

gen_laplacian.m
from
save( ['Input_Laplacian_3x3_1e-7_CSR' int2str(i) '.mat'], 'CSR');
to
save("-mat7-binary", ['Input_Laplacian_3x3_1e-7_CSR' int2str(i) '.mat'], 'CSR');
In this way, we don't need to change the code of deepmatting_seg.lua as mentioned before.

I've been met with the same issue and have also tried the approach @jogleasonjr has outlined but am also met with the same segmentation fault issue as before when loading the generated laplacian.mat file inside of deepmatting_seg.lua

Are there any more approaches I could take to solve this issue? I am using Octave 4.2.1 to generate the laplacian file.