albarji / neural-style-docker

A dockerized version of neural style transfer algorithms
MIT License
112 stars 34 forks source link

ValueError in imagemagick.py #30

Open IQNeoXen opened 5 years ago

IQNeoXen commented 5 years ago

Hi @albarji, first of all thank you for creating a dockerized version of the neural-style project! :)

However, i'm not able to get it to run properly. I'm calling it like this:

sudo nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content content.png --style style.png --output results
It starts as expected:

```bash iqneoxen@mymachine $ nvidia-docker run --rm -v $(pwd):/images albarji/neural-style --content content.png --style style.png --output results INFO:__main__:Running neural style transfer with INFO:__main__: Contents = ['/images/content.png'] INFO:__main__: Style = ['/images/style.png'] INFO:__main__: Algorithm = gatys INFO:__main__: Style weights = None INFO:__main__: Style scales = None INFO:__main__: Size = None INFO:__main__: Tile overlap = None WARNING:neuralstyle.algorithms:Unknown GPU model GeForce GTX 1080, will use default tiling parameters INFO:neuralstyle.algorithms:Starting tiling strategy WARNING:neuralstyle.algorithms:Unknown GPU model GeForce GTX 1080, will use default tiling parameters INFO:neuralstyle.algorithms:Running command: cd /app/neural-style; th neural_style.lua -backend cudnn -cudnn_autotune -normalize_gradients -init image -content_weight 100 -save_iter 10000 -proto_file /app/neural-style/models/VGG_ILSVRC_19_layers_deploy.prototxt -model_file /app/neural-style/models/VGG_ILSVRC_19_layers.caffemodel -num_iterations 500 -content_image /tmp/tmp8u63rldd/rgb.png -style_image /tmp/tmp8u63rldd/style.png -style_weight 500.0 -style_scale 1.0 -output_image /tmp/tmppzpmeoqt.png -image_size 466 tput: No value for $TERM and no -T specified [libprotobuf WARNING google/protobuf/io/coded_stream.cc:537] 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 /app/neural-style/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 Setting up style layer 2 : relu1_1 Setting up style layer 7 : relu2_1 Setting up style layer 12 : relu3_1 Setting up style layer 21 : relu4_1 Setting up content layer 23 : relu4_2 Setting up style layer 30 : relu5_1 Capturing content targets nn.Sequential { [input -> (1) -> (2) -> (3) -> (4) -> (5) -> (6) -> (7) -> (8) -> (9) -> (10) -> (11) -> (12) -> (13) -> (14) -> (15) -> (16) -> (17) -> (18) -> (19) -> (20) -> (21) -> (22) -> (23) -> (24) -> (25) -> (26) -> (27) -> (28) -> (29) -> (30) -> (31) -> (32) -> (33) -> (34) -> (35) -> (36) -> (37) -> output] (1): nn.TVLoss (2): cudnn.SpatialConvolution(3 -> 64, 3x3, 1,1, 1,1) (3): cudnn.ReLU (4): nn.StyleLoss [...............and so on] ```

It runs for ~10-20 minutes and then i'm getting an error like this every time:

```bash Iteration 500 / 500 Content 1 loss: 27202762.500000 Style 1 loss: 128.602207 Style 2 loss: 6182.222366 Style 3 loss: 4729.293823 Style 4 loss: 187635.543823 Style 5 loss: 655.002296 Total loss: 27402093.164515 reached max number of iterations neural-style-docker: artistic style between images --content CONTENT_IMAGES: file or files with the content images to use --style STYLE_IMAGES: file or files with the styles to transfer --output OUTPUT_FOLDER: name of the output folder in which to save results --size SIZE: size of the output image. Default: content image size --sw STYLE_WEIGHT (default 5): weight or list of weights of the style over the content, in range (0, inf) --ss STYLE_SCALE (default 1.0): scaling or list of scaling factors for the style images --alg ALGORITHM: style-transfer algorithm to use. Must be one of the following: gatys Highly detailed transfer, slow processing times (default) gatys-multiresolution Multipass version of Gatys method, provides even better quality chen-schmidt Fast patch-based style transfer chen-schmidt-inverse Even faster aproximation to chen-schmidt through the use of an inverse network --tileoverlap TILE_OVERLAP: overlap of tiles in the style transfer, measured in pixels. If you experience artifacts in the image you should try increasing this. Default: 100 Additionally provided parameters are carried on to the underlying algorithm. Traceback (most recent call last): File "/app/entrypoint/entrypoint.py", line 100, in main styletransfer(contents, styles, savefolder, size, alg, weights, stylescales, tileoverlap, algparams=otherparams) File "/app/entrypoint/neuralstyle/algorithms.py", line 90, in styletransfer weight=weight, stylescale=scale, algparams=algparams) File "/app/entrypoint/neuralstyle/algorithms.py", line 162, in neuraltile smush(featheredtiles, xtiles, ytiles, overlap, overlap, smushedfeathered) File "/app/entrypoint/neuralstyle/imagemagick.py", line 59, in smush % (xtiles, ytiles, len(tiles))) ValueError: Geometry (8,10) is incompatible with given number of tiles (88) ```

It seems like there's an issue in the "smush" function https://github.com/albarji/neural-style-docker/blob/acc490ba9d92b27796fe7c7f01561d03558dd9a6/neuralstyle/imagemagick.py#L55-L70

Could you help me to find out what the issue is here? Thank you very much in advance!

albarji commented 5 years ago

Hi there! Sorry for the late answer, but I'm only finding time to maintain this project on my holidays.

At first glance I can't tell what is the source of the error. But 88 tiles seems like an awfully large number of tiles. What is the size of your input image? Can you try again using --size 512? This will force the output to be small enough to fit into a single tile, so the smush stuff won't be used.