hnarayanan / artistic-style-transfer Goto Github PK
View Code? Open in Web Editor NEWConvolutional neural networks for artistic style transfer.
Home Page: https://harishnarayanan.org/writing/artistic-style-transfer/
Convolutional neural networks for artistic style transfer.
Home Page: https://harishnarayanan.org/writing/artistic-style-transfer/
Good project and explanation, I have one question when we train our model on specific style, can we reuse it with another images ? with less time of moving style ?
Do I have make this long process every time whenever I want one style to another image ?
in you wonderful blog "Convolutional neural networks for artistic style transfer", you said "the Gram matrix is a special case of a more general object". what is the general object, can you please give some reference? thank you.
pip install -r requirements.txt
This failed with the following output (Under Mac OSX 10.13.1, Python 3.6.2 :: Anaconda, Inc.)
Collecting backports-abc==0.5 (from -r requirements.txt (line 1))
Using cached backports_abc-0.5-py2.py3-none-any.whl
Collecting backports.functools-lru-cache==1.4 (from -r requirements.txt (line 2))
Using cached backports.functools_lru_cache-1.4-py2.py3-none-any.whl
Collecting backports.shutil-get-terminal-size==1.0.0 (from -r requirements.txt (line 3))
Using cached backports.shutil_get_terminal_size-1.0.0-py2.py3-none-any.whl
Collecting backports.weakref==1.0.post1 (from -r requirements.txt (line 4))
Using cached backports.weakref-1.0.post1-py2.py3-none-any.whl
Collecting bleach==1.5.0 (from -r requirements.txt (line 5))
Using cached bleach-1.5.0-py2.py3-none-any.whl
Collecting certifi==2017.7.27.1 (from -r requirements.txt (line 6))
Using cached certifi-2017.7.27.1-py2.py3-none-any.whl
Collecting configparser==3.5.0 (from -r requirements.txt (line 7))
Collecting cycler==0.10.0 (from -r requirements.txt (line 8))
Using cached cycler-0.10.0-py2.py3-none-any.whl
Collecting decorator==4.1.2 (from -r requirements.txt (line 9))
Using cached decorator-4.1.2-py2.py3-none-any.whl
Collecting entrypoints==0.2.3 (from -r requirements.txt (line 10))
Using cached entrypoints-0.2.3-py2.py3-none-any.whl
Collecting enum34==1.1.6 (from -r requirements.txt (line 11))
Using cached enum34-1.1.6-py3-none-any.whl
Collecting funcsigs==1.0.2 (from -r requirements.txt (line 12))
Using cached funcsigs-1.0.2-py2.py3-none-any.whl
Collecting functools32==3.2.3.post2 (from -r requirements.txt (line 13))
Using cached functools32-3.2.3-2.zip
Complete output from command python setup.py egg_info:
This backport is for Python 2.7 only.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/bh/580zbdb14t1b26zw3f1665wm0000gn/T/pip-build-yx7awoq3/functools32/
any idea how I can fix this issue?
Could not find a version that satisfies the requirement tensorflow==1.4.0 (from -r requirements.txt (line 60)) (from versions: )
No matching distribution found for tensorflow==1.4.0 (from -r requirements.txt (line 60))
I followed the instructions but I get this error when running step 8 of the 6th notebook. Any ideas what might be wrong? Looking forward to tomorrow.
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-2dbcbeeb6bc8> in <module>()
1 model = VGG16(input_tensor=input_tensor, weights='imagenet',
----> 2 include_top=False)
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/applications/vgg16.pyc in VGG16(include_top, weights, input_tensor, input_shape, classes)
94 x = Convolution2D(128, 3, 3, activation='relu', border_mode='same', name='block2_conv1')(x)
95 x = Convolution2D(128, 3, 3, activation='relu', border_mode='same', name='block2_conv2')(x)
---> 96 x = MaxPooling2D((2, 2), strides=(2, 2), name='block2_pool')(x)
97
98 # Block 3
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/engine/topology.pyc in __call__(self, x, mask)
570 if inbound_layers:
571 # This will call layer.build() if necessary.
--> 572 self.add_inbound_node(inbound_layers, node_indices, tensor_indices)
573 # Outputs were already computed when calling self.add_inbound_node.
574 outputs = self.inbound_nodes[-1].output_tensors
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/engine/topology.pyc in add_inbound_node(self, inbound_layers, node_indices, tensor_indices)
633 # creating the node automatically updates self.inbound_nodes
634 # as well as outbound_nodes on inbound layers.
--> 635 Node.create_node(self, inbound_layers, node_indices, tensor_indices)
636
637 def get_output_shape_for(self, input_shape):
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/engine/topology.pyc in create_node(cls, outbound_layer, inbound_layers, node_indices, tensor_indices)
164
165 if len(input_tensors) == 1:
--> 166 output_tensors = to_list(outbound_layer.call(input_tensors[0], mask=input_masks[0]))
167 output_masks = to_list(outbound_layer.compute_mask(input_tensors[0], input_masks[0]))
168 # TODO: try to auto-infer shape
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/layers/pooling.pyc in call(self, x, mask)
158 strides=self.strides,
159 border_mode=self.border_mode,
--> 160 dim_ordering=self.dim_ordering)
161 return output
162
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/layers/pooling.pyc in _pooling_function(self, inputs, pool_size, strides, border_mode, dim_ordering)
208 output = K.pool2d(inputs, pool_size, strides,
209 border_mode, dim_ordering,
--> 210 pool_mode='max')
211 return output
212
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/keras/backend/tensorflow_backend.pyc in pool2d(x, pool_size, strides, border_mode, dim_ordering, pool_mode)
2864
2865 if pool_mode == 'max':
-> 2866 x = tf.nn.max_pool(x, pool_size, strides, padding=padding)
2867 elif pool_mode == 'avg':
2868 x = tf.nn.avg_pool(x, pool_size, strides, padding=padding)
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/nn_ops.pyc in max_pool(value, ksize, strides, padding, data_format, name)
1791 padding=padding,
1792 data_format=data_format,
-> 1793 name=name)
1794
1795
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/ops/gen_nn_ops.pyc in _max_pool(input, ksize, strides, padding, data_format, name)
1596 result = _op_def_lib.apply_op("MaxPool", input=input, ksize=ksize,
1597 strides=strides, padding=padding,
-> 1598 data_format=data_format, name=name)
1599 return result
1600
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/op_def_library.pyc in apply_op(self, op_type_name, name, **keywords)
761 op = g.create_op(op_type_name, inputs, output_types, name=scope,
762 input_types=input_types, attrs=attr_protos,
--> 763 op_def=op_def)
764 if output_structure:
765 outputs = op.outputs
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in create_op(self, op_type, inputs, dtypes, input_types, name, attrs, op_def, compute_shapes, compute_device)
2395 original_op=self._default_original_op, op_def=op_def)
2396 if compute_shapes:
-> 2397 set_shapes_for_outputs(ret)
2398 self._add_op(ret)
2399 self._record_op_seen_by_control_dependencies(ret)
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in set_shapes_for_outputs(op)
1755 shape_func = _call_cpp_shape_fn_and_require_op
1756
-> 1757 shapes = shape_func(op)
1758 if shapes is None:
1759 raise RuntimeError(
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/ops.pyc in call_with_requiring(op)
1705
1706 def call_with_requiring(op):
-> 1707 return call_cpp_shape_fn(op, require_shape_fn=True)
1708
1709 _call_cpp_shape_fn_and_require_op = call_with_requiring
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.pyc in call_cpp_shape_fn(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
608 res = _call_cpp_shape_fn_impl(op, input_tensors_needed,
609 input_tensors_as_shapes_needed,
--> 610 debug_python_shape_fn, require_shape_fn)
611 if not isinstance(res, dict):
612 # Handles the case where _call_cpp_shape_fn_impl calls unknown_shape(op).
/home/john/src/artistic-style-transfer/venv/local/lib/python2.7/site-packages/tensorflow/python/framework/common_shapes.pyc in _call_cpp_shape_fn_impl(op, input_tensors_needed, input_tensors_as_shapes_needed, debug_python_shape_fn, require_shape_fn)
673 missing_shape_fn = True
674 else:
--> 675 raise ValueError(err.message)
676
677 if missing_shape_fn:
ValueError: Negative dimension size caused by subtracting 2 from 1 for 'MaxPool_1' (op: 'MaxPool') with input shapes: [3,256,1,128].
Hi Harish,
There could be an error in the 6th notebook when you tried to resize the image using resize((height, width)). Turns out it should be resize((width, height)) as I was trying on some more general rectangular picture. The example in your notebook works because height=width.
BTW, what's your laptop configuration? It took my 2-year old laptop to run each iteration much longer......
Thanks for your excellent illustration of the whole process.
J
I'm new to code, in general, I was wondering if there is an easy fix to this I'm not able to find
Collecting tensorflow==1.4.0 (from -r requirements.txt (line 60))
Could not find a version that satisfies the requirement tensorflow==1.4.0 (from -r requirements.txt (line 60)) (from versions: )
No matching distribution found for tensorflow==1.4.0 (from -r requirements.txt (line 60))
Thank you very much,
Sky Goodman
In notebook 6, this line of code gives rise to this error:
"RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead."
Hi,
I recently read your blogpost on style transferring. I understood every single bit of it, but I was wondering how you may have written it(the code)? As a beginner, whenever I take up a project, I find myself able to understand complete concepts, but still look for pieces of code online(for syntax and sometimes concepts too). And later on I start feeling that I didn't do things by myself. So what is the way to learn and implement a project? After looking at your code, it was easy to understand everything, but the fact that you wrote it from start to end ,by yourself, makes me feel intimidated. I seriously want to know the approach you and many other developers take when it comes to learning and implementing.
Hey, I came across your work on style transfer and found it amazing. But I'm getting stuck on the implementation part. Your code is for Python 2.7 but Tensorflow supports 3.5 and above right?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.