Skip to content

Commit

Permalink
Providing a better error message for mismatch in number of channels. C…
Browse files Browse the repository at this point in the history
…loses #11.
  • Loading branch information
alexjc committed Mar 10, 2016
1 parent d0dfd86 commit c899494
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 5 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ The algorithm is built for style transfer, but can also generate image analogies
.. code:: bash
# Synthesize a coastline as if painted by Monet. This uses "*_sem.png" masks for both images.
python3 doodle.py --style samples/Monet.jpg --output samples/Coastline.png\
python3 doodle.py --style samples/Monet.jpg --output samples/Coastline.png \
--device=cpu --iterations=40
# Generate a scene around a lake in the style of a Renoir painting.
python3 doodle.py --style samples/Renoir.jpg --output samples/Landscape.png\
python3 doodle.py --style samples/Renoir.jpg --output samples/Landscape.png \
--device=gpu0 --iterations=80
Note the ``--device`` argument that lets you specify which GPU or CPU to use. For the samples above, here are the performance results:

* **GPU Rendering** — Assuming you have enough on-board RAM, the process should complete in less than 10 minutes, even with twice the iterations.
* **CPU Rendering** — This will take hours and hours, possibly up to 12h on older haldware. To match quality it'd take twice the time.
* **GPU Rendering** — Assuming you have CUDA and enough on-board RAM, the process should complete in less than 10 minutes, even with twice the iterations.
* **CPU Rendering** — This will take hours and hours, even up to 12h on older haldware. To match quality it'd take twice the time. Do multiple runs in parallel!

The default is to use ``cpu``, if you have NVIDIA card setup with CUDA already try ``gpu0``. You can also set environment variable to ``OMP_NUM_THREADS=4`` for CPU use, but we've found the speed improvements to be minimal.
The default is to use ``cpu``, if you have NVIDIA card setup with CUDA already try ``gpu0``. On the CPU, you can also set environment variable to ``OMP_NUM_THREADS=4``, but we've found the speed improvements to be minimal.


Installation & Setup
Expand Down
6 changes: 4 additions & 2 deletions doodle.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ def __init__(self):
self.content_img_original = np.zeros(self.content_map_original.shape[:2]+(3,))
args.content_weight = 0.0

assert self.content_map_original.shape[2] == self.style_map_original.shape[2],\
"Mismatch in number of channels for style and content semantic map."
if self.content_map_original.shape[2] != self.style_map_original.shape[2]:
print("\n{}ERROR: Mismatch in number of channels for style and content semantic map.\n"\
"{} - Make sure both images are RGB or RGBA.{}\n".format(ansi.RED_B, ansi.RED, args.style, ansi.ENDC))
sys.exit(-1)

def load_images(self, name, filename):
"""If the image and map files exist, load them. Otherwise they'll be set to default values later.
Expand Down

0 comments on commit c899494

Please sign in to comment.