├── LICENSE ├── README.md ├── examples ├── equations │ ├── content.png │ ├── email.png │ └── plot.png ├── gatys_figure │ ├── tubingen.png │ ├── tubingen_kandinsky.png │ ├── tubingen_picasso.png │ ├── tubingen_scream.png │ ├── tubingen_shipwreck.png │ └── tubingen_starry_night.png ├── initialization │ ├── init_content.png │ ├── init_random_0.png │ ├── init_random_1.png │ ├── init_random_2.png │ ├── init_random_3.png │ ├── init_random_4.png │ └── init_style.png ├── layers │ ├── conv1_1_1e2.png │ ├── conv1_1_1e3.png │ ├── conv1_1_1e4.png │ ├── conv1_1_1e5.png │ ├── conv2_1_1e2.png │ ├── conv2_1_1e3.png │ ├── conv2_1_1e4.png │ ├── conv2_1_1e5.png │ ├── conv3_1_1e2.png │ ├── conv3_1_1e3.png │ ├── conv3_1_1e4.png │ ├── conv3_1_1e5.png │ ├── conv4_1_1e2.png │ ├── conv4_1_1e3.png │ ├── conv4_1_1e4.png │ ├── conv4_1_1e5.png │ ├── conv5_1_1e2.png │ ├── conv5_1_1e3.png │ ├── conv5_1_1e4.png │ ├── conv5_1_1e5.png │ ├── relu1_1_1e2.png │ ├── relu1_1_1e3.png │ ├── relu1_1_1e4.png │ ├── relu1_1_1e5.png │ ├── relu2_1_1e2.png │ ├── relu2_1_1e3.png │ ├── relu2_1_1e4.png │ ├── relu2_1_1e5.png │ ├── relu3_1_1e2.png │ ├── relu3_1_1e3.png │ ├── relu3_1_1e4.png │ ├── relu3_1_1e5.png │ ├── relu4_1_1e2.png │ ├── relu4_1_1e3.png │ ├── relu4_1_1e4.png │ ├── relu4_1_1e5.png │ ├── relu5_1_1e2.png │ ├── relu5_1_1e3.png │ ├── relu5_1_1e4.png │ └── relu5_1_1e5.png ├── lions │ ├── 32_output.png │ ├── 33_output.png │ ├── 42_output.png │ ├── basquiat_output.png │ ├── calliefink_output.png │ ├── content_style.png │ ├── giger_output.png │ ├── kandinsky_output.png │ ├── styles │ │ ├── basquiat_crop.jpg │ │ ├── calliefink_crop.jpg │ │ ├── giger_crop.jpg │ │ ├── kandinsky_crop.jpg │ │ ├── matisse_crop.jpg │ │ ├── water_lilies_crop.jpg │ │ └── wave_crop.jpg │ └── wave_output.png ├── multiple_styles │ ├── tubingen_afremov_grey.png │ ├── tubingen_basquiat_nielly.png │ ├── tubingen_scream_kandinsky.png │ ├── tubingen_seated_kandinsky.png.png │ ├── tubingen_starry_scream.png │ └── tubingen_starry_seated.png ├── original_colors │ ├── garden.png │ ├── garden_starry.png │ ├── garden_starry_yuv.png │ ├── new_york.png │ ├── stylized.png │ └── stylized_original_colors.png ├── pareidolic │ ├── ben_giles_output.png │ ├── dark_matter_output.png │ ├── flowers_output.png │ ├── oil_output.png │ └── styles │ │ ├── ben_giles.png │ │ ├── dark_matter_bw.png │ │ ├── flowers_crop.jpg │ │ └── oil_crop.jpg ├── segmentation │ ├── 00017.jpg │ ├── 00017_mask.png │ ├── 00017_output.png │ ├── 00110.jpg │ ├── 00110_mask.png │ ├── 00110_output.png │ ├── 00768.jpg │ ├── 00768_mask.png │ ├── 00768_output.png │ ├── 02270.jpg │ ├── 02270_mask_face.png │ ├── 02270_mask_face_inv.png │ ├── 02270_output.png │ ├── 02390.jpg │ ├── 02390_mask.png │ ├── 02390_mask_inv.png │ ├── 02390_output.png │ ├── 02630.png │ ├── 02630_mask.png │ ├── 02630_output.png │ ├── basquiat.png │ ├── frida.png │ ├── okeffe_iris.png │ └── okeffe_red_canna.png ├── style_content_tradeoff │ ├── okeffe.jpg │ ├── okeffe_10.png │ ├── okeffe_100.png │ ├── okeffe_1000.png │ ├── okeffe_10000.png │ ├── output_100000.png │ └── output_1000000.png ├── style_interpolation │ ├── golden_gate_scream_3_starry_7.png │ ├── golden_gate_scream_5_starry_5.png │ ├── golden_gate_scream_7_starry_3.png │ ├── taj_mahal_afremov_grey_2_8.png │ ├── taj_mahal_afremov_grey_5_5.png │ ├── taj_mahal_afremov_grey_8_2.png │ ├── taj_mahal_scream_2_starry_8.png │ ├── taj_mahal_scream_5_starry_5.png │ └── taj_mahal_scream_8_starry_2.png └── video │ ├── input.gif │ ├── opt_flow.gif │ ├── output.gif │ └── weights.gif ├── image_input ├── face.jpg ├── face_mask.png ├── face_mask_inv.png ├── golden_gate.jpg ├── lion.jpg ├── taj_mahal.jpg └── tubingen.jpg ├── neural_style.py ├── requirements.txt ├── styles ├── kandinsky.jpg ├── seated-nude.jpg ├── shipwreck.jpg ├── starry-night.jpg ├── the_scream.jpg └── woman-with-hat-matisse.jpg ├── stylize_image.sh ├── stylize_video.sh └── video_input ├── consistencyChecker ├── CFilter.h ├── CMatrix.h ├── CTensor.h ├── CTensor4D.h ├── CVector.h ├── Makefile ├── NMath.cpp ├── NMath.h ├── consistencyChecker └── consistencyChecker.cpp ├── deepflow2-static ├── deepmatching-static ├── make-opt-flow.sh └── run-deepflow.sh /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # neural-style-tf 2 | 3 | This is a TensorFlow implementation of several techniques described in the papers: 4 | * [Image Style Transfer Using Convolutional Neural Networks](http://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Gatys_Image_Style_Transfer_CVPR_2016_paper.pdf) 5 | by Leon A. Gatys, Alexander S. Ecker, Matthias Bethge 6 | * [Artistic style transfer for videos](https://arxiv.org/abs/1604.08610) 7 | by Manuel Ruder, Alexey Dosovitskiy, Thomas Brox 8 | * [Preserving Color in Neural Artistic Style Transfer](https://arxiv.org/abs/1606.05897) 9 | by Leon A. Gatys, Matthias Bethge, Aaron Hertzmann, Eli Shechtman 10 | 11 | Additionally, techniques are presented for semantic segmentation and multiple style transfer. 12 | 13 | The Neural Style algorithm synthesizes a [pastiche](https://en.wikipedia.org/wiki/Pastiche) by separating and combining the content of one image with the style of another image using convolutional neural networks (CNN). Below is an example of transferring the artistic style of [The Starry Night](https://en.wikipedia.org/wiki/The_Starry_Night) onto a photograph of an African lion: 14 | 15 |

16 | 17 | 18 |

19 | 20 | Transferring the style of various artworks to the same content image produces qualitatively convincing results: 21 |

22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 |

