Skip to content

Commit

Permalink
Merge pull request #8 from cameronleger/11
Browse files Browse the repository at this point in the history
1.4.0
  • Loading branch information
cameronleger authored May 7, 2020
2 parents 5f9abb1 + dd312a8 commit 654edbb
Show file tree
Hide file tree
Showing 17 changed files with 918 additions and 553 deletions.
20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ Neural Style GUI is designed for rapid prototyping art from Neural Style. To tha
![Log Tab of Neural-Style-GUI](/screenshots/log.png?raw=true "Log Tab of Neural-Style-GUI")

# Requirements
* [Neural-Style](https://github.com/jcjohnson/neural-style)
* AND/OR
* [neural-style](https://github.com/jcjohnson/neural-style) which requires Torch and is probably Linux-specific
* [neural-style-pt](https://github.com/ProGamerGov/neural-style-pt) which requires PyTorch and may work on Windows
* Java 11
* JavaFX 11 (included with Oracle, separate package for OpenJDK)

Expand All @@ -29,10 +31,11 @@ Neural Style GUI is designed for rapid prototyping art from Neural Style. To tha
* Log of Neural Style command output

# Starting
Unzip the release to a folder of your choice (or build from source and check the **target/jfx/app** folder). Run the neural-style-gui.sh file or run **java -jar neural-style-gui-*-jfx.jar** with any additional options you desire.
1. Unzip the release to a folder of your choice (or build from source and check the **shade** folder).
2. Run the neural-style-gui.sh or neural-style-gui.bat file. Alternatively, run **java -jar neural-style-gui-*.jar** with any additional options you desire.

# Minimum Required Steps
1. Set the Neural Style path in the Files Tab
1. Set the Runner and Neural Style paths in the Files Tab.
2. Modify Advanced settings based on your machine, i.e., CPU or GPU and backend
3. Set the Style Folder path to a folder containing style images
4. Select a style image in the Style Image Grid
Expand All @@ -42,7 +45,9 @@ Unzip the release to a folder of your choice (or build from source and check the
8. Press Start!

# Usage
After you have performed the Minimum Required Steps and chosen an Output Folder path, you may want to use the Save button in the Settings Pane to save all of this information into a 'default' settings file that you can load next time you run the application. If you're getting a File Not Found exception for the 'th' command because it's not properly in your PATH, you can set the path to 'th' above the Neural Style path.
After you have performed the Minimum Required Steps and chosen an Output Folder path, you may want to use the Save button in the Settings Pane to save all of this information into a 'default' settings file that you can load next time you run the application.

If you're getting a File Not Found exception for the 'th' command because it's not properly in your PATH, you can set the path to 'th' above the Neural Style path.

The Chaining parameter in the Basic Settings Pane allows you to quickly run multiple Neural Style commands that feed into each other with the previous result (i.e. the first chain will use the Initialization Image setting you chose, but each chain after that will use the last iteration image of the previous chain). Each numeric Parameter has a "Ratio" field that adjusts the Parameter for each Chain run. The normal value you specify is for the _last_ or _final_ run; the ratio value multiplies with that value for each chain by _walking backwards_. For example, with a 0.5 Size Ratio over 3 runs for a final result of 1200px, the runs will start at 300px before going to 600px and finally 1200px. This can allow you to make higher quality and larger images than with a single run with single settings, and almost always faster because less iterations are typically used with this.

Expand All @@ -67,6 +72,10 @@ In the Output Tab and next to the Image is the Output Queue Tree. Any started pr
The Neural Style Log Tab will show the output from the most recent running process. This is rarely used, but it's helpful to understand why a process might have failed, usually because of out-of-memory errors.

# Changelog
### 1.4.0
* Support for [neural-style-pt](https://github.com/ProGamerGov/neural-style-pt)
* Cross-platform JAR (since neural-style-pt works on Windows!)
* Logging improvements
### 1.3.0
* JDK 11
* Overhauled Parameters
Expand Down
1 change: 1 addition & 0 deletions neural-style-gui.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java -jar neural-style-gui-1.4.0.jar
2 changes: 1 addition & 1 deletion neural-style-gui.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
java -jar neural-style-gui-*.jar
java -jar neural-style-gui-1.4.0.jar
20 changes: 19 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<name>Neural Style GUI</name>
<groupId>com.cameronleger</groupId>
<artifactId>neural-style-gui</artifactId>
<version>1.3.0</version>
<version>1.4.0</version>
<packaging>jar</packaging>

<properties>
Expand Down Expand Up @@ -43,6 +43,24 @@
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>linux</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-graphics</artifactId>
<version>11</version>
<classifier>mac</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
Expand Down
46 changes: 31 additions & 15 deletions src/main/java/com/cameronleger/neuralstyle/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static File getLastUsedOutputStyle() {
return new File(".", LAST_STYLE_JSON);
}

public static File saveOutputStyle(NeuralStyleV3 neuralStyle) {
public static File saveOutputStyle(NeuralStyleV4 neuralStyle) {
File tempOutputDir = NeuralStyleWrapper.getWorkingFolder();
if (tempOutputDir == null) {
log.log(Level.FINE, "Unable to open file in temporary folder to save output style.");
Expand All @@ -108,7 +108,7 @@ public static File saveOutputStyle(NeuralStyleV3 neuralStyle) {
return saveOutputStyle(neuralStyle, tempOutputStyle);
}

public static File saveLastUsedOutputStyle(NeuralStyleV3 neuralStyle) {
public static File saveLastUsedOutputStyle(NeuralStyleV4 neuralStyle) {
File lastUsedOutputStyle = new File(".", LAST_STYLE_JSON);
if (lastUsedOutputStyle.exists() && !lastUsedOutputStyle.canWrite()) {
log.log(Level.FINE, "Unable to open file to save output style.");
Expand All @@ -117,7 +117,7 @@ public static File saveLastUsedOutputStyle(NeuralStyleV3 neuralStyle) {
return saveOutputStyle(neuralStyle, lastUsedOutputStyle);
}

public static File saveOutputStyle(NeuralStyleV3 neuralStyle, File outputFile) {
public static File saveOutputStyle(NeuralStyleV4 neuralStyle, File outputFile) {
try (FileWriter file = new FileWriter(outputFile)) {
file.write(gson.toJson(neuralStyle));
log.log(Level.FINE, "Output style saved: " + outputFile.getAbsolutePath());
Expand All @@ -143,40 +143,54 @@ private static NeuralStyleVersion loadStyleVersion(File styleFile) {
}
}

private static NeuralStyleV3 loadStyleV1(File styleFile) {
private static NeuralStyleV4 loadStyleV1(File styleFile) {
final FileInputStream fileStream;
try {
fileStream = new FileInputStream(styleFile);
final BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
NeuralStyleV1 neuralStyle = gson.fromJson(reader, NeuralStyleV1.class);
return neuralStyle.upgrade().upgrade();
return neuralStyle.upgrade().upgrade().upgrade();
} catch (Exception e) {
log.log(Level.FINE, "Exception loading input style.");
log.log(Level.SEVERE, e.toString(), e);
return null;
}
}

private static NeuralStyleV3 loadStyleV2(File styleFile) {
private static NeuralStyleV4 loadStyleV2(File styleFile) {
final FileInputStream fileStream;
try {
fileStream = new FileInputStream(styleFile);
final BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
NeuralStyleV2 neuralStyle = gson.fromJson(reader, NeuralStyleV2.class);
return neuralStyle.upgrade();
return neuralStyle.upgrade().upgrade();
} catch (Exception e) {
log.log(Level.FINE, "Exception loading input style.");
log.log(Level.SEVERE, e.toString(), e);
return null;
}
}

private static NeuralStyleV3 loadStyleV3(File styleFile) {
private static NeuralStyleV4 loadStyleV3(File styleFile) {
final FileInputStream fileStream;
try {
fileStream = new FileInputStream(styleFile);
final BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
NeuralStyleV3 neuralStyle = gson.fromJson(reader, NeuralStyleV3.class);
return neuralStyle.upgrade();
} catch (Exception e) {
log.log(Level.FINE, "Exception loading input style.");
log.log(Level.SEVERE, e.toString(), e);
return null;
}
}

private static NeuralStyleV4 loadStyleV4(File styleFile) {
final FileInputStream fileStream;
try {
fileStream = new FileInputStream(styleFile);
final BufferedReader reader = new BufferedReader(new InputStreamReader(fileStream));
NeuralStyleV4 neuralStyle = gson.fromJson(reader, NeuralStyleV4.class);
return neuralStyle;
} catch (Exception e) {
log.log(Level.FINE, "Exception loading input style.");
Expand All @@ -185,23 +199,25 @@ private static NeuralStyleV3 loadStyleV3(File styleFile) {
}
}

public static NeuralStyleV3 loadStyle(File styleFile) {
public static NeuralStyleV4 loadStyle(File styleFile) {
if (!FileUtils.checkFileExists(styleFile)) {
log.log(Level.FINE, "Cannot load a missing file.");
return null;
}
NeuralStyleVersion v = loadStyleVersion(styleFile);
int version = v == null ? 0 : v.getVersion();
try {
NeuralStyleV3 neuralStyle = null;
if (version < 3) {
if ((neuralStyle = loadStyleV2(styleFile)) == null) {
if ((neuralStyle = loadStyleV1(styleFile)) == null) {
log.log(Level.SEVERE, "Unable to load input style as any known version.");
NeuralStyleV4 neuralStyle = null;
if (version < 4) {
if ((neuralStyle = loadStyleV3(styleFile)) == null) {
if ((neuralStyle = loadStyleV2(styleFile)) == null) {
if ((neuralStyle = loadStyleV1(styleFile)) == null) {
log.log(Level.SEVERE, "Unable to load input style as any known version.");
}
}
}
} else {
if (v.getVersion() == 3) neuralStyle = loadStyleV3(styleFile);
if (v.getVersion() == 4) neuralStyle = loadStyleV4(styleFile);
}
return neuralStyle;
} catch (Exception e) {
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/com/cameronleger/neuralstyle/NeuralStyleV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import java.util.*;

public class NeuralStyleV2 implements Cloneable {
public final static int INVALID_ARGUMENTS = -2;
public final static int INVALID_FILE = -1;
public final static int QUEUED = 0;
public final static int IN_PROGRESS = 1;
public final static int CANCELLED = 2;
public final static int FAILED = 3;
public final static int FINISHED = 4;
private int queueStatus = QUEUED;

private File thPath;
Expand Down Expand Up @@ -400,11 +394,6 @@ public NeuralStyleV3 upgrade() {
return newStyle;
}

public void generateUniqueName() {
FileUtils.generateUniqueText();
outputFile = FileUtils.getTempOutputImage();
}

protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
Expand Down
Loading

0 comments on commit 654edbb

Please sign in to comment.