-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from albarji/feature/style-swap
Major overhaul of the application and addition of faster algorithms
- Loading branch information
Showing
53 changed files
with
604 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
**/__pycache__/ | ||
*.pyc | ||
.idea | ||
.coverage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
.PHONY: build clean | ||
.PHONY: all build clean build_tests tests clean_tests | ||
IMGNAME=albarji/neural-style | ||
IMGTAG=latest | ||
TESTIMGNAME=$(IMGNAME)-tests | ||
|
||
build: | ||
nvidia-docker build -t $(IMGNAME):$(IMGTAG) . | ||
|
||
clean: | ||
docker rmi $(IMGNAME):$(IMGTAG) | ||
|
||
build_tests: | ||
nvidia-docker build -t $(TESTIMGNAME) tests | ||
|
||
tests: | ||
nvidia-docker run --rm -it $(TESTIMGNAME) | ||
|
||
clean_tests: | ||
docker rmi $(TESTIMGNAME) | ||
|
||
all: build build_tests tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Main entrypoint script to the neural-style app | ||
import sys | ||
import traceback | ||
import logging | ||
from neuralstyle.algorithms import styletransfer | ||
from neuralstyle.utils import sublist | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
LOGGER = logging.getLogger(__name__) | ||
|
||
HELP = """ | ||
neural-style-docker: artistic style between images | ||
--content CONTENT_IMAGES: file or files with the content images to use | ||
--style STYLE_IMAGES: file or files with the styles to transfer | ||
--output OUTPUT_FOLDER: name of the output folder in which to save results | ||
--size SIZE: size of the output image. Default: content image size | ||
--sw STYLE_WEIGHT (default 10): weight or list of weights of the style over the content, in range (0, inf) | ||
--ss STYLE_SCALE (default 1.0): scaling or list of scaling factors for the style images | ||
--alg ALGORITHM: style-transfer algorithm to use. Must be one of the following: | ||
gatys Highly detailed transfer, slow processing times (default) | ||
chen-schmidt Fast patch-based style transfer | ||
chen-schmidt-inverse Even faster aproximation to chen-schmidt through the use of an inverse network | ||
--tilesize TILE_SIZE: maximum size of each tile in the style transfer. | ||
If your GPU runs out of memory you should try reducing this value. Default: 512 | ||
Additionally provided parameters are carried on to the underlying algorithm. | ||
""" | ||
|
||
|
||
def main(argv=None): | ||
if argv is None: | ||
argv = sys.argv | ||
try: | ||
# Default parameters | ||
contents = [] | ||
styles = [] | ||
savefolder = "/images" | ||
size = None | ||
alg = "gatys" | ||
weights = None | ||
stylescales = None | ||
otherparams = [] | ||
|
||
# Gather parameters | ||
i = 1 | ||
while i < len(argv): | ||
# References to inputs/outputs are re-referenced to the mounted /images directory | ||
if argv[i] == "--content": | ||
contents = ["/images/" + x for x in sublist(argv[i+1:], stopper="--")] | ||
i += len(contents) + 1 | ||
elif argv[i] == "--style": | ||
styles = ["/images/" + x for x in sublist(argv[i+1:], stopper="--")] | ||
i += len(styles) + 1 | ||
# Other general parameters | ||
elif argv[i] == "--output": | ||
savefolder = argv[i+1] | ||
i += 2 | ||
elif argv[i] == "--alg": | ||
alg = argv[i+1] | ||
i += 2 | ||
elif argv[i] == "--size": | ||
size = int(argv[i+1]) | ||
i += 2 | ||
elif argv[i] == "--sw": | ||
weights = [float(x) for x in sublist(argv[i+1:], stopper="--")] | ||
i += len(weights) + 1 | ||
elif argv[i] == "--ss": | ||
stylescales = [float(x) for x in sublist(argv[i+1:], stopper="--")] | ||
i += len(stylescales) + 1 | ||
# Help | ||
elif argv[i] == "--help": | ||
print(HELP) | ||
return 0 | ||
# Additional parameters will be passed on to the specific algorithms | ||
else: | ||
otherparams.append(argv[i]) | ||
i += 1 | ||
|
||
# Check parameters | ||
if len(contents) == 0: | ||
raise ValueError("At least one content image must be provided") | ||
if len(styles) == 0: | ||
raise ValueError("At least one style image must be provided") | ||
|
||
LOGGER.info("Running neural style transfer with") | ||
LOGGER.info("\tContents = %s" % str(contents)) | ||
LOGGER.info("\tStyle = %s" % str(styles)) | ||
LOGGER.info("\tAlgorithm = %s" % alg) | ||
LOGGER.info("\tStyle weights = %s" % str(weights)) | ||
LOGGER.info("\tStyle scales = %s" % str(stylescales)) | ||
styletransfer(contents, styles, savefolder, size, alg, weights, stylescales, *otherparams) | ||
return 1 | ||
|
||
except Exception: | ||
print(HELP) | ||
traceback.print_exc() | ||
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.exit(main()) |
Binary file not shown.
Empty file.
Oops, something went wrong.