TensorFlow with Java on Windows without CUDA

Yes, its possible today. Google is still working on it, so it might change in the future. And especially the Java API is not stable, and not very beautiful. Here is an example LabelImage.java.

Simply add these dependencies to your pom.xml:

<dependency>
	<groupId>org.tensorflow</groupId>
	<artifactId>libtensorflow</artifactId>
	<version>1.1.0-rc0-windows-fix</version>
</dependency>
<dependency>
    <groupId>org.tensorflow</groupId>
    <artifactId>libtensorflow_jni</artifactId>
    <version>1.1.0-rc0-windows-fix</version>
</dependency>

Then you can start coding:

public static void main(final String[] args) {
	System.out.println("Hello TensorFlow " + org.tensorflow.TensorFlow.version());
}

JZopfli Maven plugin

The JZopfli Maven plugin processes all artifacts and improves the compression using the Zopfli algorithm. In addition it removes useless metadata inside the zip archive to improve further the file size. See the details here.

Simply add this to your pom.xml

<build>
	<plugins>
		<plugin>
			<groupId>com.github.luccappellaro</groupId>
			<artifactId>jzopfli-mvn</artifactId>
			<version>0.0.4</version>
			<executions>
				<execution>
					<goals>
						<goal>jzopfli</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>

JZopfli command line

JZopfli has exactly the same command line as the Zopfli original.
You can simply download it from the maven central repository and execute it.

$ wget http://central.maven.org/maven2/com/github/luccappellaro/jzopfli/0.0.1/jzopfli-0.0.1.jar
--2015-01-29 00:17:24--  http://central.maven.org/maven2/com/github/luccappellaro/jzopfli/0.0.1/jzopfli-0.0.1.jar
Resolving central.maven.org (central.maven.org)... 23.235.43.209
Connecting to central.maven.org (central.maven.org)|23.235.43.209|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 58811 (57K) [application/java-archive]
Saving to: `jzopfli-0.0.1.jar'

100%[============================================================================================================================================>] 58,811      --.-K/s   in 0.04s

2015-01-29 00:17:24 (1.33 MB/s) - `jzopfli-0.0.1.jar' saved [58811/58811]

$ java -jar jzopfli-0.0.1.jar -h
Usage: zopfli [OPTION]... FILE
  -h    gives this help
  -c    write the result on standard output, instead of disk filename + '.gz'
  -v    verbose mode
  --i#  perform # iterations (default 15). More gives more compression but is slower. Examples: --i10, --i50, --i1000
  --gzip        output to gzip format (default)
  --zlib        output to zlib format instead of gzip
  --deflate     output to deflate format instead of gzip
  --splitlast   do block splitting last instead of first

ZopfliOutputStream

I have implemented a simple drop-in replacement for the java.util.zip.ZipOutputStream which uses theĀ Zopfli algorithm: JZopfli-Stream.

try(ZopfliOutputStream zos=new ZopfliOutputStream(new FileOutputStream("file.zip"))){
	zos.putNextEntry(new ZipEntry("file.txt"));
	zos.write("content".getBytes());
}

Using this dependency:

<dependency>
	<groupId>com.github.luccappellaro</groupId>
	<artifactId>jzopfli-stream</artifactId>
	<version>0.0.2</version>
</dependency>