37 | 38 | Here we reproduce Figure 3 from the first paper, which renders a photograph of the Neckarfront in Tübingen, Germany in the style of 5 different iconic paintings [The Shipwreck of the Minotaur](http://www.artble.com/artists/joseph_mallord_william_turner/paintings/the_shipwreck_of_the_minotaur), [The Starry Night](https://www.wikiart.org/en/vincent-van-gogh/the-starry-night-1889), [Composition VII](https://www.wikiart.org/en/wassily-kandinsky/composition-vii-1913), [The Scream](https://www.wikiart.org/en/edvard-munch/the-scream-1893), [Seated Nude](http://www.pablopicasso.org/seated-nude.jsp): 39 |

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |

48 | 49 | ### Content / Style Tradeoff 50 | The relative weight of the style and content can be controlled. 51 | 52 | Here we render with an increasing style weight applied to [Red Canna](http://www.georgiaokeeffe.net/red-canna.jsp): 53 |

54 | 55 | 56 | 57 | 58 | 59 |

60 | 61 | ### Multiple Style Images 62 | More than one style image can be used to blend multiple artistic styles. 63 | 64 |

65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |

73 | 74 | *Top row (left to right)*: [The Starry Night](https://www.wikiart.org/en/vincent-van-gogh/the-starry-night-1889) + [The Scream](https://www.wikiart.org/en/edvard-munch/the-scream-1893), [The Scream](https://www.wikiart.org/en/edvard-munch/the-scream-1893) + [Composition VII](https://www.wikiart.org/en/wassily-kandinsky/composition-vii-1913), [Seated Nude](http://www.pablopicasso.org/seated-nude.jsp) + [Composition VII](https://www.wikiart.org/en/wassily-kandinsky/composition-vii-1913) 75 | *Bottom row (left to right)*: [Seated Nude](http://www.pablopicasso.org/seated-nude.jsp) + [The Starry Night](https://www.wikiart.org/en/vincent-van-gogh/the-starry-night-1889), [Oversoul](http://alexgrey.com/art/paintings/soul/oversoul/) + [Freshness of Cold](https://afremov.com/FRESHNESS-OF-COLD-PALETTE-KNIFE-Oil-Painting-On-Canvas-By-Leonid-Afremov-Size-30-x40.html), [David Bowie](http://www.francoise-nielly.com/index.php/galerie/index/56) + [Skull](https://www.wikiart.org/en/jean-michel-basquiat/head) 76 | 77 | ### Style Interpolation 78 | When using multiple style images, the degree of blending between the images can be controlled. 79 | 80 |

81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 |

89 | 90 | *Top row (left to right)*: content image, .2 [The Starry Night](https://www.wikiart.org/en/vincent-van-gogh/the-starry-night-1889) + .8 [The Scream](https://www.wikiart.org/en/edvard-munch/the-scream-1893), .8 [The Starry Night](https://www.wikiart.org/en/vincent-van-gogh/the-starry-night-1889) + .2 [The Scream](https://www.wikiart.org/en/edvard-munch/the-scream-1893) 91 | *Bottom row (left to right)*: .2 [Oversoul](http://alexgrey.com/art/paintings/soul/oversoul/) + .8 [Freshness of Cold](https://afremov.com/FRESHNESS-OF-COLD-PALETTE-KNIFE-Oil-Painting-On-Canvas-By-Leonid-Afremov-Size-30-x40.html), .5 [Oversoul](http://alexgrey.com/art/paintings/soul/oversoul/) + .5 [Freshness of Cold](https://afremov.com/FRESHNESS-OF-COLD-PALETTE-KNIFE-Oil-Painting-On-Canvas-By-Leonid-Afremov-Size-30-x40.html), .8 [Oversoul](http://alexgrey.com/art/paintings/soul/oversoul/) + .2 [Freshness of Cold](https://afremov.com/FRESHNESS-OF-COLD-PALETTE-KNIFE-Oil-Painting-On-Canvas-By-Leonid-Afremov-Size-30-x40.html) 92 | 93 | ### Transfer style but not color 94 | The color scheme of the original image can be preserved by including the flag `--original_colors`. Colors are transferred using either the [YUV](https://en.wikipedia.org/wiki/YUV), [YCrCb](https://en.wikipedia.org/wiki/YCbCr), [CIE L\*a\*b\*](https://en.wikipedia.org/wiki/Lab_color_space), or [CIE L\*u\*v\*](https://en.wikipedia.org/wiki/CIELUV) color spaces. 95 | 96 | Here we reproduce Figure 1 and Figure 2 in the third paper using luminance-only transfer: 97 |

98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 |

106 | 107 | *Left to right*: content image, stylized image, stylized image with the original colors of the content image 108 | 109 | ### Textures 110 | The algorithm is not constrained to artistic painting styles. It can also be applied to photographic textures to create [pareidolic](https://en.wikipedia.org/wiki/Pareidolia) images. 111 |

112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |

122 | 123 | ### Segmentation 124 | Style can be transferred to semantic segmentations in the content image. 125 |

126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 |

140 | 141 | Multiple styles can be transferred to the foreground and background of the content image. 142 |

143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 |

157 | 158 | *Left to right*: content image, foreground style, background style, foreground mask, background mask, stylized image 159 | 160 | ### Video 161 | Animations can be rendered by applying the algorithm to each source frame. For the best results, the gradient descent is initialized with the previously stylized frame warped to the current frame according to the optical flow between the pair of frames. Loss functions for temporal consistency are used to penalize pixels excluding disoccluded regions and motion boundaries. 162 | 163 |

164 | 165 | 166 |
167 | 168 | 169 |

170 | 171 | *Top row (left to right)*: source frames, ground-truth optical flow visualized 172 | *Bottom row (left to right)*: disoccluded regions and motion boundaries, stylized frames 173 | 174 | Big thanks to Mike Burakoff for finding a bug in the video rendering. 175 | 176 | ### Gradient Descent Initialization 177 | The initialization of the gradient descent is controlled using `--init_img_type` for single images and `--init_frame_type` or `--first_frame_type` for video frames. White noise allows an arbitrary number of distinct images to be generated. Whereas, initializing with a fixed image always converges to the same output. 178 | 179 | Here we reproduce Figure 6 from the first paper: 180 |

181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 |

189 | 190 | *Top row (left to right)*: Initialized with the content image, the style image, white noise (RNG seed 1) 191 | *Bottom row (left to right)*: Initialized with white noise (RNG seeds 2, 3, 4) 192 | 193 | ### Layer Representations 194 | The feature complexities and receptive field sizes increase down the CNN heirarchy. 195 | 196 | Here we reproduce Figure 3 from [the original paper](https://arxiv.org/abs/1508.06576): 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 |
1 x 10^-51 x 10^-41 x 10^-31 x 10^-2
conv1_1
conv2_1
conv3_1
conv4_1
conv5_1
241 | 242 | *Rows*: increasing subsets of CNN layers; i.e. 'conv4_1' means using 'conv1_1', 'conv2_1', 'conv3_1', 'conv4_1'. 243 | *Columns*: alpha/beta ratio of the the content and style reconstruction (see Content / Style Tradeoff). 244 | 245 | ## Setup 246 | #### Dependencies: 247 | * [tensorflow](https://github.com/tensorflow/tensorflow) 248 | * [opencv](http://opencv.org/downloads.html) 249 | 250 | #### Optional (but recommended) dependencies: 251 | * [CUDA](https://developer.nvidia.com/cuda-downloads) 7.5+ 252 | * [cuDNN](https://developer.nvidia.com/cudnn) 5.0+ 253 | 254 | #### After installing the dependencies: 255 | * Download the [VGG-19 model weights](http://www.vlfeat.org/matconvnet/pretrained/) (see the "VGG-VD models from the *Very Deep Convolutional Networks for Large-Scale Visual Recognition* project" section). More info about the VGG-19 network can be found [here](http://www.robots.ox.ac.uk/~vgg/research/very_deep/). 256 | * After downloading, copy the weights file `imagenet-vgg-verydeep-19.mat` to the project directory. 257 | 258 | ## Usage 259 | ### Basic Usage 260 | 261 | #### Single Image 262 | 1. Copy 1 content image to the default image content directory `./image_input` 263 | 2. Copy 1 or more style images to the default style directory `./styles` 264 | 3. Run the command: 265 | ``` 266 | bash stylize_image.sh 267 | ``` 268 | *Example*: 269 | ``` 270 | bash stylize_image.sh ./image_input/lion.jpg ./styles/kandinsky.jpg 271 | ``` 272 | *Note*: Supported image formats include: `.png`, `.jpg`, `.ppm`, `.pgm` 273 | 274 | *Note*: Paths to images should not contain the `~` character to represent your home directory; you should instead use a relative path or the absolute path. 275 | 276 | #### Video Frames 277 | 1. Copy 1 content video to the default video content directory `./video_input` 278 | 2. Copy 1 or more style images to the default style directory `./styles` 279 | 3. Run the command: 280 | ``` 281 | bash stylize_video.sh 282 | ``` 283 | *Example*: 284 | ``` 285 | bash stylize_video.sh ./video_input/video.mp4 ./styles/kandinsky.jpg 286 | ``` 287 | 288 | *Note*: Supported video formats include: `.mp4`, `.mov`, `.mkv` 289 | 290 | ### Advanced Usage 291 | #### Single Image or Video Frames 292 | 1. Copy content images to the default image content directory `./image_input` or copy video frames to the default video content directory `./video_input` 293 | 2. Copy 1 or more style images to the default style directory `./styles` 294 | 3. Run the command with specific arguments: 295 | ``` 296 | python neural_style.py 297 | ``` 298 | *Example (Single Image)*: 299 | ``` 300 | python neural_style.py --content_img golden_gate.jpg \ 301 | --style_imgs starry-night.jpg \ 302 | --max_size 1000 \ 303 | --max_iterations 100 \ 304 | --original_colors \ 305 | --device /cpu:0 \ 306 | --verbose; 307 | ``` 308 | 309 | To use multiple style images, pass a *space-separated* list of the image names and image weights like this: 310 | 311 | `--style_imgs starry_night.jpg the_scream.jpg --style_imgs_weights 0.5 0.5` 312 | 313 | *Example (Video Frames)*: 314 | ``` 315 | python neural_style.py --video \ 316 | --video_input_dir ./video_input/my_video_frames \ 317 | --style_imgs starry-night.jpg \ 318 | --content_weight 5 \ 319 | --style_weight 1000 \ 320 | --temporal_weight 1000 \ 321 | --start_frame 1 \ 322 | --end_frame 50 \ 323 | --max_size 1024 \ 324 | --first_frame_iterations 3000 \ 325 | --verbose; 326 | ``` 327 | *Note*: When using `--init_frame_type prev_warp` you must have previously computed the backward and forward optical flow between the frames. See `./video_input/make-opt-flow.sh` and `./video_input/run-deepflow.sh` 328 | 329 | #### Arguments 330 | * `--content_img`: Filename of the content image. *Example*: `lion.jpg` 331 | * `--content_img_dir`: Relative or absolute directory path to the content image. *Default*: `./image_input` 332 | * `--style_imgs`: Filenames of the style images. To use multiple style images, pass a *space-separated* list. *Example*: `--style_imgs starry-night.jpg` 333 | * `--style_imgs_weights`: The blending weights for each style image. *Default*: `1.0` (assumes only 1 style image) 334 | * `--style_imgs_dir`: Relative or absolute directory path to the style images. *Default*: `./styles` 335 | * `--init_img_type`: Image used to initialize the network. *Choices*: `content`, `random`, `style`. *Default*: `content` 336 | * `--max_size`: Maximum width or height of the input images. *Default*: `512` 337 | * `--content_weight`: Weight for the content loss function. *Default*: `5e0` 338 | * `--style_weight`: Weight for the style loss function. *Default*: `1e4` 339 | * `--style_scale`: Scales style images (global for all style images) *Default*: `1.0` 340 | * `--tv_weight`: Weight for the total variational loss function. *Default*: `1e-3` 341 | * `--temporal_weight`: Weight for the temporal loss function. *Default*: `2e2` 342 | * `--content_layers`: *Space-separated* VGG-19 layer names used for the content image. *Default*: `conv4_2` 343 | * `--style_layers`: *Space-separated* VGG-19 layer names used for the style image. *Default*: `relu1_1 relu2_1 relu3_1 relu4_1 relu5_1` 344 | * `--content_layer_weights`: *Space-separated* weights of each content layer to the content loss. *Default*: `1.0` 345 | * `--style_layer_weights`: *Space-separated* weights of each style layer to loss. *Default*: `0.2 0.2 0.2 0.2 0.2` 346 | * `--original_colors`: Boolean flag indicating if the style is transferred but not the colors. 347 | * `--color_convert_type`: Color spaces (YUV, YCrCb, CIE L\*u\*v\*, CIE L\*a\*b\*) for luminance-matching conversion to original colors. *Choices*: `yuv`, `ycrcb`, `luv`, `lab`. *Default*: `yuv` 348 | * `--style_mask`: Boolean flag indicating if style is transferred to masked regions. 349 | * `--style_mask_imgs`: Filenames of the style mask images (example: `face_mask.png`). To use multiple style mask images, pass a *space-separated* list. *Example*: `--style_mask_imgs face_mask.png face_mask_inv.png` 350 | * `--noise_ratio`: Interpolation value between the content image and noise image if network is initialized with `random`. *Default*: `1.0` 351 | * `--seed`: Seed for the random number generator. *Default*: `0` 352 | * `--model_weights`: Weights and biases of the VGG-19 network. Download [here](http://www.vlfeat.org/matconvnet/pretrained/). *Default*:`imagenet-vgg-verydeep-19.mat` 353 | * `--pooling_type`: Type of pooling in convolutional neural network. *Choices*: `avg`, `max`. *Default*: `avg` 354 | * `--device`: GPU or CPU device. GPU mode highly recommended but requires NVIDIA CUDA. *Choices*: `/gpu:0` `/cpu:0`. *Default*: `/gpu:0` 355 | * `--img_output_dir`: Directory to write output to. *Default*: `./image_output` 356 | * `--img_name`: Filename of the output image. *Default*: `result` 357 | * `--verbose`: Boolean flag indicating if statements should be printed to the console. 358 | 359 | #### Optimization Arguments 360 | * `--optimizer`: Loss minimization optimizer. L-BFGS gives better results. Adam uses less memory. *Choices*: `lbfgs`, `adam`. *Default*: `lbfgs` 361 | * `--learning_rate`: Learning-rate parameter for the Adam optimizer. *Default*: `1e0` 362 | 363 |

364 | 365 |

366 | 367 | * `--max_iterations`: Max number of iterations for the Adam or L-BFGS optimizer. *Default*: `1000` 368 | * `--print_iterations`: Number of iterations between optimizer print statements. *Default*: `50` 369 | * `--content_loss_function`: Different constants K in the content loss function. *Choices*: `1`, `2`, `3`. *Default*: `1` 370 | 371 |

372 | 373 |

374 | 375 | #### Video Frame Arguments 376 | * `--video`: Boolean flag indicating if the user is creating a video. 377 | * `--start_frame`: First frame number. *Default*: `1` 378 | * `--end_frame`: Last frame number. *Default*: `1` 379 | * `--first_frame_type`: Image used to initialize the network during the rendering of the first frame. *Choices*: `content`, `random`, `style`. *Default*: `random` 380 | * `--init_frame_type`: Image used to initialize the network during the every rendering after the first frame. *Choices*: `prev_warped`, `prev`, `content`, `random`, `style`. *Default*: `prev_warped` 381 | * `--video_input_dir`: Relative or absolute directory path to input frames. *Default*: `./video_input` 382 | * `--video_output_dir`: Relative or absolute directory path to write output frames to. *Default*: `./video_output` 383 | * `--content_frame_frmt`: Format string of input frames. *Default*: `frame_{}.png` 384 | * `--backward_optical_flow_frmt`: Format string of backward optical flow files. *Default*: `backward_{}_{}.flo` 385 | * `--forward_optical_flow_frmt`: Format string of forward optical flow files. *Default*: `forward_{}_{}.flo` 386 | * `--content_weights_frmt`: Format string of optical flow consistency files. *Default*: `reliable_{}_{}.txt` 387 | * `--prev_frame_indices`: Previous frames to consider for longterm temporal consistency. *Default*: `1` 388 | * `--first_frame_iterations`: Maximum number of optimizer iterations of the first frame. *Default*: `2000` 389 | * `--frame_iterations`: Maximum number of optimizer iterations for each frame after the first frame. *Default*: `800` 390 | 391 | ## Questions and Errata 392 | 393 | Send questions or issues: 394 | 395 | 396 | ## Memory 397 | By default, `neural-style-tf` uses the NVIDIA cuDNN GPU backend for convolutions and L-BFGS for optimization. 398 | These produce better and faster results, but can consume a lot of memory. You can reduce memory usage with the following: 399 | 400 | * **Use Adam**: Add the flag `--optimizer adam` to use Adam instead of L-BFGS. This should significantly 401 | reduce memory usage, but will require tuning of other parameters for good results; in particular you should 402 | experiment with different values of `--learning_rate`, `--content_weight`, `--style_weight` 403 | * **Reduce image size**: You can reduce the size of the generated image with the `--max_size` argument. 404 | 405 | ## Implementation Details 406 | All images were rendered on a machine with: 407 | * **CPU:** Intel Core i7-6800K @ 3.40GHz × 12 408 | * **GPU:** NVIDIA GeForce GTX 1080/PCIe/SSE2 409 | * **OS:** Linux Ubuntu 16.04.1 LTS 64-bit 410 | * **CUDA:** 8.0 411 | * **python:** 2.7.12 412 | * **tensorflow:** 0.10.0rc 413 | * **opencv:** 2.4.9.1 414 | 415 | ## Acknowledgements 416 | 417 | The implementation is based on the projects: 418 | * Torch (Lua) implementation 'neural-style' by [jcjohnson](https://github.com/jcjohnson) 419 | * Torch (Lua) implementation 'artistic-videos' by [manuelruder](https://github.com/manuelruder) 420 | 421 | Source video frames were obtained from: 422 | * [MPI Sintel Flow Dataset](http://sintel.is.tue.mpg.de/) 423 | 424 | Artistic images were created by the modern artists: 425 | * [Alex Grey](http://alexgrey.com/) 426 | * [Minjae Lee](http://www.grenomj.com/) 427 | * [Leonid Afremov](https://afremov.com/) 428 | * [Françoise Nielly](http://www.francoise-nielly.com/) 429 | * [James Jean](http://www.jamesjean.com/) 430 | * [Ben Giles](https://benlewisgiles.format.com/) 431 | * [Callie Fink](http://calliefink.deviantart.com/) 432 | * [H.R. Giger](https://en.wikipedia.org/wiki/H._R._Giger) 433 | * [Voka](http://www.voka.at/) 434 | 435 | Artistic images were created by the popular historical artists: 436 | * [Vincent Van Gogh](https://www.wikiart.org/en/vincent-van-gogh) 437 | * [Wassily Kandinsky](https://www.wikiart.org/en/wassily-kandinsky) 438 | * [Georgia O'Keeffe](http://www.georgiaokeeffe.net/) 439 | * [Jean-Michel Basquiat](http://basquiat.com/) 440 | * [Édouard Manet](http://www.manet.org/) 441 | * [Pablo Picasso](https://www.wikiart.org/en/pablo-picasso) 442 | * [Joseph Mallord William Turner](https://en.wikipedia.org/wiki/J._M._W._Turner) 443 | * [Frida Kahlo](https://en.wikipedia.org/wiki/Frida_Kahlo) 444 | 445 | Bash shell scripts for testing were created by my brother [Sheldon Smith](http://www.imdb.com/name/nm4328496/). 446 | 447 | ## Citation 448 | 449 | If you find this code useful for your research, please cite: 450 | 451 | ``` 452 | @misc{Smith2016, 453 | author = {Smith, Cameron}, 454 | title = {neural-style-tf}, 455 | year = {2016}, 456 | publisher = {GitHub}, 457 | journal = {GitHub repository}, 458 | howpublished = {\url{https://github.com/cysmith/neural-style-tf}}, 459 | } 460 | ``` 461 | -------------------------------------------------------------------------------- /examples/equations/content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/equations/content.png -------------------------------------------------------------------------------- /examples/equations/email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/equations/email.png -------------------------------------------------------------------------------- /examples/equations/plot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/equations/plot.png -------------------------------------------------------------------------------- /examples/gatys_figure/tubingen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/gatys_figure/tubingen.png -------------------------------------------------------------------------------- /examples/gatys_figure/tubingen_kandinsky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/gatys_figure/tubingen_kandinsky.png -------------------------------------------------------------------------------- /examples/gatys_figure/tubingen_picasso.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/gatys_figure/tubingen_picasso.png -------------------------------------------------------------------------------- /examples/gatys_figure/tubingen_scream.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/gatys_figure/tubingen_scream.png -------------------------------------------------------------------------------- /examples/gatys_figure/tubingen_shipwreck.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/gatys_figure/tubingen_shipwreck.png -------------------------------------------------------------------------------- /examples/gatys_figure/tubingen_starry_night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/gatys_figure/tubingen_starry_night.png -------------------------------------------------------------------------------- /examples/initialization/init_content.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_content.png -------------------------------------------------------------------------------- /examples/initialization/init_random_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_random_0.png -------------------------------------------------------------------------------- /examples/initialization/init_random_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_random_1.png -------------------------------------------------------------------------------- /examples/initialization/init_random_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_random_2.png -------------------------------------------------------------------------------- /examples/initialization/init_random_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_random_3.png -------------------------------------------------------------------------------- /examples/initialization/init_random_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_random_4.png -------------------------------------------------------------------------------- /examples/initialization/init_style.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/initialization/init_style.png -------------------------------------------------------------------------------- /examples/layers/conv1_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv1_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/conv1_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv1_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/conv1_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv1_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/conv1_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv1_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/conv2_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv2_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/conv2_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv2_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/conv2_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv2_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/conv2_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv2_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/conv3_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv3_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/conv3_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv3_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/conv3_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv3_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/conv3_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv3_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/conv4_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv4_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/conv4_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv4_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/conv4_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv4_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/conv4_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv4_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/conv5_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv5_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/conv5_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv5_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/conv5_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv5_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/conv5_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/conv5_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/relu1_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu1_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/relu1_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu1_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/relu1_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu1_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/relu1_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu1_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/relu2_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu2_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/relu2_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu2_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/relu2_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu2_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/relu2_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu2_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/relu3_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu3_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/relu3_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu3_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/relu3_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu3_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/relu3_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu3_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/relu4_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu4_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/relu4_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu4_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/relu4_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu4_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/relu4_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu4_1_1e5.png -------------------------------------------------------------------------------- /examples/layers/relu5_1_1e2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu5_1_1e2.png -------------------------------------------------------------------------------- /examples/layers/relu5_1_1e3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu5_1_1e3.png -------------------------------------------------------------------------------- /examples/layers/relu5_1_1e4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu5_1_1e4.png -------------------------------------------------------------------------------- /examples/layers/relu5_1_1e5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/layers/relu5_1_1e5.png -------------------------------------------------------------------------------- /examples/lions/32_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/32_output.png -------------------------------------------------------------------------------- /examples/lions/33_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/33_output.png -------------------------------------------------------------------------------- /examples/lions/42_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/42_output.png -------------------------------------------------------------------------------- /examples/lions/basquiat_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/basquiat_output.png -------------------------------------------------------------------------------- /examples/lions/calliefink_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/calliefink_output.png -------------------------------------------------------------------------------- /examples/lions/content_style.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/content_style.png -------------------------------------------------------------------------------- /examples/lions/giger_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/giger_output.png -------------------------------------------------------------------------------- /examples/lions/kandinsky_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/kandinsky_output.png -------------------------------------------------------------------------------- /examples/lions/styles/basquiat_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/basquiat_crop.jpg -------------------------------------------------------------------------------- /examples/lions/styles/calliefink_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/calliefink_crop.jpg -------------------------------------------------------------------------------- /examples/lions/styles/giger_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/giger_crop.jpg -------------------------------------------------------------------------------- /examples/lions/styles/kandinsky_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/kandinsky_crop.jpg -------------------------------------------------------------------------------- /examples/lions/styles/matisse_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/matisse_crop.jpg -------------------------------------------------------------------------------- /examples/lions/styles/water_lilies_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/water_lilies_crop.jpg -------------------------------------------------------------------------------- /examples/lions/styles/wave_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/styles/wave_crop.jpg -------------------------------------------------------------------------------- /examples/lions/wave_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/lions/wave_output.png -------------------------------------------------------------------------------- /examples/multiple_styles/tubingen_afremov_grey.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/multiple_styles/tubingen_afremov_grey.png -------------------------------------------------------------------------------- /examples/multiple_styles/tubingen_basquiat_nielly.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/multiple_styles/tubingen_basquiat_nielly.png -------------------------------------------------------------------------------- /examples/multiple_styles/tubingen_scream_kandinsky.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/multiple_styles/tubingen_scream_kandinsky.png -------------------------------------------------------------------------------- /examples/multiple_styles/tubingen_seated_kandinsky.png.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/multiple_styles/tubingen_seated_kandinsky.png.png -------------------------------------------------------------------------------- /examples/multiple_styles/tubingen_starry_scream.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/multiple_styles/tubingen_starry_scream.png -------------------------------------------------------------------------------- /examples/multiple_styles/tubingen_starry_seated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/multiple_styles/tubingen_starry_seated.png -------------------------------------------------------------------------------- /examples/original_colors/garden.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/original_colors/garden.png -------------------------------------------------------------------------------- /examples/original_colors/garden_starry.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/original_colors/garden_starry.png -------------------------------------------------------------------------------- /examples/original_colors/garden_starry_yuv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/original_colors/garden_starry_yuv.png -------------------------------------------------------------------------------- /examples/original_colors/new_york.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/original_colors/new_york.png -------------------------------------------------------------------------------- /examples/original_colors/stylized.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/original_colors/stylized.png -------------------------------------------------------------------------------- /examples/original_colors/stylized_original_colors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/original_colors/stylized_original_colors.png -------------------------------------------------------------------------------- /examples/pareidolic/ben_giles_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/ben_giles_output.png -------------------------------------------------------------------------------- /examples/pareidolic/dark_matter_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/dark_matter_output.png -------------------------------------------------------------------------------- /examples/pareidolic/flowers_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/flowers_output.png -------------------------------------------------------------------------------- /examples/pareidolic/oil_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/oil_output.png -------------------------------------------------------------------------------- /examples/pareidolic/styles/ben_giles.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/styles/ben_giles.png -------------------------------------------------------------------------------- /examples/pareidolic/styles/dark_matter_bw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/styles/dark_matter_bw.png -------------------------------------------------------------------------------- /examples/pareidolic/styles/flowers_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/styles/flowers_crop.jpg -------------------------------------------------------------------------------- /examples/pareidolic/styles/oil_crop.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/pareidolic/styles/oil_crop.jpg -------------------------------------------------------------------------------- /examples/segmentation/00017.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00017.jpg -------------------------------------------------------------------------------- /examples/segmentation/00017_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00017_mask.png -------------------------------------------------------------------------------- /examples/segmentation/00017_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00017_output.png -------------------------------------------------------------------------------- /examples/segmentation/00110.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00110.jpg -------------------------------------------------------------------------------- /examples/segmentation/00110_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00110_mask.png -------------------------------------------------------------------------------- /examples/segmentation/00110_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00110_output.png -------------------------------------------------------------------------------- /examples/segmentation/00768.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00768.jpg -------------------------------------------------------------------------------- /examples/segmentation/00768_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00768_mask.png -------------------------------------------------------------------------------- /examples/segmentation/00768_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/00768_output.png -------------------------------------------------------------------------------- /examples/segmentation/02270.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02270.jpg -------------------------------------------------------------------------------- /examples/segmentation/02270_mask_face.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02270_mask_face.png -------------------------------------------------------------------------------- /examples/segmentation/02270_mask_face_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02270_mask_face_inv.png -------------------------------------------------------------------------------- /examples/segmentation/02270_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02270_output.png -------------------------------------------------------------------------------- /examples/segmentation/02390.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02390.jpg -------------------------------------------------------------------------------- /examples/segmentation/02390_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02390_mask.png -------------------------------------------------------------------------------- /examples/segmentation/02390_mask_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02390_mask_inv.png -------------------------------------------------------------------------------- /examples/segmentation/02390_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02390_output.png -------------------------------------------------------------------------------- /examples/segmentation/02630.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02630.png -------------------------------------------------------------------------------- /examples/segmentation/02630_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02630_mask.png -------------------------------------------------------------------------------- /examples/segmentation/02630_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/02630_output.png -------------------------------------------------------------------------------- /examples/segmentation/basquiat.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/basquiat.png -------------------------------------------------------------------------------- /examples/segmentation/frida.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/frida.png -------------------------------------------------------------------------------- /examples/segmentation/okeffe_iris.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/okeffe_iris.png -------------------------------------------------------------------------------- /examples/segmentation/okeffe_red_canna.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/segmentation/okeffe_red_canna.png -------------------------------------------------------------------------------- /examples/style_content_tradeoff/okeffe.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/okeffe.jpg -------------------------------------------------------------------------------- /examples/style_content_tradeoff/okeffe_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/okeffe_10.png -------------------------------------------------------------------------------- /examples/style_content_tradeoff/okeffe_100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/okeffe_100.png -------------------------------------------------------------------------------- /examples/style_content_tradeoff/okeffe_1000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/okeffe_1000.png -------------------------------------------------------------------------------- /examples/style_content_tradeoff/okeffe_10000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/okeffe_10000.png -------------------------------------------------------------------------------- /examples/style_content_tradeoff/output_100000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/output_100000.png -------------------------------------------------------------------------------- /examples/style_content_tradeoff/output_1000000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_content_tradeoff/output_1000000.png -------------------------------------------------------------------------------- /examples/style_interpolation/golden_gate_scream_3_starry_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/golden_gate_scream_3_starry_7.png -------------------------------------------------------------------------------- /examples/style_interpolation/golden_gate_scream_5_starry_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/golden_gate_scream_5_starry_5.png -------------------------------------------------------------------------------- /examples/style_interpolation/golden_gate_scream_7_starry_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/golden_gate_scream_7_starry_3.png -------------------------------------------------------------------------------- /examples/style_interpolation/taj_mahal_afremov_grey_2_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/taj_mahal_afremov_grey_2_8.png -------------------------------------------------------------------------------- /examples/style_interpolation/taj_mahal_afremov_grey_5_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/taj_mahal_afremov_grey_5_5.png -------------------------------------------------------------------------------- /examples/style_interpolation/taj_mahal_afremov_grey_8_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/taj_mahal_afremov_grey_8_2.png -------------------------------------------------------------------------------- /examples/style_interpolation/taj_mahal_scream_2_starry_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/taj_mahal_scream_2_starry_8.png -------------------------------------------------------------------------------- /examples/style_interpolation/taj_mahal_scream_5_starry_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/taj_mahal_scream_5_starry_5.png -------------------------------------------------------------------------------- /examples/style_interpolation/taj_mahal_scream_8_starry_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/style_interpolation/taj_mahal_scream_8_starry_2.png -------------------------------------------------------------------------------- /examples/video/input.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/video/input.gif -------------------------------------------------------------------------------- /examples/video/opt_flow.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/video/opt_flow.gif -------------------------------------------------------------------------------- /examples/video/output.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/video/output.gif -------------------------------------------------------------------------------- /examples/video/weights.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/examples/video/weights.gif -------------------------------------------------------------------------------- /image_input/face.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/face.jpg -------------------------------------------------------------------------------- /image_input/face_mask.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/face_mask.png -------------------------------------------------------------------------------- /image_input/face_mask_inv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/face_mask_inv.png -------------------------------------------------------------------------------- /image_input/golden_gate.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/golden_gate.jpg -------------------------------------------------------------------------------- /image_input/lion.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/lion.jpg -------------------------------------------------------------------------------- /image_input/taj_mahal.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/taj_mahal.jpg -------------------------------------------------------------------------------- /image_input/tubingen.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/image_input/tubingen.jpg -------------------------------------------------------------------------------- /neural_style.py: -------------------------------------------------------------------------------- 1 | import tensorflow as tf 2 | import numpy as np 3 | import scipy.io 4 | import argparse 5 | import struct 6 | import errno 7 | import time 8 | import cv2 9 | import os 10 | 11 | ''' 12 | parsing and configuration 13 | ''' 14 | def parse_args(): 15 | 16 | desc = "TensorFlow implementation of 'A Neural Algorithm for Artistic Style'" 17 | parser = argparse.ArgumentParser(description=desc) 18 | 19 | # options for single image 20 | parser.add_argument('--verbose', action='store_true', 21 | help='Boolean flag indicating if statements should be printed to the console.') 22 | 23 | parser.add_argument('--img_name', type=str, 24 | default='result', 25 | help='Filename of the output image.') 26 | 27 | parser.add_argument('--style_imgs', nargs='+', type=str, 28 | help='Filenames of the style images (example: starry-night.jpg)', 29 | required=True) 30 | 31 | parser.add_argument('--style_imgs_weights', nargs='+', type=float, 32 | default=[1.0], 33 | help='Interpolation weights of each of the style images. (example: 0.5 0.5)') 34 | 35 | parser.add_argument('--content_img', type=str, 36 | help='Filename of the content image (example: lion.jpg)') 37 | 38 | parser.add_argument('--style_imgs_dir', type=str, 39 | default='./styles', 40 | help='Directory path to the style images. (default: %(default)s)') 41 | 42 | parser.add_argument('--content_img_dir', type=str, 43 | default='./image_input', 44 | help='Directory path to the content image. (default: %(default)s)') 45 | 46 | parser.add_argument('--init_img_type', type=str, 47 | default='content', 48 | choices=['random', 'content', 'style'], 49 | help='Image used to initialize the network. (default: %(default)s)') 50 | 51 | parser.add_argument('--max_size', type=int, 52 | default=512, 53 | help='Maximum width or height of the input images. (default: %(default)s)') 54 | 55 | parser.add_argument('--content_weight', type=float, 56 | default=5e0, 57 | help='Weight for the content loss function. (default: %(default)s)') 58 | 59 | parser.add_argument('--style_weight', type=float, 60 | default=1e4, 61 | help='Weight for the style loss function. (default: %(default)s)') 62 | 63 | parser.add_argument('--tv_weight', type=float, 64 | default=1e-3, 65 | help='Weight for the total variational loss function. Set small (e.g. 1e-3). (default: %(default)s)') 66 | 67 | parser.add_argument('--temporal_weight', type=float, 68 | default=2e2, 69 | help='Weight for the temporal loss function. (default: %(default)s)') 70 | 71 | parser.add_argument('--content_loss_function', type=int, 72 | default=1, 73 | choices=[1, 2, 3], 74 | help='Different constants for the content layer loss function. (default: %(default)s)') 75 | 76 | parser.add_argument('--content_layers', nargs='+', type=str, 77 | default=['conv4_2'], 78 | help='VGG19 layers used for the content image. (default: %(default)s)') 79 | 80 | parser.add_argument('--style_layers', nargs='+', type=str, 81 | default=['relu1_1', 'relu2_1', 'relu3_1', 'relu4_1', 'relu5_1'], 82 | help='VGG19 layers used for the style image. (default: %(default)s)') 83 | 84 | parser.add_argument('--style_scale', type=float, 85 | default=1.0, 86 | help='scale the of style image. (default: %(default)s)') 87 | 88 | parser.add_argument('--content_layer_weights', nargs='+', type=float, 89 | default=[1.0], 90 | help='Contributions (weights) of each content layer to loss. (default: %(default)s)') 91 | 92 | parser.add_argument('--style_layer_weights', nargs='+', type=float, 93 | default=[0.2, 0.2, 0.2, 0.2, 0.2], 94 | help='Contributions (weights) of each style layer to loss. (default: %(default)s)') 95 | 96 | parser.add_argument('--original_colors', action='store_true', 97 | help='Transfer the style but not the colors.') 98 | 99 | parser.add_argument('--color_convert_type', type=str, 100 | default='yuv', 101 | choices=['yuv', 'ycrcb', 'luv', 'lab'], 102 | help='Color space for conversion to original colors (default: %(default)s)') 103 | 104 | parser.add_argument('--color_convert_time', type=str, 105 | default='after', 106 | choices=['after', 'before'], 107 | help='Time (before or after) to convert to original colors (default: %(default)s)') 108 | 109 | parser.add_argument('--style_mask', action='store_true', 110 | help='Transfer the style to masked regions.') 111 | 112 | parser.add_argument('--style_mask_imgs', nargs='+', type=str, 113 | default=None, 114 | help='Filenames of the style mask images (example: face_mask.png) (default: %(default)s)') 115 | 116 | parser.add_argument('--noise_ratio', type=float, 117 | default=1.0, 118 | help="Interpolation value between the content image and noise image if the network is initialized with 'random'.") 119 | 120 | parser.add_argument('--seed', type=int, 121 | default=0, 122 | help='Seed for the random number generator. (default: %(default)s)') 123 | 124 | parser.add_argument('--model_weights', type=str, 125 | default='imagenet-vgg-verydeep-19.mat', 126 | help='Weights and biases of the VGG-19 network.') 127 | 128 | parser.add_argument('--pooling_type', type=str, 129 | default='avg', 130 | choices=['avg', 'max'], 131 | help='Type of pooling in convolutional neural network. (default: %(default)s)') 132 | 133 | parser.add_argument('--device', type=str, 134 | default='/gpu:0', 135 | choices=['/gpu:0', '/cpu:0'], 136 | help='GPU or CPU mode. GPU mode requires NVIDIA CUDA. (default|recommended: %(default)s)') 137 | 138 | parser.add_argument('--img_output_dir', type=str, 139 | default='./image_output', 140 | help='Relative or absolute directory path to output image and data.') 141 | 142 | # optimizations 143 | parser.add_argument('--optimizer', type=str, 144 | default='lbfgs', 145 | choices=['lbfgs', 'adam'], 146 | help='Loss minimization optimizer. L-BFGS gives better results. Adam uses less memory. (default|recommended: %(default)s)') 147 | 148 | parser.add_argument('--learning_rate', type=float, 149 | default=1e0, 150 | help='Learning rate parameter for the Adam optimizer. (default: %(default)s)') 151 | 152 | parser.add_argument('--max_iterations', type=int, 153 | default=1000, 154 | help='Max number of iterations for the Adam or L-BFGS optimizer. (default: %(default)s)') 155 | 156 | parser.add_argument('--print_iterations', type=int, 157 | default=50, 158 | help='Number of iterations between optimizer print statements. (default: %(default)s)') 159 | 160 | # options for video frames 161 | parser.add_argument('--video', action='store_true', 162 | help='Boolean flag indicating if the user is generating a video.') 163 | 164 | parser.add_argument('--start_frame', type=int, 165 | default=1, 166 | help='First frame number.') 167 | 168 | parser.add_argument('--end_frame', type=int, 169 | default=1, 170 | help='Last frame number.') 171 | 172 | parser.add_argument('--first_frame_type', type=str, 173 | choices=['random', 'content', 'style'], 174 | default='content', 175 | help='Image used to initialize the network during the rendering of the first frame.') 176 | 177 | parser.add_argument('--init_frame_type', type=str, 178 | choices=['prev_warped', 'prev', 'random', 'content', 'style'], 179 | default='prev_warped', 180 | help='Image used to initialize the network during the every rendering after the first frame.') 181 | 182 | parser.add_argument('--video_input_dir', type=str, 183 | default='./video_input', 184 | help='Relative or absolute directory path to input frames.') 185 | 186 | parser.add_argument('--video_output_dir', type=str, 187 | default='./video_output', 188 | help='Relative or absolute directory path to output frames.') 189 | 190 | parser.add_argument('--content_frame_frmt', type=str, 191 | default='frame_{}.ppm', 192 | help='Filename format of the input content frames.') 193 | 194 | parser.add_argument('--zfill', type=str, 195 | default=4, 196 | help='digits in frame count') 197 | 198 | parser.add_argument('--backward_optical_flow_frmt', type=str, 199 | default='backward_{}_{}.flo', 200 | help='Filename format of the backward optical flow files.') 201 | 202 | parser.add_argument('--forward_optical_flow_frmt', type=str, 203 | default='forward_{}_{}.flo', 204 | help='Filename format of the forward optical flow files') 205 | 206 | parser.add_argument('--content_weights_frmt', type=str, 207 | default='reliable_{}_{}.txt', 208 | help='Filename format of the optical flow consistency files.') 209 | 210 | parser.add_argument('--prev_frame_indices', nargs='+', type=int, 211 | default=[1], 212 | help='Previous frames to consider for longterm temporal consistency.') 213 | 214 | parser.add_argument('--first_frame_iterations', type=int, 215 | default=2000, 216 | help='Maximum number of optimizer iterations of the first frame. (default: %(default)s)') 217 | 218 | parser.add_argument('--frame_iterations', type=int, 219 | default=800, 220 | help='Maximum number of optimizer iterations for each frame after the first frame. (default: %(default)s)') 221 | 222 | args = parser.parse_args() 223 | 224 | # normalize weights 225 | args.style_layer_weights = normalize(args.style_layer_weights) 226 | args.content_layer_weights = normalize(args.content_layer_weights) 227 | args.style_imgs_weights = normalize(args.style_imgs_weights) 228 | 229 | # create directories for output 230 | if args.video: 231 | maybe_make_directory(args.video_output_dir) 232 | else: 233 | maybe_make_directory(args.img_output_dir) 234 | 235 | return args 236 | 237 | ''' 238 | pre-trained vgg19 convolutional neural network 239 | remark: layers are manually initialized for clarity. 240 | ''' 241 | 242 | def build_model(input_img): 243 | if args.verbose: print('\nBUILDING VGG-19 NETWORK') 244 | net = {} 245 | _, h, w, d = input_img.shape 246 | 247 | if args.verbose: print('loading model weights...') 248 | vgg_rawnet = scipy.io.loadmat(args.model_weights) 249 | vgg_layers = vgg_rawnet['layers'][0] 250 | if args.verbose: print('constructing layers...') 251 | net['input'] = tf.Variable(np.zeros((1, h, w, d), dtype=np.float32)) 252 | 253 | if args.verbose: print('LAYER GROUP 1') 254 | net['conv1_1'] = conv_layer('conv1_1', net['input'], W=get_weights(vgg_layers, 0)) 255 | net['relu1_1'] = relu_layer('relu1_1', net['conv1_1'], b=get_bias(vgg_layers, 0)) 256 | 257 | net['conv1_2'] = conv_layer('conv1_2', net['relu1_1'], W=get_weights(vgg_layers, 2)) 258 | net['relu1_2'] = relu_layer('relu1_2', net['conv1_2'], b=get_bias(vgg_layers, 2)) 259 | 260 | net['pool1'] = pool_layer('pool1', net['relu1_2']) 261 | 262 | if args.verbose: print('LAYER GROUP 2') 263 | net['conv2_1'] = conv_layer('conv2_1', net['pool1'], W=get_weights(vgg_layers, 5)) 264 | net['relu2_1'] = relu_layer('relu2_1', net['conv2_1'], b=get_bias(vgg_layers, 5)) 265 | 266 | net['conv2_2'] = conv_layer('conv2_2', net['relu2_1'], W=get_weights(vgg_layers, 7)) 267 | net['relu2_2'] = relu_layer('relu2_2', net['conv2_2'], b=get_bias(vgg_layers, 7)) 268 | 269 | net['pool2'] = pool_layer('pool2', net['relu2_2']) 270 | 271 | if args.verbose: print('LAYER GROUP 3') 272 | net['conv3_1'] = conv_layer('conv3_1', net['pool2'], W=get_weights(vgg_layers, 10)) 273 | net['relu3_1'] = relu_layer('relu3_1', net['conv3_1'], b=get_bias(vgg_layers, 10)) 274 | 275 | net['conv3_2'] = conv_layer('conv3_2', net['relu3_1'], W=get_weights(vgg_layers, 12)) 276 | net['relu3_2'] = relu_layer('relu3_2', net['conv3_2'], b=get_bias(vgg_layers, 12)) 277 | 278 | net['conv3_3'] = conv_layer('conv3_3', net['relu3_2'], W=get_weights(vgg_layers, 14)) 279 | net['relu3_3'] = relu_layer('relu3_3', net['conv3_3'], b=get_bias(vgg_layers, 14)) 280 | 281 | net['conv3_4'] = conv_layer('conv3_4', net['relu3_3'], W=get_weights(vgg_layers, 16)) 282 | net['relu3_4'] = relu_layer('relu3_4', net['conv3_4'], b=get_bias(vgg_layers, 16)) 283 | 284 | net['pool3'] = pool_layer('pool3', net['relu3_4']) 285 | 286 | if args.verbose: print('LAYER GROUP 4') 287 | net['conv4_1'] = conv_layer('conv4_1', net['pool3'], W=get_weights(vgg_layers, 19)) 288 | net['relu4_1'] = relu_layer('relu4_1', net['conv4_1'], b=get_bias(vgg_layers, 19)) 289 | 290 | net['conv4_2'] = conv_layer('conv4_2', net['relu4_1'], W=get_weights(vgg_layers, 21)) 291 | net['relu4_2'] = relu_layer('relu4_2', net['conv4_2'], b=get_bias(vgg_layers, 21)) 292 | 293 | net['conv4_3'] = conv_layer('conv4_3', net['relu4_2'], W=get_weights(vgg_layers, 23)) 294 | net['relu4_3'] = relu_layer('relu4_3', net['conv4_3'], b=get_bias(vgg_layers, 23)) 295 | 296 | net['conv4_4'] = conv_layer('conv4_4', net['relu4_3'], W=get_weights(vgg_layers, 25)) 297 | net['relu4_4'] = relu_layer('relu4_4', net['conv4_4'], b=get_bias(vgg_layers, 25)) 298 | 299 | net['pool4'] = pool_layer('pool4', net['relu4_4']) 300 | 301 | if args.verbose: print('LAYER GROUP 5') 302 | net['conv5_1'] = conv_layer('conv5_1', net['pool4'], W=get_weights(vgg_layers, 28)) 303 | net['relu5_1'] = relu_layer('relu5_1', net['conv5_1'], b=get_bias(vgg_layers, 28)) 304 | 305 | net['conv5_2'] = conv_layer('conv5_2', net['relu5_1'], W=get_weights(vgg_layers, 30)) 306 | net['relu5_2'] = relu_layer('relu5_2', net['conv5_2'], b=get_bias(vgg_layers, 30)) 307 | 308 | net['conv5_3'] = conv_layer('conv5_3', net['relu5_2'], W=get_weights(vgg_layers, 32)) 309 | net['relu5_3'] = relu_layer('relu5_3', net['conv5_3'], b=get_bias(vgg_layers, 32)) 310 | 311 | net['conv5_4'] = conv_layer('conv5_4', net['relu5_3'], W=get_weights(vgg_layers, 34)) 312 | net['relu5_4'] = relu_layer('relu5_4', net['conv5_4'], b=get_bias(vgg_layers, 34)) 313 | 314 | net['pool5'] = pool_layer('pool5', net['relu5_4']) 315 | 316 | return net 317 | 318 | def conv_layer(layer_name, layer_input, W): 319 | conv = tf.nn.conv2d(layer_input, W, strides=[1, 1, 1, 1], padding='SAME') 320 | if args.verbose: print('--{} | shape={} | weights_shape={}'.format(layer_name, 321 | conv.get_shape(), W.get_shape())) 322 | return conv 323 | 324 | def relu_layer(layer_name, layer_input, b): 325 | relu = tf.nn.relu(layer_input + b) 326 | if args.verbose: 327 | print('--{} | shape={} | bias_shape={}'.format(layer_name, relu.get_shape(), 328 | b.get_shape())) 329 | return relu 330 | 331 | def pool_layer(layer_name, layer_input): 332 | if args.pooling_type == 'avg': 333 | pool = tf.nn.avg_pool(layer_input, ksize=[1, 2, 2, 1], 334 | strides=[1, 2, 2, 1], padding='SAME') 335 | elif args.pooling_type == 'max': 336 | pool = tf.nn.max_pool(layer_input, ksize=[1, 2, 2, 1], 337 | strides=[1, 2, 2, 1], padding='SAME') 338 | if args.verbose: 339 | print('--{} | shape={}'.format(layer_name, pool.get_shape())) 340 | return pool 341 | 342 | def get_weights(vgg_layers, i): 343 | weights = vgg_layers[i][0][0][2][0][0] 344 | W = tf.constant(weights) 345 | return W 346 | 347 | def get_bias(vgg_layers, i): 348 | bias = vgg_layers[i][0][0][2][0][1] 349 | b = tf.constant(np.reshape(bias, (bias.size))) 350 | return b 351 | 352 | ''' 353 | 'a neural algorithm for artistic style' loss functions 354 | ''' 355 | def content_layer_loss(p, x): 356 | _, h, w, d = p.get_shape() 357 | M = h.value * w.value 358 | N = d.value 359 | if args.content_loss_function == 1: 360 | K = 1. / (2. * N**0.5 * M**0.5) 361 | elif args.content_loss_function == 2: 362 | K = 1. / (N * M) 363 | elif args.content_loss_function == 3: 364 | K = 1. / 2. 365 | loss = K * tf.reduce_sum(tf.pow((x - p), 2)) 366 | return loss 367 | 368 | def style_layer_loss(a, x): 369 | _, h, w, d = a.get_shape() 370 | M = h.value * w.value 371 | N = d.value 372 | A = gram_matrix(a, M, N) 373 | G = gram_matrix(x, M, N) 374 | loss = (1./(4 * N**2 * M**2)) * tf.reduce_sum(tf.pow((G - A), 2)) 375 | return loss 376 | 377 | def gram_matrix(x, area, depth): 378 | F = tf.reshape(x, (area, depth)) 379 | G = tf.matmul(tf.transpose(F), F) 380 | return G 381 | 382 | def mask_style_layer(a, x, mask_img): 383 | _, h, w, d = a.get_shape() 384 | mask = get_mask_image(mask_img, w.value, h.value) 385 | mask = tf.convert_to_tensor(mask) 386 | tensors = [] 387 | for _ in range(d.value): 388 | tensors.append(mask) 389 | mask = tf.stack(tensors, axis=2) 390 | mask = tf.stack(mask, axis=0) 391 | mask = tf.expand_dims(mask, 0) 392 | a = tf.multiply(a, mask) 393 | x = tf.multiply(x, mask) 394 | return a, x 395 | 396 | def sum_masked_style_losses(sess, net, style_imgs): 397 | total_style_loss = 0. 398 | weights = args.style_imgs_weights 399 | masks = args.style_mask_imgs 400 | for img, img_weight, img_mask in zip(style_imgs, weights, masks): 401 | sess.run(net['input'].assign(img)) 402 | style_loss = 0. 403 | for layer, weight in zip(args.style_layers, args.style_layer_weights): 404 | a = sess.run(net[layer]) 405 | x = net[layer] 406 | a = tf.convert_to_tensor(a) 407 | a, x = mask_style_layer(a, x, img_mask) 408 | style_loss += style_layer_loss(a, x) * weight 409 | style_loss /= float(len(args.style_layers)) 410 | total_style_loss += (style_loss * img_weight) 411 | total_style_loss /= float(len(style_imgs)) 412 | return total_style_loss 413 | 414 | def sum_style_losses(sess, net, style_imgs): 415 | total_style_loss = 0. 416 | weights = args.style_imgs_weights 417 | for img, img_weight in zip(style_imgs, weights): 418 | sess.run(net['input'].assign(img)) 419 | style_loss = 0. 420 | for layer, weight in zip(args.style_layers, args.style_layer_weights): 421 | a = sess.run(net[layer]) 422 | x = net[layer] 423 | a = tf.convert_to_tensor(a) 424 | style_loss += style_layer_loss(a, x) * weight 425 | style_loss /= float(len(args.style_layers)) 426 | total_style_loss += (style_loss * img_weight) 427 | total_style_loss /= float(len(style_imgs)) 428 | return total_style_loss 429 | 430 | def sum_content_losses(sess, net, content_img): 431 | sess.run(net['input'].assign(content_img)) 432 | content_loss = 0. 433 | for layer, weight in zip(args.content_layers, args.content_layer_weights): 434 | p = sess.run(net[layer]) 435 | x = net[layer] 436 | p = tf.convert_to_tensor(p) 437 | content_loss += content_layer_loss(p, x) * weight 438 | content_loss /= float(len(args.content_layers)) 439 | return content_loss 440 | 441 | ''' 442 | 'artistic style transfer for videos' loss functions 443 | ''' 444 | def temporal_loss(x, w, c): 445 | c = c[np.newaxis,:,:,:] 446 | D = float(x.size) 447 | loss = (1. / D) * tf.reduce_sum(c * tf.nn.l2_loss(x - w)) 448 | loss = tf.cast(loss, tf.float32) 449 | return loss 450 | 451 | def get_longterm_weights(i, j): 452 | c_sum = 0. 453 | for k in range(args.prev_frame_indices): 454 | if i - k > i - j: 455 | c_sum += get_content_weights(i, i - k) 456 | c = get_content_weights(i, i - j) 457 | c_max = tf.maximum(c - c_sum, 0.) 458 | return c_max 459 | 460 | def sum_longterm_temporal_losses(sess, net, frame, input_img): 461 | x = sess.run(net['input'].assign(input_img)) 462 | loss = 0. 463 | for j in range(args.prev_frame_indices): 464 | prev_frame = frame - j 465 | w = get_prev_warped_frame(frame) 466 | c = get_longterm_weights(frame, prev_frame) 467 | loss += temporal_loss(x, w, c) 468 | return loss 469 | 470 | def sum_shortterm_temporal_losses(sess, net, frame, input_img): 471 | x = sess.run(net['input'].assign(input_img)) 472 | prev_frame = frame - 1 473 | w = get_prev_warped_frame(frame) 474 | c = get_content_weights(frame, prev_frame) 475 | loss = temporal_loss(x, w, c) 476 | return loss 477 | 478 | ''' 479 | utilities and i/o 480 | ''' 481 | def read_image(path): 482 | # bgr image 483 | img = cv2.imread(path, cv2.IMREAD_COLOR) 484 | check_image(img, path) 485 | img = img.astype(np.float32) 486 | img = preprocess(img) 487 | return img 488 | 489 | def write_image(path, img): 490 | img = postprocess(img) 491 | cv2.imwrite(path, img) 492 | 493 | def preprocess(img): 494 | imgpre = np.copy(img) 495 | # bgr to rgb 496 | imgpre = imgpre[...,::-1] 497 | # shape (h, w, d) to (1, h, w, d) 498 | imgpre = imgpre[np.newaxis,:,:,:] 499 | imgpre -= np.array([123.68, 116.779, 103.939]).reshape((1,1,1,3)) 500 | return imgpre 501 | 502 | def postprocess(img): 503 | imgpost = np.copy(img) 504 | imgpost += np.array([123.68, 116.779, 103.939]).reshape((1,1,1,3)) 505 | # shape (1, h, w, d) to (h, w, d) 506 | imgpost = imgpost[0] 507 | imgpost = np.clip(imgpost, 0, 255).astype('uint8') 508 | # rgb to bgr 509 | imgpost = imgpost[...,::-1] 510 | return imgpost 511 | 512 | def read_flow_file(path): 513 | with open(path, 'rb') as f: 514 | # 4 bytes header 515 | header = struct.unpack('4s', f.read(4))[0] 516 | # 4 bytes width, height 517 | w = struct.unpack('i', f.read(4))[0] 518 | h = struct.unpack('i', f.read(4))[0] 519 | flow = np.ndarray((2, h, w), dtype=np.float32) 520 | for y in range(h): 521 | for x in range(w): 522 | flow[0,y,x] = struct.unpack('f', f.read(4))[0] 523 | flow[1,y,x] = struct.unpack('f', f.read(4))[0] 524 | return flow 525 | 526 | def read_weights_file(path): 527 | lines = open(path).readlines() 528 | header = list(map(int, lines[0].split(' '))) 529 | w = header[0] 530 | h = header[1] 531 | vals = np.zeros((h, w), dtype=np.float32) 532 | for i in range(1, len(lines)): 533 | line = lines[i].rstrip().split(' ') 534 | vals[i-1] = np.array(list(map(np.float32, line))) 535 | vals[i-1] = list(map(lambda x: 0. if x < 255. else 1., vals[i-1])) 536 | # expand to 3 channels 537 | weights = np.dstack([vals.astype(np.float32)] * 3) 538 | return weights 539 | 540 | def normalize(weights): 541 | denom = sum(weights) 542 | if denom > 0.: 543 | return [float(i) / denom for i in weights] 544 | else: return [0.] * len(weights) 545 | 546 | def maybe_make_directory(dir_path): 547 | if not os.path.exists(dir_path): 548 | os.makedirs(dir_path) 549 | 550 | def check_image(img, path): 551 | if img is None: 552 | raise OSError(errno.ENOENT, "No such file", path) 553 | 554 | ''' 555 | rendering -- where the magic happens 556 | ''' 557 | def stylize(content_img, style_imgs, init_img, frame=None): 558 | with tf.device(args.device), tf.compat.v1.Session() as sess: 559 | # setup network 560 | net = build_model(content_img) 561 | 562 | # style loss 563 | if args.style_mask: 564 | L_style = sum_masked_style_losses(sess, net, style_imgs) 565 | else: 566 | L_style = sum_style_losses(sess, net, style_imgs) 567 | 568 | # content loss 569 | L_content = sum_content_losses(sess, net, content_img) 570 | 571 | # denoising loss 572 | L_tv = tf.image.total_variation(net['input']) 573 | 574 | # loss weights 575 | alpha = args.content_weight 576 | beta = args.style_weight 577 | theta = args.tv_weight 578 | 579 | # total loss 580 | L_total = alpha * L_content 581 | L_total += beta * L_style 582 | L_total += theta * L_tv 583 | 584 | # video temporal loss 585 | if args.video and frame > 1: 586 | gamma = args.temporal_weight 587 | L_temporal = sum_shortterm_temporal_losses(sess, net, frame, init_img) 588 | L_total += gamma * L_temporal 589 | 590 | # optimization algorithm 591 | optimizer = get_optimizer(L_total) 592 | 593 | if args.optimizer == 'adam': 594 | minimize_with_adam(sess, net, optimizer, init_img, L_total) 595 | elif args.optimizer == 'lbfgs': 596 | minimize_with_lbfgs(sess, net, optimizer, init_img) 597 | 598 | output_img = sess.run(net['input']) 599 | 600 | if args.original_colors: 601 | output_img = convert_to_original_colors(np.copy(content_img), output_img) 602 | 603 | if args.video: 604 | write_video_output(frame, output_img) 605 | else: 606 | write_image_output(output_img, content_img, style_imgs, init_img) 607 | 608 | def minimize_with_lbfgs(sess, net, optimizer, init_img): 609 | if args.verbose: print('\nMINIMIZING LOSS USING: L-BFGS OPTIMIZER') 610 | init_op = tf.global_variables_initializer() 611 | sess.run(init_op) 612 | sess.run(net['input'].assign(init_img)) 613 | optimizer.minimize(sess) 614 | 615 | def minimize_with_adam(sess, net, optimizer, init_img, loss): 616 | if args.verbose: print('\nMINIMIZING LOSS USING: ADAM OPTIMIZER') 617 | train_op = optimizer.minimize(loss) 618 | init_op = tf.global_variables_initializer() 619 | sess.run(init_op) 620 | sess.run(net['input'].assign(init_img)) 621 | iterations = 0 622 | while (iterations < args.max_iterations): 623 | sess.run(train_op) 624 | if iterations % args.print_iterations == 0 and args.verbose: 625 | curr_loss = loss.eval() 626 | print("At iterate {}\tf= {}".format(iterations, curr_loss)) 627 | iterations += 1 628 | 629 | def get_optimizer(loss): 630 | print_iterations = args.print_iterations if args.verbose else 0 631 | if args.optimizer == 'lbfgs': 632 | optimizer = tf.contrib.opt.ScipyOptimizerInterface( 633 | loss, method='L-BFGS-B', 634 | options={'maxiter': args.max_iterations, 635 | 'disp': print_iterations}) 636 | elif args.optimizer == 'adam': 637 | optimizer = tf.train.AdamOptimizer(args.learning_rate) 638 | return optimizer 639 | 640 | def write_video_output(frame, output_img): 641 | fn = args.content_frame_frmt.format(str(frame).zfill(args.zfill)) 642 | path = os.path.join(args.video_output_dir, fn) 643 | write_image(path, output_img) 644 | 645 | def write_image_output(output_img, content_img, style_imgs, init_img): 646 | out_dir = os.path.join(args.img_output_dir, str(args.max_iterations)) 647 | maybe_make_directory(out_dir) 648 | img_path = os.path.join(out_dir, args.img_output_dir+'-'+str(args.max_iterations)+'.png') 649 | content_path = os.path.join(out_dir, 'content.png') 650 | init_path = os.path.join(out_dir, 'init.png') 651 | 652 | write_image(img_path, output_img) 653 | write_image(content_path, content_img) 654 | write_image(init_path, init_img) 655 | index = 0 656 | for style_img in style_imgs: 657 | path = os.path.join(out_dir, 'style_'+str(index)+'.png') 658 | write_image(path, style_img) 659 | index += 1 660 | 661 | # save the configuration settings 662 | out_file = os.path.join(out_dir, 'meta_data.txt') 663 | f = open(out_file, 'w') 664 | f.write('image_name: {}\n'.format(args.img_name)) 665 | f.write('content: {}\n'.format(args.content_img)) 666 | index = 0 667 | for style_img, weight in zip(args.style_imgs, args.style_imgs_weights): 668 | f.write('styles['+str(index)+']: {} * {}\n'.format(weight, style_img)) 669 | index += 1 670 | index = 0 671 | if args.style_mask_imgs is not None: 672 | for mask in args.style_mask_imgs: 673 | f.write('style_masks['+str(index)+']: {}\n'.format(mask)) 674 | index += 1 675 | f.write('init_type: {}\n'.format(args.init_img_type)) 676 | f.write('content_weight: {}\n'.format(args.content_weight)) 677 | f.write('style_weight: {}\n'.format(args.style_weight)) 678 | f.write('tv_weight: {}\n'.format(args.tv_weight)) 679 | f.write('content_layers: {}\n'.format(args.content_layers)) 680 | f.write('style_layers: {}\n'.format(args.style_layers)) 681 | f.write('optimizer_type: {}\n'.format(args.optimizer)) 682 | f.write('max_iterations: {}\n'.format(args.max_iterations)) 683 | f.write('max_image_size: {}\n'.format(args.max_size)) 684 | f.close() 685 | 686 | ''' 687 | image loading and processing 688 | ''' 689 | def get_init_image(init_type, content_img, style_imgs, frame=None): 690 | if init_type == 'content': 691 | return content_img 692 | elif init_type == 'style': 693 | return style_imgs[0] 694 | elif init_type == 'random': 695 | init_img = get_noise_image(args.noise_ratio, content_img) 696 | return init_img 697 | # only for video frames 698 | elif init_type == 'prev': 699 | init_img = get_prev_frame(frame) 700 | return init_img 701 | elif init_type == 'prev_warped': 702 | init_img = get_prev_warped_frame(frame) 703 | return init_img 704 | 705 | def get_content_frame(frame): 706 | fn = args.content_frame_frmt.format(str(frame).zfill(args.zfill)) 707 | path = os.path.join(args.video_input_dir, fn) 708 | img = read_image(path) 709 | return img 710 | 711 | def get_content_image(content_img): 712 | path = os.path.join(args.content_img_dir, content_img) 713 | # bgr image 714 | img = cv2.imread(path, cv2.IMREAD_COLOR) 715 | check_image(img, path) 716 | img = img.astype(np.float32) 717 | h, w, d = img.shape 718 | mx = args.max_size 719 | # resize if > max size 720 | if h > w and h > mx: 721 | w = (float(mx) / float(h)) * w 722 | img = cv2.resize(img, dsize=(int(w), mx), interpolation=cv2.INTER_AREA) 723 | if w > mx: 724 | h = (float(mx) / float(w)) * h 725 | img = cv2.resize(img, dsize=(mx, int(h)), interpolation=cv2.INTER_AREA) 726 | img = preprocess(img) 727 | return img 728 | 729 | def get_style_images(content_img): 730 | _, ch, cw, cd = content_img.shape 731 | mx = args.max_size 732 | style_imgs = [] 733 | for style_fn in args.style_imgs: 734 | path = os.path.join(args.style_imgs_dir, style_fn) 735 | # bgr image 736 | img = cv2.imread(path, cv2.IMREAD_COLOR) 737 | check_image(img, path) 738 | img = img.astype(np.float32) 739 | sh, sw, sd = img.shape 740 | 741 | # use scale args to resize and tile image 742 | scaled_img = cv2.resize(img, dsize=(int(sw*args.style_scale), int(sh*args.style_scale)), interpolation=cv2.INTER_AREA) 743 | ssh, ssw, ssd = scaled_img.shape 744 | 745 | if ssh > ch and ssw > cw: 746 | starty = int((ssh-ch)/2) 747 | startx = int((ssw-cw)/2) 748 | img = scaled_img[starty:starty+ch, startx:startx+cw] 749 | elif ssh > ch: 750 | starty = int((ssh-ch)/2) 751 | img = scaled_img[starty:starty+ch, 0:ssw] 752 | if ssw != cw: 753 | img = cv2.copyMakeBorder(img,0,0,0,(cw-ssw),cv2.BORDER_REFLECT) 754 | elif ssw > cw: 755 | startx = int((ssw-cw)/2) 756 | img = scaled_img[0:ssh, startx:startx+cw] 757 | if ssh != ch: 758 | img = cv2.copyMakeBorder(img,0,(ch-ssh),0,0,cv2.BORDER_REFLECT) 759 | else: 760 | img = cv2.copyMakeBorder(scaled_img,0,(ch-ssh),0,(cw-ssw),cv2.BORDER_REFLECT) 761 | 762 | img = preprocess(img) 763 | style_imgs.append(img) 764 | return style_imgs 765 | 766 | def get_noise_image(noise_ratio, content_img): 767 | np.random.seed(args.seed) 768 | noise_img = np.random.uniform(-20., 20., content_img.shape).astype(np.float32) 769 | img = noise_ratio * noise_img + (1.-noise_ratio) * content_img 770 | return img 771 | 772 | def get_mask_image(mask_img, width, height): 773 | path = os.path.join(args.content_img_dir, mask_img) 774 | img = cv2.imread(path, cv2.IMREAD_GRAYSCALE) 775 | check_image(img, path) 776 | img = cv2.resize(img, dsize=(width, height), interpolation=cv2.INTER_AREA) 777 | img = img.astype(np.float32) 778 | mx = np.amax(img) 779 | img /= mx 780 | return img 781 | 782 | def get_prev_frame(frame): 783 | # previously stylized frame 784 | prev_frame = frame - 1 785 | fn = args.content_frame_frmt.format(str(prev_frame).zfill(args.zfill)) 786 | path = os.path.join(args.video_output_dir, fn) 787 | img = cv2.imread(path, cv2.IMREAD_COLOR) 788 | check_image(img, path) 789 | return img 790 | 791 | def get_prev_warped_frame(frame): 792 | prev_img = get_prev_frame(frame) 793 | prev_frame = frame - 1 794 | # backwards flow: current frame -> previous frame 795 | fn = args.backward_optical_flow_frmt.format(str(frame), str(prev_frame)) 796 | path = os.path.join(args.video_input_dir, fn) 797 | flow = read_flow_file(path) 798 | warped_img = warp_image(prev_img, flow).astype(np.float32) 799 | img = preprocess(warped_img) 800 | return img 801 | 802 | def get_content_weights(frame, prev_frame): 803 | forward_fn = args.content_weights_frmt.format(str(prev_frame), str(frame)) 804 | backward_fn = args.content_weights_frmt.format(str(frame), str(prev_frame)) 805 | forward_path = os.path.join(args.video_input_dir, forward_fn) 806 | backward_path = os.path.join(args.video_input_dir, backward_fn) 807 | forward_weights = read_weights_file(forward_path) 808 | backward_weights = read_weights_file(backward_path) 809 | return forward_weights #, backward_weights 810 | 811 | def warp_image(src, flow): 812 | _, h, w = flow.shape 813 | flow_map = np.zeros(flow.shape, dtype=np.float32) 814 | for y in range(h): 815 | flow_map[1,y,:] = float(y) + flow[1,y,:] 816 | for x in range(w): 817 | flow_map[0,:,x] = float(x) + flow[0,:,x] 818 | # remap pixels to optical flow 819 | dst = cv2.remap( 820 | src, flow_map[0], flow_map[1], 821 | interpolation=cv2.INTER_CUBIC, borderMode=cv2.BORDER_TRANSPARENT) 822 | return dst 823 | 824 | def convert_to_original_colors(content_img, stylized_img): 825 | content_img = postprocess(content_img) 826 | stylized_img = postprocess(stylized_img) 827 | if args.color_convert_type == 'yuv': 828 | cvt_type = cv2.COLOR_BGR2YUV 829 | inv_cvt_type = cv2.COLOR_YUV2BGR 830 | elif args.color_convert_type == 'ycrcb': 831 | cvt_type = cv2.COLOR_BGR2YCR_CB 832 | inv_cvt_type = cv2.COLOR_YCR_CB2BGR 833 | elif args.color_convert_type == 'luv': 834 | cvt_type = cv2.COLOR_BGR2LUV 835 | inv_cvt_type = cv2.COLOR_LUV2BGR 836 | elif args.color_convert_type == 'lab': 837 | cvt_type = cv2.COLOR_BGR2LAB 838 | inv_cvt_type = cv2.COLOR_LAB2BGR 839 | content_cvt = cv2.cvtColor(content_img, cvt_type) 840 | stylized_cvt = cv2.cvtColor(stylized_img, cvt_type) 841 | c1, _, _ = cv2.split(stylized_cvt) 842 | _, c2, c3 = cv2.split(content_cvt) 843 | merged = cv2.merge((c1, c2, c3)) 844 | dst = cv2.cvtColor(merged, inv_cvt_type).astype(np.float32) 845 | dst = preprocess(dst) 846 | return dst 847 | 848 | def render_single_image(): 849 | content_img = get_content_image(args.content_img) 850 | style_imgs = get_style_images(content_img) 851 | with tf.Graph().as_default(): 852 | print('\n---- RENDERING SINGLE IMAGE ----\n') 853 | init_img = get_init_image(args.init_img_type, content_img, style_imgs) 854 | tick = time.time() 855 | stylize(content_img, style_imgs, init_img) 856 | tock = time.time() 857 | print('Single image elapsed time: {}'.format(tock - tick)) 858 | 859 | def render_video(): 860 | for frame in range(args.start_frame, args.end_frame+1): 861 | with tf.Graph().as_default(): 862 | print('\n---- RENDERING VIDEO FRAME: {}/{} ----\n'.format(frame, args.end_frame)) 863 | if frame == 1: 864 | content_frame = get_content_frame(frame) 865 | style_imgs = get_style_images(content_frame) 866 | init_img = get_init_image(args.first_frame_type, content_frame, style_imgs, frame) 867 | args.max_iterations = args.first_frame_iterations 868 | tick = time.time() 869 | stylize(content_frame, style_imgs, init_img, frame) 870 | tock = time.time() 871 | print('Frame {} elapsed time: {}'.format(frame, tock - tick)) 872 | else: 873 | content_frame = get_content_frame(frame) 874 | style_imgs = get_style_images(content_frame) 875 | init_img = get_init_image(args.init_frame_type, content_frame, style_imgs, frame) 876 | args.max_iterations = args.frame_iterations 877 | tick = time.time() 878 | stylize(content_frame, style_imgs, init_img, frame) 879 | tock = time.time() 880 | print('Frame {} elapsed time: {}'.format(frame, tock - tick)) 881 | 882 | def main(): 883 | global args 884 | args = parse_args() 885 | if args.video: render_video() 886 | else: render_single_image() 887 | 888 | if __name__ == '__main__': 889 | main() 890 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | opencv-python>=4.1.1.26 2 | scipy>=1.3.1 3 | -------------------------------------------------------------------------------- /styles/kandinsky.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/styles/kandinsky.jpg -------------------------------------------------------------------------------- /styles/seated-nude.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/styles/seated-nude.jpg -------------------------------------------------------------------------------- /styles/shipwreck.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/styles/shipwreck.jpg -------------------------------------------------------------------------------- /styles/starry-night.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/styles/starry-night.jpg -------------------------------------------------------------------------------- /styles/the_scream.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/styles/the_scream.jpg -------------------------------------------------------------------------------- /styles/woman-with-hat-matisse.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/styles/woman-with-hat-matisse.jpg -------------------------------------------------------------------------------- /stylize_image.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | # Get a carriage return into `cr` 3 | cr=`echo $'\n.'` 4 | cr=${cr%.} 5 | 6 | if [ "$#" -le 1 ]; then 7 | echo "Usage: bash stylize_image.sh " 8 | exit 1 9 | fi 10 | 11 | echo "" 12 | read -p "Did you install the required dependencies? [y/n] $cr > " dependencies 13 | 14 | if [ "$dependencies" != "y" ]; then 15 | echo "Error: Requires dependencies: tensorflow, opencv2 (python), scipy" 16 | exit 1; 17 | fi 18 | 19 | echo "" 20 | read -p "Do you have a CUDA enabled GPU? [y/n] $cr > " cuda 21 | 22 | if [ "$cuda" != "y" ]; then 23 | device='/cpu:0' 24 | else 25 | device='/gpu:0' 26 | fi 27 | 28 | # Parse arguments 29 | content_image="$1" 30 | content_dir=$(dirname "$content_image") 31 | content_filename=$(basename "$content_image") 32 | 33 | style_image="$2" 34 | style_dir=$(dirname "$style_image" ) 35 | style_filename=$(basename "$style_image") 36 | 37 | echo "Rendering stylized image. This may take a while..." 38 | python neural_style.py \ 39 | --content_img "${content_filename}" \ 40 | --content_img_dir "${content_dir}" \ 41 | --style_imgs "${style_filename}" \ 42 | --style_imgs_dir "${style_dir}" \ 43 | --device "${device}" \ 44 | --verbose; -------------------------------------------------------------------------------- /stylize_video.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | # Get a carriage return into `cr` 3 | cr=`echo $'\n.'` 4 | cr=${cr%.} 5 | 6 | # Find out whether ffmpeg or avconv is installed on the system 7 | FFMPEG=ffmpeg 8 | command -v $FFMPEG >/dev/null 2>&1 || { 9 | FFMPEG=avconv 10 | command -v $FFMPEG >/dev/null 2>&1 || { 11 | echo >&2 "This script requires either ffmpeg or avconv installed. Aborting."; exit 1; 12 | } 13 | } 14 | 15 | if [ "$#" -le 1 ]; then 16 | echo "Usage: bash stylize_video.sh " 17 | exit 1 18 | fi 19 | 20 | echo "" 21 | read -p "Did you install the required dependencies? [y/n] $cr > " dependencies 22 | 23 | if [ "$dependencies" != "y" ]; then 24 | echo "Error: Requires dependencies: tensorflow, opencv2 (python), scipy" 25 | exit 1; 26 | fi 27 | 28 | echo "" 29 | read -p "Do you have a CUDA enabled GPU? [y/n] $cr > " cuda 30 | 31 | if [ "$cuda" != "y" ]; then 32 | echo "Error: GPU required to render videos in a feasible amount of time." 33 | exit 1; 34 | fi 35 | 36 | # Parse arguments 37 | content_video="$1" 38 | content_dir=$(dirname "$content_video") 39 | content_filename=$(basename "$content_video") 40 | extension="${content_filename##*.}" 41 | content_filename="${content_filename%.*}" 42 | content_filename=${content_filename//[%]/x} 43 | 44 | style_image="$2" 45 | style_dir=$(dirname "$style_image") 46 | style_filename=$(basename "$style_image") 47 | 48 | if [ ! -d "./video_input" ]; then 49 | mkdir -p ./video_input 50 | fi 51 | temp_dir="./video_input/${content_filename}" 52 | 53 | # Create output folder 54 | mkdir -p "$temp_dir" 55 | 56 | # Save frames of the video as individual image files 57 | $FFMPEG -v quiet -i "$1" "${temp_dir}/frame_%04d.ppm" 58 | eval $(ffprobe -v error -of flat=s=_ -select_streams v:0 -show_entries stream=width,height "$1") 59 | width="${streams_stream_0_width}" 60 | height="${streams_stream_0_height}" 61 | if [ "$width" -gt "$height" ]; then 62 | max_size="$width" 63 | else 64 | max_size="$height" 65 | fi 66 | num_frames=$(find "$temp_dir" -iname "*.ppm" | wc -l) 67 | 68 | echo "Computing optical flow [CPU]. This will take a while..." 69 | cd ./video_input 70 | bash make-opt-flow.sh ${content_filename}/frame_%04d.ppm ${content_filename} 71 | cd .. 72 | 73 | echo "Rendering stylized video frames [CPU & GPU]. This will take a while..." 74 | python neural_style.py --video \ 75 | --video_input_dir "${temp_dir}" \ 76 | --style_imgs_dir "${style_dir}" \ 77 | --style_imgs "${style_filename}" \ 78 | --end_frame "${num_frames}" \ 79 | --max_size "${max_size}" \ 80 | --verbose; 81 | 82 | # Create video from output images. 83 | echo "Converting image sequence to video. This should be quick..." 84 | $FFMPEG -v quiet -i ./video_output/frame_%04d.ppm ./video_output/${content_filename}-stylized.$extension 85 | 86 | # Clean up garbage 87 | if [ -d "${temp_dir}" ]; then 88 | rm -rf "${temp_dir}" 89 | fi 90 | -------------------------------------------------------------------------------- /video_input/consistencyChecker/CTensor4D.h: -------------------------------------------------------------------------------- 1 | // CTensor4D 2 | // A four-dimensional array 3 | // 4 | // Author: Thomas Brox 5 | // Last change: 05.11.2001 6 | //------------------------------------------------------------------------- 7 | // Note: 8 | // There is a difference between the GNU Compiler's STL and the standard 9 | // concerning the definition and usage of string streams as well as substrings. 10 | // Thus if using a GNU Compiler you should write #define GNU_COMPILER at the 11 | // beginning of your program. 12 | // 13 | // Another Note: 14 | // Linker problems occured in connection with from the STL. 15 | // In this case you should include this file in a namespace. 16 | // Example: 17 | // namespace NTensor4D { 18 | // #include 19 | // } 20 | // After including other packages you can then write: 21 | // using namespace NTensor4D; 22 | 23 | #ifndef CTENSOR4D_H 24 | #define CTENSOR4D_H 25 | 26 | #include 27 | #include 28 | #include 29 | #ifdef GNU_COMPILER 30 | #include 31 | #else 32 | #include 33 | #endif 34 | #include "CTensor.h" 35 | 36 | template 37 | class CTensor4D { 38 | public: 39 | // constructor 40 | inline CTensor4D(); 41 | inline CTensor4D(const int aXSize, const int aYSize, const int aZSize, const int aASize); 42 | // copy constructor 43 | CTensor4D(const CTensor4D& aCopyFrom); 44 | // constructor with implicit filling 45 | CTensor4D(const int aXSize, const int aYSize, const int aZSize, const int aASize, const T aFillValue); 46 | // destructor 47 | virtual ~CTensor4D(); 48 | 49 | // Changes the size of the tensor, data will be lost 50 | void setSize(int aXSize, int aYSize, int aZSize, int aASize); 51 | // Downsamples the tensor 52 | void downsample(int aNewXSize, int aNewYSize); 53 | void downsample(int aNewXSize, int aNewYSize, int aNewZSize); 54 | // Upsamples the tensor 55 | void upsample(int aNewXSize, int aNewYSize); 56 | void upsampleBilinear(int aNewXSize, int aNewYSize); 57 | void upsampleTrilinear(int aNewXSize, int aNewYSize, int aNewZSize); 58 | // Fills the tensor with the value aValue (see also operator =) 59 | void fill(const T aValue); 60 | // Copies a box from the tensor into aResult, the size of aResult will be adjusted 61 | void cut(CTensor4D& aResult, int x1, int y1, int z1, int a1, int x2, int y2, int z2, int a2); 62 | // Reads data from a list of PPM or PGM files given in a text file 63 | void readFromFile(char* aFilename); 64 | // Writes a set of colour images to a large PPM image 65 | void writeToPPM(const char* aFilename, int aCols = 0, int aRows = 0); 66 | 67 | // Gives full access to tensor's values 68 | inline T& operator()(const int ax, const int ay, const int az, const int aa) const; 69 | // Read access with bilinear interpolation 70 | CVector operator()(const float ax, const float ay, const int aa) const; 71 | // Fills the tensor with the value aValue (equivalent to fill()) 72 | inline CTensor4D& operator=(const T aValue); 73 | // Copies the tensor aCopyFrom to this tensor (size of tensor might change) 74 | CTensor4D& operator=(const CTensor4D& aCopyFrom); 75 | // Multiplication with a scalar 76 | CTensor4D& operator*=(const T aValue); 77 | // Component-wise addition 78 | CTensor4D& operator+=(const CTensor4D& aTensor); 79 | 80 | // Gives access to the tensor's size 81 | inline int xSize() const; 82 | inline int ySize() const; 83 | inline int zSize() const; 84 | inline int aSize() const; 85 | inline int size() const; 86 | // Returns the aath layer of the 4D-tensor as 3D-tensor 87 | CTensor getTensor3D(const int aa) const; 88 | // Removes one dimension and returns the resulting 3D-tensor 89 | void getTensor3D(CTensor& aTensor, int aIndex, int aDim = 3) const; 90 | // Copies the components of a 3D-tensor in the aDimth layer of the 4D-tensor 91 | void putTensor3D(CTensor& aTensor, int aIndex, int aDim = 3); 92 | // Removes two dimensions and returns the resulting matrix 93 | void getMatrix(CMatrix& aMatrix, int aZIndex, int aAIndex) const; 94 | // Copies the components of a 3D-tensor in the aDimth layer of the 4D-tensor 95 | void putMatrix(CMatrix& aMatrix, int aZIndex, int aAIndex); 96 | // Gives access to the internal data representation (use sparingly) 97 | inline T* data() const; 98 | protected: 99 | int mXSize,mYSize,mZSize,mASize; 100 | T *mData; 101 | }; 102 | 103 | // Provides basic output functionality (only appropriate for very small tensors) 104 | template std::ostream& operator<<(std::ostream& aStream, const CTensor4D& aTensor); 105 | 106 | // Exceptions thrown by CTensor------------------------------------------------- 107 | 108 | // Thrown when one tries to access an element of a tensor which is out of 109 | // the tensor's bounds 110 | struct ETensor4DRangeOverflow { 111 | ETensor4DRangeOverflow(const int ax, const int ay, const int az, const int aa) { 112 | using namespace std; 113 | cerr << "Exception ETensor4DRangeOverflow: x = " << ax << ", y = " << ay << ", z = " << az << ", a = " << aa << endl; 114 | } 115 | }; 116 | 117 | // Thrown from getTensor3D if the parameter's size does not match with the size 118 | // of this tensor 119 | struct ETensor4DIncompatibleSize { 120 | ETensor4DIncompatibleSize(int ax, int ay, int az, int ax2, int ay2, int az2) { 121 | using namespace std; 122 | cerr << "Exception ETensor4DIncompatibleSize: x = " << ax << ":" << ax2; 123 | cerr << ", y = " << ay << ":" << ay2; 124 | cerr << ", z = " << az << ":" << az2 << endl; 125 | } 126 | }; 127 | 128 | // Thrown from readFromFile if the file format is unknown 129 | struct ETensor4DInvalidFileFormat { 130 | ETensor4DInvalidFileFormat() { 131 | using namespace std; 132 | cerr << "Exception ETensor4DInvalidFileFormat" << endl; 133 | } 134 | }; 135 | 136 | // I M P L E M E N T A T I O N -------------------------------------------- 137 | // 138 | // You might wonder why there is implementation code in a header file. 139 | // The reason is that not all C++ compilers yet manage separate compilation 140 | // of templates. Inline functions cannot be compiled separately anyway. 141 | // So in this case the whole implementation code is added to the header 142 | // file. 143 | // Users of CTensor4D should ignore everything that's beyond this line :) 144 | // ------------------------------------------------------------------------ 145 | 146 | // P U B L I C ------------------------------------------------------------ 147 | 148 | // constructor 149 | template 150 | inline CTensor4D::CTensor4D() { 151 | mData = 0; mXSize = 0; mYSize = 0; mZSize = 0; mASize = 0; 152 | } 153 | 154 | // constructor 155 | template 156 | inline CTensor4D::CTensor4D(const int aXSize, const int aYSize, const int aZSize, const int aASize) 157 | : mXSize(aXSize), mYSize(aYSize), mZSize(aZSize), mASize(aASize) { 158 | mData = new T[aXSize*aYSize*aZSize*aASize]; 159 | } 160 | 161 | // copy constructor 162 | template 163 | CTensor4D::CTensor4D(const CTensor4D& aCopyFrom) 164 | : mXSize(aCopyFrom.mXSize), mYSize(aCopyFrom.mYSize), mZSize(aCopyFrom.mZSize), mASize(aCopyFrom.mASize) { 165 | int wholeSize = mXSize*mYSize*mZSize*mASize; 166 | mData = new T[wholeSize]; 167 | for (register int i = 0; i < wholeSize; i++) 168 | mData[i] = aCopyFrom.mData[i]; 169 | } 170 | 171 | // constructor with implicit filling 172 | template 173 | CTensor4D::CTensor4D(const int aXSize, const int aYSize, const int aZSize, const int aASize, const T aFillValue) 174 | : mXSize(aXSize), mYSize(aYSize), mZSize(aZSize), mASize(aASize) { 175 | mData = new T[aXSize*aYSize*aZSize*aASize]; 176 | fill(aFillValue); 177 | } 178 | 179 | // destructor 180 | template 181 | CTensor4D::~CTensor4D() { 182 | delete[] mData; 183 | } 184 | 185 | // setSize 186 | template 187 | void CTensor4D::setSize(int aXSize, int aYSize, int aZSize, int aASize) { 188 | if (mData != 0) delete[] mData; 189 | mData = new T[aXSize*aYSize*aZSize*aASize]; 190 | mXSize = aXSize; 191 | mYSize = aYSize; 192 | mZSize = aZSize; 193 | mASize = aASize; 194 | } 195 | 196 | //downsample 197 | template 198 | void CTensor4D::downsample(int aNewXSize, int aNewYSize) { 199 | T* mData2 = new T[aNewXSize*aNewYSize*mZSize*mASize]; 200 | int aSize = aNewXSize*aNewYSize; 201 | for (int a = 0; a < mASize; a++) 202 | for (int z = 0; z < mZSize; z++) { 203 | CMatrix aTemp(mXSize,mYSize); 204 | getMatrix(aTemp,z,a); 205 | aTemp.downsample(aNewXSize,aNewYSize); 206 | for (int i = 0; i < aSize; i++) 207 | mData2[i+(a*mZSize+z)*aSize] = aTemp.data()[i]; 208 | } 209 | delete[] mData; 210 | mData = mData2; 211 | mXSize = aNewXSize; 212 | mYSize = aNewYSize; 213 | } 214 | 215 | template 216 | void CTensor4D::downsample(int aNewXSize, int aNewYSize, int aNewZSize) { 217 | T* mData2 = new T[aNewXSize*aNewYSize*aNewZSize*mASize]; 218 | int aSize = aNewXSize*aNewYSize*aNewZSize; 219 | for (int a = 0; a < mASize; a++) { 220 | CTensor aTemp(mXSize,mYSize,mZSize); 221 | getTensor3D(aTemp,a); 222 | aTemp.downsample(aNewXSize,aNewYSize,aNewZSize); 223 | for (int i = 0; i < aSize; i++) 224 | mData2[i+a*aSize] = aTemp.data()[i]; 225 | } 226 | delete[] mData; 227 | mData = mData2; 228 | mXSize = aNewXSize; 229 | mYSize = aNewYSize; 230 | mZSize = aNewZSize; 231 | } 232 | 233 | // upsample 234 | template 235 | void CTensor4D::upsample(int aNewXSize, int aNewYSize) { 236 | T* mData2 = new T[aNewXSize*aNewYSize*mZSize*mASize]; 237 | int aSize = aNewXSize*aNewYSize; 238 | for (int a = 0; a < mASize; a++) 239 | for (int z = 0; z < mZSize; z++) { 240 | CMatrix aTemp(mXSize,mYSize); 241 | getMatrix(aTemp,z,a); 242 | aTemp.upsample(aNewXSize,aNewYSize); 243 | for (int i = 0; i < aSize; i++) 244 | mData2[i+(a*mZSize+z)*aSize] = aTemp.data()[i]; 245 | } 246 | delete[] mData; 247 | mData = mData2; 248 | mXSize = aNewXSize; 249 | mYSize = aNewYSize; 250 | } 251 | 252 | // upsampleBilinear 253 | template 254 | void CTensor4D::upsampleBilinear(int aNewXSize, int aNewYSize) { 255 | T* mData2 = new T[aNewXSize*aNewYSize*mZSize*mASize]; 256 | int aSize = aNewXSize*aNewYSize; 257 | for (int a = 0; a < mASize; a++) 258 | for (int z = 0; z < mZSize; z++) { 259 | CMatrix aTemp(mXSize,mYSize); 260 | getMatrix(aTemp,z,a); 261 | aTemp.upsampleBilinear(aNewXSize,aNewYSize); 262 | for (int i = 0; i < aSize; i++) 263 | mData2[i+(a*mZSize+z)*aSize] = aTemp.data()[i]; 264 | } 265 | delete[] mData; 266 | mData = mData2; 267 | mXSize = aNewXSize; 268 | mYSize = aNewYSize; 269 | } 270 | 271 | // upsampleTrilinear 272 | template 273 | void CTensor4D::upsampleTrilinear(int aNewXSize, int aNewYSize, int aNewZSize) { 274 | T* mData2 = new T[aNewXSize*aNewYSize*aNewZSize*mASize]; 275 | int aSize = aNewXSize*aNewYSize*aNewZSize; 276 | for (int a = 0; a < mASize; a++) { 277 | CTensor aTemp(mXSize,mYSize,mZSize); 278 | getTensor3D(aTemp,a); 279 | aTemp.upsampleTrilinear(aNewXSize,aNewYSize,aNewZSize); 280 | for (int i = 0; i < aSize; i++) 281 | mData2[i+a*aSize] = aTemp.data()[i]; 282 | } 283 | delete[] mData; 284 | mData = mData2; 285 | mXSize = aNewXSize; 286 | mYSize = aNewYSize; 287 | mZSize = aNewZSize; 288 | } 289 | 290 | // fill 291 | template 292 | void CTensor4D::fill(const T aValue) { 293 | int wholeSize = mXSize*mYSize*mZSize*mASize; 294 | for (register int i = 0; i < wholeSize; i++) 295 | mData[i] = aValue; 296 | } 297 | 298 | // cut 299 | template 300 | void CTensor4D::cut(CTensor4D& aResult, int x1, int y1, int z1, int a1, int x2, int y2, int z2, int a2) { 301 | aResult.mXSize = x2-x1+1; 302 | aResult.mYSize = y2-y1+1; 303 | aResult.mZSize = z2-z1+1; 304 | aResult.mASize = a2-a1+1; 305 | delete[] aResult.mData; 306 | aResult.mData = new T[aResult.mXSize*aResult.mYSize*aResult.mZSize*aResult.mASize]; 307 | for (int a = a1; a <= a2; a++) 308 | for (int z = z1; z <= z2; z++) 309 | for (int y = y1; y <= y2; y++) 310 | for (int x = x1; x <= x2; x++) 311 | aResult(x-x1,y-y1,z-z1,a-a1) = operator()(x,y,z,a); 312 | } 313 | 314 | // readFromFile 315 | template 316 | void CTensor4D::readFromFile(char* aFilename) { 317 | if (mData != 0) delete[] mData; 318 | std::string s; 319 | std::string aPath = aFilename; 320 | aPath.erase(aPath.find_last_of('\\')+1,100); 321 | mASize = 0; 322 | { 323 | std::ifstream aStream(aFilename); 324 | while (!aStream.eof()) { 325 | aStream >> s; 326 | if (s != "") { 327 | mASize++; 328 | if (mASize == 1) { 329 | s.erase(0,s.find_last_of('.')); 330 | if (s == ".ppm" || s == ".PPM") mZSize = 3; 331 | else if (s == ".pgm" || s == ".PGM") mZSize = 1; 332 | else throw ETensor4DInvalidFileFormat(); 333 | } 334 | } 335 | } 336 | } 337 | std::ifstream aStream(aFilename); 338 | aStream >> s; 339 | s = aPath+s; 340 | // PGM 341 | if (mZSize == 1) { 342 | CMatrix aTemp; 343 | aTemp.readFromPGM(s.c_str()); 344 | mXSize = aTemp.xSize(); 345 | mYSize = aTemp.ySize(); 346 | int aSize = mXSize*mYSize; 347 | mData = new T[aSize*mASize]; 348 | for (int i = 0; i < aSize; i++) 349 | mData[i] = aTemp.data()[i]; 350 | for (int a = 1; a < mASize; a++) { 351 | aStream >> s; 352 | s = aPath+s; 353 | aTemp.readFromPGM(s.c_str()); 354 | for (int i = 0; i < aSize; i++) 355 | mData[i+a*aSize] = aTemp.data()[i]; 356 | } 357 | } 358 | // PPM 359 | else { 360 | CTensor aTemp; 361 | aTemp.readFromPPM(s.c_str()); 362 | mXSize = aTemp.xSize(); 363 | mYSize = aTemp.ySize(); 364 | int aSize = 3*mXSize*mYSize; 365 | mData = new T[aSize*mASize]; 366 | for (int i = 0; i < aSize; i++) 367 | mData[i] = aTemp.data()[i]; 368 | for (int a = 1; a < mASize; a++) { 369 | aStream >> s; 370 | s = aPath+s; 371 | aTemp.readFromPPM(s.c_str()); 372 | for (int i = 0; i < aSize; i++) 373 | mData[i+a*aSize] = aTemp.data()[i]; 374 | } 375 | } 376 | } 377 | 378 | // writeToPPM 379 | template 380 | void CTensor4D::writeToPPM(const char* aFilename, int aCols, int aRows) { 381 | int rows = (int)floor(sqrt(mASize)); 382 | if (aRows != 0) rows = aRows; 383 | int cols = (int)ceil(mASize*1.0/rows); 384 | if (aCols != 0) cols = aCols; 385 | FILE* outimage = fopen(aFilename, "wb"); 386 | fprintf(outimage, "P6 \n"); 387 | fprintf(outimage, "%ld %ld \n255\n", cols*mXSize,rows*mYSize); 388 | for (int r = 0; r < rows; r++) 389 | for (int y = 0; y < mYSize; y++) 390 | for (int c = 0; c < cols; c++) 391 | for (int x = 0; x < mXSize; x++) { 392 | unsigned char aHelp; 393 | if (r*cols+c >= mASize) aHelp = 0; 394 | else aHelp = (unsigned char)operator()(x,y,0,r*cols+c); 395 | fwrite (&aHelp, sizeof(unsigned char), 1, outimage); 396 | if (r*cols+c >= mASize) aHelp = 0; 397 | else aHelp = (unsigned char)operator()(x,y,1,r*cols+c); 398 | fwrite (&aHelp, sizeof(unsigned char), 1, outimage); 399 | if (r*cols+c >= mASize) aHelp = 0; 400 | else aHelp = (unsigned char)operator()(x,y,2,r*cols+c); 401 | fwrite (&aHelp, sizeof(unsigned char), 1, outimage); 402 | } 403 | fclose(outimage); 404 | } 405 | 406 | // operator () 407 | template 408 | inline T& CTensor4D::operator()(const int ax, const int ay, const int az, const int aa) const { 409 | #ifdef DEBUG 410 | if (ax >= mXSize || ay >= mYSize || az >= mZSize || aa >= mASize || ax < 0 || ay < 0 || az < 0 || aa < 0) 411 | throw ETensorRangeOverflow(ax,ay,az,aa); 412 | #endif 413 | return mData[mXSize*(mYSize*(mZSize*aa+az)+ay)+ax]; 414 | } 415 | 416 | template 417 | CVector CTensor4D::operator()(const float ax, const float ay, const int aa) const { 418 | CVector aResult(mZSize); 419 | int x1 = (int)ax; 420 | int y1 = (int)ay; 421 | int x2 = x1+1; 422 | int y2 = y1+1; 423 | #ifdef _DEBUG 424 | if (x2 >= mXSize || y2 >= mYSize || x1 < 0 || y1 < 0) throw ETensorRangeOverflow(ax,ay,0); 425 | #endif 426 | float alphaX = ax-x1; float alphaXTrans = 1.0-alphaX; 427 | float alphaY = ay-y1; float alphaYTrans = 1.0-alphaY; 428 | for (int k = 0; k < mZSize; k++) { 429 | float a = alphaXTrans*operator()(x1,y1,k,aa)+alphaX*operator()(x2,y1,k,aa); 430 | float b = alphaXTrans*operator()(x1,y2,k,aa)+alphaX*operator()(x2,y2,k,aa); 431 | aResult(k) = alphaYTrans*a+alphaY*b; 432 | } 433 | return aResult; 434 | } 435 | 436 | // operator = 437 | template 438 | inline CTensor4D& CTensor4D::operator=(const T aValue) { 439 | fill(aValue); 440 | return *this; 441 | } 442 | 443 | template 444 | CTensor4D& CTensor4D::operator=(const CTensor4D& aCopyFrom) { 445 | if (this != &aCopyFrom) { 446 | if (mData != 0) delete[] mData; 447 | mXSize = aCopyFrom.mXSize; 448 | mYSize = aCopyFrom.mYSize; 449 | mZSize = aCopyFrom.mZSize; 450 | mASize = aCopyFrom.mASize; 451 | int wholeSize = mXSize*mYSize*mZSize*mASize; 452 | mData = new T[wholeSize]; 453 | for (register int i = 0; i < wholeSize; i++) 454 | mData[i] = aCopyFrom.mData[i]; 455 | } 456 | return *this; 457 | } 458 | 459 | // operator *= 460 | template 461 | CTensor4D& CTensor4D::operator*=(const T aValue) { 462 | int wholeSize = mXSize*mYSize*mZSize*mASize; 463 | for (int i = 0; i < wholeSize; i++) 464 | mData[i] *= aValue; 465 | return *this; 466 | } 467 | 468 | // operator += 469 | template 470 | CTensor4D& CTensor4D::operator+=(const CTensor4D& aTensor) { 471 | #ifdef _DEBUG 472 | if (mXSize != aTensor.mXSize || mYSize != aTensor.mYSize || mZSize != aTensor.mZSize || mASize != aTensor.mASize) 473 | throw ETensorIncompatibleSize(mXSize,mYSize,mZSize); 474 | #endif 475 | int wholeSize = size(); 476 | for (int i = 0; i < wholeSize; i++) 477 | mData[i] += aTensor.mData[i]; 478 | return *this; 479 | } 480 | 481 | // xSize 482 | template 483 | inline int CTensor4D::xSize() const { 484 | 485 | return mXSize; 486 | } 487 | 488 | // ySize 489 | template 490 | inline int CTensor4D::ySize() const { 491 | return mYSize; 492 | } 493 | 494 | // zSize 495 | template 496 | inline int CTensor4D::zSize() const { 497 | return mZSize; 498 | } 499 | 500 | // aSize 501 | template 502 | inline int CTensor4D::aSize() const { 503 | return mASize; 504 | } 505 | 506 | // size 507 | template 508 | inline int CTensor4D::size() const { 509 | return mXSize*mYSize*mZSize*mASize; 510 | } 511 | 512 | // getTensor3D 513 | template 514 | CTensor CTensor4D::getTensor3D(const int aa) const { 515 | CTensor aTemp(mXSize,mYSize,mZSize); 516 | int aTensorSize = mXSize*mYSize*mZSize; 517 | int aOffset = aa*aTensorSize; 518 | for (int i = 0; i < aTensorSize; i++) 519 | aTemp.data()[i] = mData[i+aOffset]; 520 | return aTemp; 521 | } 522 | 523 | // getTensor3D 524 | template 525 | void CTensor4D::getTensor3D(CTensor& aTensor, int aIndex, int aDim) const { 526 | int aSize; 527 | int aOffset; 528 | switch (aDim) { 529 | case 3: 530 | if (aTensor.xSize() != mXSize || aTensor.ySize() != mYSize || aTensor.zSize() != mZSize) 531 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mXSize,mYSize,mZSize); 532 | aSize = mXSize*mYSize*mZSize; 533 | aOffset = aIndex*aSize; 534 | for (int i = 0; i < aSize; i++) 535 | aTensor.data()[i] = mData[i+aOffset]; 536 | break; 537 | case 2: 538 | if (aTensor.xSize() != mXSize || aTensor.ySize() != mYSize || aTensor.zSize() != mASize) 539 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mXSize,mYSize,mASize); 540 | aSize = mXSize*mYSize; 541 | aOffset = aIndex*aSize; 542 | for (int a = 0; a < mASize; a++) 543 | for (int i = 0; i < aSize; i++) 544 | aTensor.data()[i+a*aSize] = mData[i+aOffset+a*aSize*mZSize]; 545 | break; 546 | case 1: 547 | if (aTensor.xSize() != mXSize || aTensor.ySize() != mZSize || aTensor.zSize() != mASize) 548 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mXSize,mZSize,mASize); 549 | for (int a = 0; a < mASize; a++) 550 | for (int z = 0; z < mZSize; z++) 551 | for (int x = 0; x < mXSize; x++) 552 | aTensor(x,z,a) = operator()(x,aIndex,z,a); 553 | break; 554 | case 0: 555 | if (aTensor.xSize() != mYSize || aTensor.ySize() != mZSize || aTensor.zSize() != mASize) 556 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mYSize,mZSize,mASize); 557 | for (int a = 0; a < mASize; a++) 558 | for (int z = 0; z < mZSize; z++) 559 | for (int y = 0; y < mYSize; y++) 560 | aTensor(y,z,a) = operator()(aIndex,y,z,a); 561 | break; 562 | default: getTensor3D(aTensor,aIndex); 563 | } 564 | } 565 | 566 | // putTensor3D 567 | template 568 | void CTensor4D::putTensor3D(CTensor& aTensor, int aIndex, int aDim) { 569 | int aSize; 570 | int aOffset; 571 | switch (aDim) { 572 | case 3: 573 | if (aTensor.xSize() != mXSize || aTensor.ySize() != mYSize || aTensor.zSize() != mZSize) 574 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mXSize,mYSize,mZSize); 575 | aSize = mXSize*mYSize*mZSize; 576 | aOffset = aIndex*aSize; 577 | for (int i = 0; i < aSize; i++) 578 | mData[i+aOffset] = aTensor.data()[i]; 579 | break; 580 | case 2: 581 | if (aTensor.xSize() != mXSize || aTensor.ySize() != mYSize || aTensor.zSize() != mASize) 582 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mXSize,mYSize,mASize); 583 | aSize = mXSize*mYSize; 584 | aOffset = aIndex*aSize; 585 | for (int a = 0; a < mASize; a++) 586 | for (int i = 0; i < aSize; i++) 587 | mData[i+aOffset+a*aSize*mZSize] = aTensor.data()[i+a*aSize]; 588 | break; 589 | case 1: 590 | if (aTensor.xSize() != mXSize || aTensor.ySize() != mZSize || aTensor.zSize() != mASize) 591 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mXSize,mZSize,mASize); 592 | for (int a = 0; a < mASize; a++) 593 | for (int z = 0; z < mZSize; z++) 594 | for (int x = 0; x < mXSize; x++) 595 | operator()(x,aIndex,z,a) = aTensor(x,z,a); 596 | break; 597 | case 0: 598 | if (aTensor.xSize() != mYSize || aTensor.ySize() != mZSize || aTensor.zSize() != mASize) 599 | throw ETensor4DIncompatibleSize(aTensor.xSize(),aTensor.ySize(),aTensor.zSize(),mYSize,mZSize,mASize); 600 | for (int a = 0; a < mASize; a++) 601 | for (int z = 0; z < mZSize; z++) 602 | for (int y = 0; y < mYSize; y++) 603 | operator()(aIndex,y,z,a) = aTensor(y,z,a); 604 | break; 605 | default: putTensor3D(aTensor,aIndex); 606 | } 607 | } 608 | 609 | // getMatrix 610 | template 611 | void CTensor4D::getMatrix(CMatrix& aMatrix, int aZIndex, int aAIndex) const { 612 | if (aMatrix.xSize() != mXSize || aMatrix.ySize() != mYSize) 613 | throw ETensor4DIncompatibleSize(aMatrix.xSize(),aMatrix.ySize(),1,mXSize,mYSize,1); 614 | int aSize = mXSize*mYSize; 615 | int aOffset = aSize*(aAIndex*mZSize+aZIndex); 616 | for (int i = 0; i < aSize; i++) 617 | aMatrix.data()[i] = mData[i+aOffset]; 618 | } 619 | 620 | // putMatrix 621 | template 622 | void CTensor4D::putMatrix(CMatrix& aMatrix, int aZIndex, int aAIndex) { 623 | if (aMatrix.xSize() != mXSize || aMatrix.ySize() != mYSize) 624 | throw ETensor4DIncompatibleSize(aMatrix.xSize(),aMatrix.ySize(),1,mXSize,mYSize,1); 625 | int aSize = mXSize*mYSize; 626 | int aOffset = aSize*(aAIndex*mZSize+aZIndex); 627 | for (int i = 0; i < aSize; i++) 628 | mData[i+aOffset] = aMatrix.data()[i]; 629 | } 630 | 631 | // data() 632 | template 633 | inline T* CTensor4D::data() const { 634 | return mData; 635 | } 636 | 637 | // N O N - M E M B E R F U N C T I O N S -------------------------------------- 638 | 639 | // operator << 640 | template 641 | std::ostream& operator<<(std::ostream& aStream, const CTensor4D& aTensor) { 642 | for (int a = 0; a < aTensor.aSize(); a++) { 643 | for (int z = 0; z < aTensor.zSize(); z++) { 644 | for (int y = 0; y < aTensor.ySize(); y++) { 645 | for (int x = 0; x < aTensor.xSize(); x++) 646 | aStream << aTensor(x,y,z) << ' '; 647 | aStream << std::endl; 648 | } 649 | aStream << std::endl; 650 | } 651 | aStream << std::endl; 652 | } 653 | return aStream; 654 | } 655 | 656 | #endif 657 | -------------------------------------------------------------------------------- /video_input/consistencyChecker/CVector.h: -------------------------------------------------------------------------------- 1 | // CVector 2 | // A one-dimensional array including basic vector operations 3 | // 4 | // Author: Thomas Brox 5 | // Last change: 23.05.2005 6 | //------------------------------------------------------------------------- 7 | #ifndef CVECTOR_H 8 | #define CVECTOR_H 9 | 10 | #include 11 | #include 12 | 13 | template class CMatrix; 14 | template class CTensor; 15 | 16 | template 17 | class CVector { 18 | public: 19 | // constructor 20 | inline CVector(); 21 | // constructor 22 | inline CVector(const int aSize); 23 | // copy constructor 24 | CVector(const CVector& aCopyFrom); 25 | // constructor (from array) 26 | CVector(const T* aPointer, const int aSize); 27 | // constructor with implicit filling 28 | CVector(const int aSize, const T aFillValue); 29 | // destructor 30 | virtual ~CVector(); 31 | 32 | // Changes the size of the vector (data is lost) 33 | void setSize(int aSize); 34 | // Fills the vector with the specified value (see also operator=) 35 | void fill(const T aValue); 36 | // Appends the values of another vector 37 | void append(CVector& aVector); 38 | // Normalizes the length of the vector to 1 39 | void normalize(); 40 | // Normalizes the component sum to 1 41 | void normalizeSum(); 42 | // Reads values from a text file 43 | void readFromTXT(const char* aFilename); 44 | // Writes values to a text file 45 | void writeToTXT(char* aFilename); 46 | // Returns the sum of all values 47 | T sum(); 48 | // Returns the minimum value 49 | T min(); 50 | // Returns the maximum value 51 | T max(); 52 | // Returns the Euclidean norm 53 | T norm(); 54 | 55 | // Converts vector to homogeneous coordinates, i.e., all components are divided by last component 56 | CVector& homogen(); 57 | // Remove the last component 58 | inline void homogen_nD(); 59 | // Computes the cross product between this vector and aVector 60 | void cross(CVector& aVector); 61 | 62 | // Gives full access to the vector's values 63 | inline T& operator()(const int aIndex) const; 64 | inline T& operator[](const int aIndex) const; 65 | // Fills the vector with the specified value (equivalent to fill) 66 | inline CVector& operator=(const T aValue); 67 | // Copies a vector into this vector (size might change) 68 | CVector& operator=(const CVector& aCopyFrom); 69 | // Copies values from a matrix to the vector (size might change) 70 | CVector& operator=(const CMatrix& aCopyFrom); 71 | // Copies values from a tensor to the vector (size might change) 72 | CVector& operator=(const CTensor& aCopyFrom); 73 | // Adds another vector 74 | CVector& operator+=(const CVector& aVector); 75 | // Substracts another vector 76 | CVector& operator-=(const CVector& aVector); 77 | // Multiplies the vector with a scalar 78 | CVector& operator*=(const T aValue); 79 | // Scalar product 80 | T operator*=(const CVector& aVector); 81 | // Checks (non-)equivalence to another vector 82 | bool operator==(const CVector& aVector); 83 | inline bool operator!=(const CVector& aVector); 84 | 85 | // Gives access to the vector's size 86 | inline int size() const; 87 | // Gives access to the internal data representation 88 | inline T* data() const {return mData;} 89 | protected: 90 | int mSize; 91 | T* mData; 92 | }; 93 | 94 | // Adds two vectors 95 | template CVector operator+(const CVector& vec1, const CVector& vec2); 96 | // Substracts two vectors 97 | template CVector operator-(const CVector& vec1, const CVector& vec2); 98 | // Multiplies vector with a scalar 99 | template CVector operator*(const CVector& aVector, const T aValue); 100 | template CVector operator*(const T aValue, const CVector& aVector); 101 | // Computes the scalar product of two vectors 102 | template T operator*(const CVector& vec1, const CVector& vec2); 103 | // Computes cross product of two vectors 104 | template CVector operator/(const CVector& vec1, const CVector& vec2); 105 | // Sends the vector to an output stream 106 | template std::ostream& operator<<(std::ostream& aStream, const CVector& aVector); 107 | 108 | // Exceptions thrown by CVector-------------------------------------------- 109 | 110 | // Thrown if one tries to access an element of a vector which is out of 111 | // the vector's bounds 112 | struct EVectorRangeOverflow { 113 | EVectorRangeOverflow(const int aIndex) { 114 | using namespace std; 115 | cerr << "Exception EVectorRangeOverflow: Index = " << aIndex << endl; 116 | } 117 | }; 118 | 119 | struct EVectorIncompatibleSize { 120 | EVectorIncompatibleSize(int aSize1, int aSize2) { 121 | using namespace std; 122 | cerr << "Exception EVectorIncompatibleSize: " << aSize1 << " <> " << aSize2 << endl; 123 | } 124 | }; 125 | 126 | 127 | // I M P L E M E N T A T I O N -------------------------------------------- 128 | // 129 | // You might wonder why there is implementation code in a header file. 130 | // The reason is that not all C++ compilers yet manage separate compilation 131 | // of templates. Inline functions cannot be compiled separately anyway. 132 | // So in this case the whole implementation code is added to the header 133 | // file. 134 | // Users of CVector should ignore everything that's beyond this line. 135 | // ------------------------------------------------------------------------ 136 | 137 | // P U B L I C ------------------------------------------------------------ 138 | // constructor 139 | template 140 | inline CVector::CVector() : mSize(0) { 141 | mData = new T[0]; 142 | } 143 | 144 | // constructor 145 | template 146 | inline CVector::CVector(const int aSize) 147 | : mSize(aSize) { 148 | mData = new T[aSize]; 149 | } 150 | 151 | // copy constructor 152 | template 153 | CVector::CVector(const CVector& aCopyFrom) 154 | : mSize(aCopyFrom.mSize) { 155 | mData = new T[mSize]; 156 | for (int i = 0; i < mSize; i++) 157 | mData[i] = aCopyFrom.mData[i]; 158 | } 159 | 160 | // constructor (from array) 161 | template 162 | CVector::CVector(const T* aPointer, const int aSize) 163 | : mSize(aSize) { 164 | mData = new T[mSize]; 165 | for (int i = 0; i < mSize; i++) 166 | mData[i] = aPointer[i]; 167 | } 168 | 169 | // constructor with implicit filling 170 | template 171 | CVector::CVector(const int aSize, const T aFillValue) 172 | : mSize(aSize) { 173 | mData = new T[aSize]; 174 | fill(aFillValue); 175 | } 176 | 177 | // destructor 178 | template 179 | CVector::~CVector() { 180 | delete[] mData; 181 | } 182 | 183 | // setSize 184 | template 185 | void CVector::setSize(int aSize) { 186 | if (mData != 0) delete[] mData; 187 | mData = new T[aSize]; 188 | mSize = aSize; 189 | } 190 | 191 | // fill 192 | template 193 | void CVector::fill(const T aValue) { 194 | for (register int i = 0; i < mSize; i++) 195 | mData[i] = aValue; 196 | } 197 | 198 | // append 199 | template 200 | void CVector::append(CVector& aVector) { 201 | T* aNewData = new T[mSize+aVector.size()]; 202 | for (int i = 0; i < mSize; i++) 203 | aNewData[i] = mData[i]; 204 | for (int i = 0; i < aVector.size(); i++) 205 | aNewData[i+mSize] = aVector(i); 206 | mSize += aVector.size(); 207 | delete[] mData; 208 | mData = aNewData; 209 | } 210 | 211 | // normalize 212 | template 213 | void CVector::normalize() { 214 | T aSum = 0; 215 | for (register int i = 0; i < mSize; i++) 216 | aSum += mData[i]*mData[i]; 217 | if (aSum == 0) return; 218 | aSum = 1.0/sqrt(aSum); 219 | for (register int i = 0; i < mSize; i++) 220 | mData[i] *= aSum; 221 | } 222 | 223 | // normalizeSum 224 | template 225 | void CVector::normalizeSum() { 226 | T aSum = 0; 227 | for (register int i = 0; i < mSize; i++) 228 | aSum += mData[i]; 229 | if (aSum == 0) return; 230 | aSum = 1.0/aSum; 231 | for (register int i = 0; i < mSize; i++) 232 | mData[i] *= aSum; 233 | } 234 | 235 | // readFromTXT 236 | template 237 | void CVector::readFromTXT(const char* aFilename) { 238 | std::ifstream aStream(aFilename); 239 | mSize = 0; 240 | float aDummy; 241 | while (!aStream.eof()) { 242 | aStream >> aDummy; 243 | mSize++; 244 | } 245 | aStream.close(); 246 | std::ifstream aStream2(aFilename); 247 | delete mData; 248 | mData = new T[mSize]; 249 | for (int i = 0; i < mSize; i++) 250 | aStream2 >> mData[i]; 251 | } 252 | 253 | // writeToTXT 254 | template 255 | void CVector::writeToTXT(char* aFilename) { 256 | std::ofstream aStream(aFilename); 257 | for (int i = 0; i < mSize; i++) 258 | aStream << mData[i] << std::endl; 259 | } 260 | 261 | // sum 262 | template 263 | T CVector::sum() { 264 | T val = mData[0]; 265 | for (int i = 1; i < mSize; i++) 266 | val += mData[i]; 267 | return val; 268 | } 269 | 270 | // min 271 | template 272 | T CVector::min() { 273 | T bestValue = mData[0]; 274 | for (int i = 1; i < mSize; i++) 275 | if (mData[i] < bestValue) bestValue = mData[i]; 276 | return bestValue; 277 | } 278 | 279 | // max 280 | template 281 | T CVector::max() { 282 | T bestValue = mData[0]; 283 | for (int i = 1; i < mSize; i++) 284 | if (mData[i] > bestValue) bestValue = mData[i]; 285 | return bestValue; 286 | } 287 | 288 | // norm 289 | template 290 | T CVector::norm() { 291 | T aSum = 0.0; 292 | for (int i = 0; i < mSize; i++) 293 | aSum += mData[i]*mData[i]; 294 | return sqrt(aSum); 295 | } 296 | 297 | // homogen 298 | template 299 | CVector& CVector::homogen() { 300 | if (mSize > 1 && mData[mSize-1] != 0) { 301 | T invVal = 1.0/mData[mSize-1]; 302 | for (int i = 0; i < mSize; i++) 303 | mData[i] *= invVal; 304 | } 305 | return (*this); 306 | } 307 | 308 | // homogen_nD 309 | template 310 | inline void CVector::homogen_nD() { 311 | mSize--; 312 | } 313 | 314 | // cross 315 | template 316 | void CVector::cross(CVector& aVector) { 317 | T aHelp0 = aVector(2)*mData[1] - aVector(1)*mData[2]; 318 | T aHelp1 = aVector(0)*mData[2] - aVector(2)*mData[0]; 319 | T aHelp2 = aVector(1)*mData[0] - aVector(0)*mData[1]; 320 | mData[0] = aHelp0; 321 | mData[1] = aHelp1; 322 | mData[2] = aHelp2; 323 | } 324 | 325 | // operator() 326 | template 327 | inline T& CVector::operator()(const int aIndex) const { 328 | #ifdef _DEBUG 329 | if (aIndex >= mSize || aIndex < 0) 330 | throw EVectorRangeOverflow(aIndex); 331 | #endif 332 | return mData[aIndex]; 333 | } 334 | 335 | // operator[] 336 | template 337 | inline T& CVector::operator[](const int aIndex) const { 338 | return operator()(aIndex); 339 | } 340 | 341 | // operator= 342 | template 343 | inline CVector& CVector::operator=(const T aValue) { 344 | fill(aValue); 345 | return *this; 346 | } 347 | 348 | template 349 | CVector& CVector::operator=(const CVector& aCopyFrom) { 350 | if (this != &aCopyFrom) { 351 | if (mSize != aCopyFrom.size()) { 352 | delete[] mData; 353 | mSize = aCopyFrom.size(); 354 | mData = new T[mSize]; 355 | } 356 | for (register int i = 0; i < mSize; i++) 357 | mData[i] = aCopyFrom.mData[i]; 358 | } 359 | return *this; 360 | } 361 | 362 | template 363 | CVector& CVector::operator=(const CMatrix& aCopyFrom) { 364 | if (mSize != aCopyFrom.size()) { 365 | delete[] mData; 366 | mSize = aCopyFrom.size(); 367 | mData = new T[mSize]; 368 | } 369 | for (register int i = 0; i < mSize; i++) 370 | mData[i] = aCopyFrom.data()[i]; 371 | return *this; 372 | } 373 | 374 | template 375 | CVector& CVector::operator=(const CTensor& aCopyFrom) { 376 | if (mSize != aCopyFrom.size()) { 377 | delete[] mData; 378 | mSize = aCopyFrom.size(); 379 | mData = new T[mSize]; 380 | } 381 | for (register int i = 0; i < mSize; i++) 382 | mData[i] = aCopyFrom.data()[i]; 383 | return *this; 384 | } 385 | 386 | // operator += 387 | template 388 | CVector& CVector::operator+=(const CVector& aVector) { 389 | #ifdef _DEBUG 390 | if (mSize != aVector.size()) throw EVectorIncompatibleSize(mSize,aVector.size()); 391 | #endif 392 | for (int i = 0; i < mSize; i++) 393 | mData[i] += aVector(i); 394 | return *this; 395 | } 396 | 397 | // operator -= 398 | template 399 | CVector& CVector::operator-=(const CVector& aVector) { 400 | #ifdef _DEBUG 401 | if (mSize != aVector.size()) throw EVectorIncompatibleSize(mSize,aVector.size()); 402 | #endif 403 | for (int i = 0; i < mSize; i++) 404 | mData[i] -= aVector(i); 405 | return *this; 406 | } 407 | 408 | // operator *= 409 | template 410 | CVector& CVector::operator*=(const T aValue) { 411 | for (int i = 0; i < mSize; i++) 412 | mData[i] *= aValue; 413 | return *this; 414 | } 415 | 416 | template 417 | T CVector::operator*=(const CVector& aVector) { 418 | #ifdef _DEBUG 419 | if (mSize != aVector.size()) throw EVectorIncompatibleSize(mSize,aVector.size()); 420 | #endif 421 | T aSum = 0.0; 422 | for (int i = 0; i < mSize; i++) 423 | aSum += mData[i]*aVector(i); 424 | return aSum; 425 | } 426 | 427 | // operator == 428 | template 429 | bool CVector::operator==(const CVector& aVector) { 430 | if (mSize != aVector.size()) return false; 431 | int i = 0; 432 | while (i < mSize && aVector(i) == mData[i]) 433 | i++; 434 | return (i == mSize); 435 | } 436 | 437 | // operator != 438 | template 439 | inline bool CVector::operator!=(const CVector& aVector) { 440 | return !((*this)==aVector); 441 | } 442 | 443 | // size 444 | template 445 | inline int CVector::size() const { 446 | return mSize; 447 | } 448 | 449 | // N O N - M E M B E R F U N C T I O N S ------------------------------------- 450 | 451 | // operator + 452 | template 453 | CVector operator+(const CVector& vec1, const CVector& vec2) { 454 | #ifdef _DEBUG 455 | if (vec1.size() != vec2.size()) throw EVectorIncompatibleSize(vec1.size(),vec2.size()); 456 | #endif 457 | CVector result(vec1.size()); 458 | for (int i = 0; i < vec1.size(); i++) 459 | result(i) = vec1[i]+vec2[i]; 460 | return result; 461 | } 462 | 463 | // operator - 464 | template 465 | CVector operator-(const CVector& vec1, const CVector& vec2) { 466 | #ifdef _DEBUG 467 | if (vec1.size() != vec2.size()) throw EVectorIncompatibleSize(vec1.size(),vec2.size()); 468 | #endif 469 | CVector result(vec1.size()); 470 | for (int i = 0; i < vec1.size(); i++) 471 | result(i) = vec1(i)-vec2(i); 472 | return result; 473 | } 474 | 475 | // operator * 476 | template 477 | CVector operator*(const T aValue, const CVector& aVector) { 478 | CVector result(aVector.size()); 479 | for (int i = 0; i < aVector.size(); i++) 480 | result(i) = aValue*aVector(i); 481 | return result; 482 | } 483 | 484 | template 485 | CVector operator*(const CVector& aVector, const T aValue) { 486 | return operator*(aValue,aVector); 487 | } 488 | 489 | template 490 | T operator*(const CVector& vec1, const CVector& vec2) { 491 | #ifdef _DEBUG 492 | if (vec1.size() != vec2.size()) throw EVectorIncompatibleSize(vec1.size(),vec2.size()); 493 | #endif 494 | T aSum = 0.0; 495 | for (int i = 0; i < vec1.size(); i++) 496 | aSum += vec1(i)*vec2(i); 497 | return aSum; 498 | } 499 | 500 | // operator / 501 | template 502 | CVector operator/(const CVector& vec1, const CVector& vec2) { 503 | CVector result(3); 504 | result[0]=vec1[1]*vec2[2] - vec1[2]*vec2[1]; 505 | result[1]=vec1[2]*vec2[0] - vec1[0]*vec2[2]; 506 | result[2]=vec1[0]*vec2[1] - vec1[1]*vec2[0]; 507 | return result; 508 | } 509 | 510 | // operator << 511 | template 512 | std::ostream& operator<<(std::ostream& aStream, const CVector& aVector) { 513 | for (int i = 0; i < aVector.size(); i++) 514 | aStream << aVector(i) << '|'; 515 | aStream << std::endl; 516 | return aStream; 517 | } 518 | 519 | #endif 520 | -------------------------------------------------------------------------------- /video_input/consistencyChecker/Makefile: -------------------------------------------------------------------------------- 1 | default: 2 | g++ -O3 -fPIC consistencyChecker.cpp NMath.cpp -I. -o consistencyChecker -L. 3 | 4 | -------------------------------------------------------------------------------- /video_input/consistencyChecker/NMath.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/video_input/consistencyChecker/NMath.cpp -------------------------------------------------------------------------------- /video_input/consistencyChecker/NMath.h: -------------------------------------------------------------------------------- 1 | // NMath 2 | // A collection of mathematical functions and numerical algorithms 3 | // 4 | // Author: Thomas Brox 5 | 6 | #ifndef NMathH 7 | #define NMathH 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace NMath { 15 | // Returns the faculty of a number 16 | int faculty(int n); 17 | // Computes the binomial coefficient of two numbers 18 | int binCoeff(const int n, const int k); 19 | // Returns the angle of the line connecting (x1,y1) with (y1,y2) 20 | float tangent(const float x1, const float y1, const float x2, const float y2); 21 | // Absolute for floating points 22 | inline float abs(const float aValue); 23 | // Computes min or max value of two numbers 24 | inline float min(float aVal1, float aVal2); 25 | inline float max(float aVal1, float aVal2); 26 | inline int min(int aVal1, int aVal2); 27 | inline int max(int aVal1, int aVal2); 28 | // Computes the sign of a value 29 | inline float sign(float aVal); 30 | // minmod function (see description in implementation) 31 | inline float minmod(float a, float b, float c); 32 | // Computes the difference between two angles respecting the cyclic property of an angle 33 | // The result is always between 0 and Pi 34 | float absAngleDifference(const float aFirstAngle, const float aSecondAngle); 35 | // Computes the difference between two angles aFirstAngle - aSecondAngle 36 | // respecting the cyclic property of an angle 37 | // The result ist between -Pi and Pi 38 | float angleDifference(const float aFirstAngle, const float aSecondAngle); 39 | // Computes the sum of two angles respecting the cyclic property of an angle 40 | // The result is between -Pi and Pi 41 | float angleSum(const float aFirstAngle, const float aSecondAngle); 42 | // Rounds to the nearest integer 43 | int round(const float aValue); 44 | // Computes the arctan with results between 0 and 2*Pi 45 | inline float arctan(float x, float y); 46 | 47 | // Computes [0,1] uniformly distributed random number 48 | inline float random(); 49 | // Computes N(0,1) distributed random number 50 | inline float randomGauss(); 51 | 52 | extern const float Pi; 53 | 54 | // Computes a principal axis transformation 55 | // Eigenvectors are in the rows of aEigenvectors 56 | void PATransformation(const CMatrix& aMatrix, CVector& aEigenvalues, CMatrix& aEigenvectors, bool aOrdering = true); 57 | // Computes the principal axis backtransformation 58 | void PABacktransformation(const CMatrix& aEigenVectors, const CVector& aEigenValues, CMatrix& aMatrix); 59 | // Computes a singular value decomposition A=USV^T 60 | // Input: U MxN matrix 61 | // Output: U MxN matrix, S NxN diagonal matrix, V NxN diagonal matrix 62 | void svd(CMatrix& U, CMatrix& S, CMatrix& V, bool aOrdering = true, int aIterations = 20); 63 | // Reassembles A = USV^T, Result in U 64 | void svdBack(CMatrix& U, const CMatrix& S, const CMatrix& V); 65 | // Applies the Householder method to A and b, i.e., A is transformed into an upper triangular matrix 66 | void householder(CMatrix& A, CVector& b); 67 | // Computes least squares solution of an overdetermined linear system Ax=b using the Householder method 68 | CVector leastSquares(CMatrix& A, CVector& b); 69 | // Inverts a square matrix by eigenvalue decomposition, 70 | // eigenvalues smaller than aReg are replaced by aReg 71 | void invRegularized(CMatrix& A, int aReg); 72 | // Given a positive-definite symmetric matrix A, this routine constructs A = LL^T. 73 | // Only the upper triangle of A need be given. L is returned in the lower triangle. 74 | void cholesky(CMatrix& A); 75 | // Solves L*aOut = aIn when L is a lower triangular matrix (e.g. result from cholesky) 76 | void triangularSolve(CMatrix& L, CVector& aIn, CVector& aOut); 77 | void triangularSolve(CMatrix& L, CMatrix& aIn, CMatrix& aOut); 78 | // Solves L^T*aOut = aIn when L is a lower triangular matrix (e.g. result from cholesky) 79 | void triangularSolveTransposed(CMatrix& L, CVector& aIn, CVector& aOut); 80 | void triangularSolveTransposed(CMatrix& L, CMatrix& aIn, CMatrix& aOut); 81 | // Computes the inverse of a matrix, given its cholesky decomposition L (lower triangle) 82 | void choleskyInv(const CMatrix& L, CMatrix& aInv); 83 | // Creates the rotation matrix RzRyRx and extends it to a 4x4 RBM matrix with translation 0 84 | void eulerAngles(float rx, float ry, float rz, CMatrix& A); 85 | // Transforms a rigid body motion in matrix representation to a twist representation 86 | void RBM2Twist(CVector &T, CMatrix& RBM); 87 | } 88 | 89 | // I M P L E M E N T A T I O N ------------------------------------------------- 90 | // Inline functions have to be implemented directly in the header file 91 | 92 | namespace NMath { 93 | 94 | // abs 95 | inline float abs(const float aValue) { 96 | if (aValue >= 0) return aValue; 97 | else return -aValue; 98 | } 99 | 100 | // min 101 | inline float min(float aVal1, float aVal2) { 102 | if (aVal1 < aVal2) return aVal1; 103 | else return aVal2; 104 | } 105 | 106 | // max 107 | inline float max(float aVal1, float aVal2) { 108 | if (aVal1 > aVal2) return aVal1; 109 | else return aVal2; 110 | } 111 | 112 | // min 113 | inline int min(int aVal1, int aVal2) { 114 | if (aVal1 < aVal2) return aVal1; 115 | else return aVal2; 116 | } 117 | 118 | // max 119 | inline int max(int aVal1, int aVal2) { 120 | if (aVal1 > aVal2) return aVal1; 121 | else return aVal2; 122 | } 123 | 124 | // sign 125 | inline float sign(float aVal) { 126 | if (aVal > 0) return 1.0; 127 | else return -1.0; 128 | } 129 | 130 | // minmod function: 131 | // 0, if any of the a, b, c are 0 or of opposite sign 132 | // sign(a) min(|a|,|b|,|c|) else 133 | inline float minmod(float a, float b, float c) { 134 | if ((sign(a) == sign(b)) && (sign(b) == sign(c)) && (a != 0.0)) { 135 | float aMin = fabs(a); 136 | if (fabs(b) < aMin) aMin = fabs(b); 137 | if (fabs(c) < aMin) aMin = fabs(c); 138 | return sign(a)*aMin; 139 | } 140 | else return 0.0; 141 | } 142 | 143 | // arctan 144 | inline float arctan(float x, float y) { 145 | if (x == 0.0) 146 | if (y >= 0.0) return 0.5 * 3.1415926536; 147 | else return 1.5 * 3.1415926536; 148 | else if (x > 0.0) 149 | if (y >= 0.0) return atan (y/x); 150 | else return 2.0 * 3.1415926536 + atan (y/x); 151 | else return 3.1415926536 + atan (y/x); 152 | } 153 | 154 | // random 155 | inline float random() { 156 | return (float)rand()/RAND_MAX; 157 | } 158 | 159 | // randomGauss 160 | inline float randomGauss() { 161 | // Draw two [0,1]-uniformly distributed numbers a and b 162 | float a = random(); 163 | float b = random(); 164 | // assemble a N(0,1) number c according to Box-Muller */ 165 | if (a > 0.0) return sqrt(-2.0*log(a)) * cos(2.0*3.1415926536*b); 166 | else return 0; 167 | } 168 | 169 | } 170 | #endif 171 | -------------------------------------------------------------------------------- /video_input/consistencyChecker/consistencyChecker: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/video_input/consistencyChecker/consistencyChecker -------------------------------------------------------------------------------- /video_input/consistencyChecker/consistencyChecker.cpp: -------------------------------------------------------------------------------- 1 | // consistencyChecker 2 | // Check consistency of forward flow via backward flow. 3 | // 4 | // (c) Manuel Ruder, Alexey Dosovitskiy, Thomas Brox 2016 5 | 6 | #include 7 | #include 8 | #include "CTensor.h" 9 | #include "CFilter.h" 10 | 11 | // Which certainty value motion boundaries should get. Value between 0 (uncertain) and 255 (certain). 12 | #define MOTION_BOUNDARIE_VALUE 0 13 | 14 | // The amount of gaussian smoothing that sould be applied. Set 0 to disable smoothing. 15 | #define SMOOTH_STRENGH 0.8 16 | 17 | // readMiddlebury 18 | bool readMiddlebury(const char* filename, CTensor& flow) { 19 | FILE *stream = fopen(filename, "rb"); 20 | if (stream == 0) { 21 | std::cout << "Could not open " << filename << std::endl; 22 | return false; 23 | } 24 | float help; 25 | int dummy; 26 | dummy = fread(&help,sizeof(float),1,stream); 27 | int aXSize,aYSize; 28 | dummy = fread(&aXSize,sizeof(int),1,stream); 29 | dummy = fread(&aYSize,sizeof(int),1,stream); 30 | flow.setSize(aXSize,aYSize,2); 31 | for (int y = 0; y < flow.ySize(); y++) 32 | for (int x = 0; x < flow.xSize(); x++) { 33 | dummy = fread(&flow(x,y,0),sizeof(float),1,stream); 34 | dummy = fread(&flow(x,y,1),sizeof(float),1,stream); 35 | } 36 | fclose(stream); 37 | return true; 38 | } 39 | 40 | void checkConsistency(const CTensor& flow1, const CTensor& flow2, CMatrix& reliable, int argc, char** args) { 41 | int xSize = flow1.xSize(), ySize = flow1.ySize(); 42 | int size = xSize * ySize; 43 | CTensor dx(xSize,ySize,2); 44 | CTensor dy(xSize,ySize,2); 45 | CDerivative derivative(3); 46 | NFilter::filter(flow1,dx,derivative,1,1); 47 | NFilter::filter(flow1,dy,1,derivative,1); 48 | CMatrix motionEdge(xSize,ySize,0); 49 | for (int i = 0; i < size; i++) { 50 | motionEdge.data()[i] += dx.data()[i]*dx.data()[i]; 51 | motionEdge.data()[i] += dx.data()[size+i]*dx.data()[size+i]; 52 | motionEdge.data()[i] += dy.data()[i]*dy.data()[i]; 53 | motionEdge.data()[i] += dy.data()[size+i]*dy.data()[size+i]; 54 | } 55 | 56 | for (int ay = 0; ay < flow1.ySize(); ay++) 57 | for (int ax = 0; ax < flow1.xSize(); ax++) { 58 | float bx = ax+flow1(ax, ay, 0); 59 | float by = ay+flow1(ax, ay, 1); 60 | int x1 = floor(bx); 61 | int y1 = floor(by); 62 | int x2 = x1 + 1; 63 | int y2 = y1 + 1; 64 | if (x1 < 0 || x2 >= xSize || y1 < 0 || y2 >= ySize) 65 | { reliable(ax, ay) = 0.0f; continue; } 66 | float alphaX = bx-x1; float alphaY = by-y1; 67 | float a = (1.0-alphaX) * flow2(x1, y1, 0) + alphaX * flow2(x2, y1, 0); 68 | float b = (1.0-alphaX) * flow2(x1, y2, 0) + alphaX * flow2(x2, y2, 0); 69 | float u = (1.0-alphaY)*a+alphaY*b; 70 | a = (1.0-alphaX) * flow2(x1, y1, 1) + alphaX * flow2(x2, y1, 1); 71 | b = (1.0-alphaX) * flow2(x1, y2, 1) + alphaX * flow2(x2, y2, 1); 72 | float v = (1.0-alphaY)*a+alphaY*b; 73 | float cx = bx+u; 74 | float cy = by+v; 75 | float u2 = flow1(ax,ay,0); 76 | float v2 = flow1(ax,ay,1); 77 | if (((cx-ax) * (cx-ax) + (cy-ay) * (cy-ay)) >= 0.01*(u2*u2 + v2*v2 + u*u + v*v) + 0.5f) { 78 | // Set to a negative value so that when smoothing is applied the smoothing goes "to the outside". 79 | // Afterwards, we clip values below 0. 80 | reliable(ax, ay) = -255.0f; 81 | continue; 82 | } 83 | if (motionEdge(ax, ay) > 0.01 * (u2*u2+v2*v2) + 0.002f) { 84 | reliable(ax, ay) = MOTION_BOUNDARIE_VALUE; 85 | continue; 86 | } 87 | } 88 | } 89 | 90 | int main(int argc, char** args) { 91 | assert(argc >= 4); 92 | 93 | CTensor flow1,flow2; 94 | readMiddlebury(args[1], flow1); 95 | readMiddlebury(args[2], flow2); 96 | 97 | assert(flow1.xSize() == flow2.xSize()); 98 | assert(flow1.ySize() == flow2.ySize()); 99 | 100 | int xSize = flow1.xSize(), ySize = flow1.ySize(); 101 | 102 | // Check consistency of forward flow via backward flow and exclude motion boundaries 103 | CMatrix reliable(xSize, ySize, 255.0f); 104 | checkConsistency(flow1, flow2, reliable, argc, args); 105 | 106 | if (SMOOTH_STRENGH > 0) { 107 | CSmooth smooth(SMOOTH_STRENGH, 2.0f); 108 | NFilter::filter(reliable, smooth, smooth); 109 | } 110 | reliable.clip(0.0f, 255.0f); 111 | 112 | reliable.writeToPGM(args[3]); 113 | reliable.writeToTXT(args[3], true); 114 | } 115 | -------------------------------------------------------------------------------- /video_input/deepflow2-static: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/video_input/deepflow2-static -------------------------------------------------------------------------------- /video_input/deepmatching-static: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dvschultz/neural-style-tf/b599ccfdb580130e9ddd8ee1793c4143558ae5f6/video_input/deepmatching-static -------------------------------------------------------------------------------- /video_input/make-opt-flow.sh: -------------------------------------------------------------------------------- 1 | # Specify the path to the optical flow utility here. 2 | # Also check line 44 and 47 whether the arguments are in the correct order. 3 | 4 | # deepflow and deepmatching optical flow binaries 5 | flowCommandLine="bash run-deepflow.sh" 6 | 7 | if [ -z "$flowCommandLine" ]; then 8 | echo "Please open make-opt-flow.sh and specify the command line for computing the optical flow." 9 | exit 1 10 | fi 11 | 12 | if [ ! -f ./consistencyChecker/consistencyChecker ]; then 13 | if [ ! -f ./consistencyChecker/Makefile ]; then 14 | echo "Consistency checker makefile not found." 15 | exit 1 16 | fi 17 | cd consistencyChecker/ 18 | make 19 | cd .. 20 | fi 21 | 22 | filePattern=$1 23 | folderName=$2 24 | startFrame=${3:-1} 25 | stepSize=${4:-1} 26 | 27 | if [ "$#" -le 1 ]; then 28 | echo "Usage: ./make-opt-flow [ []]" 29 | echo -e "\tfilePattern:\tFilename pattern of the frames of the videos." 30 | echo -e "\toutputFolder:\tOutput folder." 31 | echo -e "\tstartNumber:\tThe index of the first frame. Default: 1" 32 | echo -e "\tstepSize:\tThe step size to create long-term flow. Default: 1" 33 | exit 1 34 | fi 35 | 36 | i=$[$startFrame] 37 | j=$[$startFrame + $stepSize] 38 | 39 | mkdir -p "${folderName}" 40 | 41 | while true; do 42 | file1=$(printf "$filePattern" "$i") 43 | file2=$(printf "$filePattern" "$j") 44 | if [ -a $file2 ]; then 45 | if [ ! -f ${folderName}/forward_${i}_${j}.flo ]; then 46 | eval $flowCommandLine "$file1" "$file2" "${folderName}/forward_${i}_${j}.flo" 47 | fi 48 | if [ ! -f ${folderName}/backward_${j}_${i}.flo ]; then 49 | eval $flowCommandLine "$file2" "$file1" "${folderName}/backward_${j}_${i}.flo" 50 | fi 51 | ./consistencyChecker/consistencyChecker "${folderName}/backward_${j}_${i}.flo" "${folderName}/forward_${i}_${j}.flo" "${folderName}/reliable_${j}_${i}.txt" 52 | ./consistencyChecker/consistencyChecker "${folderName}/forward_${i}_${j}.flo" "${folderName}/backward_${j}_${i}.flo" "${folderName}/reliable_${i}_${j}.txt" 53 | else 54 | break 55 | fi 56 | i=$[$i +1] 57 | j=$[$j +1] 58 | done 59 | -------------------------------------------------------------------------------- /video_input/run-deepflow.sh: -------------------------------------------------------------------------------- 1 | if [ "$#" -ne 3 ]; then 2 | echo "This is an auxiliary script for makeOptFlow.sh. No need to call this script directly." 3 | exit 1 4 | fi 5 | if [ ! -f deepmatching-static ] && [ ! -f deepflow2-static ]; then 6 | echo "Place deepflow2-static and deepmatching-static in this directory." 7 | exit 1 8 | fi 9 | 10 | ./deepmatching-static $1 $2 -nt 0 | ./deepflow2-static $1 $2 $3 -match --------------------------------------------------------------------------------