Skip to content

Commit

Permalink
Added GPL header to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnetts authored and deepnetts committed Dec 2, 2021
1 parent 07e2bfb commit c4f296c
Show file tree
Hide file tree
Showing 18 changed files with 1,342 additions and 1,003 deletions.
123 changes: 71 additions & 52 deletions src/main/java/javax/visrec/ri/BufferedImageFactory.java
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
package javax.visrec.ri;

import javax.imageio.ImageIO;
import javax.visrec.ImageFactory;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Path;

/**
* {@link ImageFactory} to provide {@link BufferedImage} as return object.
*
*/
public class BufferedImageFactory implements ImageFactory<BufferedImage> {

/**
* {@inheritDoc}
*/
@Override
public BufferedImage getImage(Path path) throws IOException {
BufferedImage img = ImageIO.read(path.toFile());
if (img == null) {
throw new IOException("Failed to transform Path into BufferedImage due to unknown image encoding");
}
return img;
}

/**
* {@inheritDoc}
*/
@Override
public BufferedImage getImage(URL file) throws IOException {
BufferedImage img = ImageIO.read(file);
if (img == null) {
throw new IOException("Failed to transform URL into BufferedImage due to unknown image encoding");
}
return img;
}

/**
* {@inheritDoc}
*/
@Override
public BufferedImage getImage(InputStream file) throws IOException {
BufferedImage img = ImageIO.read(file);
if (img == null) {
throw new IOException("Failed to transform InputStream into BufferedImage due to unknown image encoding");
}
return img;
}
}
/**
* Visual Recognition API for Java, JSR381
* Copyright (C) 2020 Zoran Sevarac, Frank Greco
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package javax.visrec.ri;

import javax.imageio.ImageIO;
import javax.visrec.ImageFactory;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Path;

/**
* {@link ImageFactory} to provide {@link BufferedImage} as return object.
*
*/
public class BufferedImageFactory implements ImageFactory<BufferedImage> {

/**
* {@inheritDoc}
*/
@Override
public BufferedImage getImage(Path path) throws IOException {
BufferedImage img = ImageIO.read(path.toFile());
if (img == null) {
throw new IOException("Failed to transform Path into BufferedImage due to unknown image encoding");
}
return img;
}

/**
* {@inheritDoc}
*/
@Override
public BufferedImage getImage(URL file) throws IOException {
BufferedImage img = ImageIO.read(file);
if (img == null) {
throw new IOException("Failed to transform URL into BufferedImage due to unknown image encoding");
}
return img;
}

/**
* {@inheritDoc}
*/
@Override
public BufferedImage getImage(InputStream file) throws IOException {
BufferedImage img = ImageIO.read(file);
if (img == null) {
throw new IOException("Failed to transform InputStream into BufferedImage due to unknown image encoding");
}
return img;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
* Visual Recognition API for Java, JSR381
* Copyright (C) 2020 Zoran Sevarac, Frank Greco
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package javax.visrec.ri.ml.classification;

import javax.visrec.ImageFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
* Visual Recognition API for Java, JSR381
* Copyright (C) 2020 Zoran Sevarac, Frank Greco
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package javax.visrec.ri.ml.classification;

import deepnetts.net.FeedForwardNetwork;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,71 @@
package javax.visrec.ri.ml.classification;

import deepnetts.data.ExampleImage;
import deepnetts.net.ConvolutionalNetwork;

import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

/**
* Implementation of abstract image classifier for BufferedImage-s using
* Convolutional network form Deep Netts.
*/
public class ImageClassifierNetwork extends AbstractImageClassifier<BufferedImage, ConvolutionalNetwork> {

// it seems that these are not used at the end, onlz in builder. Do we need them exposed here__
private int inputWidth, inputHeight;

public ImageClassifierNetwork(ConvolutionalNetwork network) {
super(BufferedImage.class, network);
}

@Override
public Map<String, Float> classify(BufferedImage inputImage) {
// create input for neural network from image
ExampleImage exImage = new ExampleImage(inputImage);

// get underlying ML model, in this case convolutional network
ConvolutionalNetwork neuralNet = getModel();
// set neural network input and get outputs
neuralNet.setInput(exImage.getInput());
float[] outputs = neuralNet.getOutput();

// get all class labels with corresponding output larger then classification threshold
Map<String, Float> results = new HashMap<>();
for (int i = 0; i < outputs.length; i++) {
if (outputs[i] >= getThreshold())
results.put(neuralNet.getOutputLabel(i), outputs[i]);
}

return results;
}

public int getInputWidth() {
return inputWidth;
}

public int getInputHeight() {
return inputHeight;
}

}
/**
* Visual Recognition API for Java, JSR381
* Copyright (C) 2020 Zoran Sevarac, Frank Greco
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package javax.visrec.ri.ml.classification;

import deepnetts.data.ExampleImage;
import deepnetts.net.ConvolutionalNetwork;

import java.awt.image.BufferedImage;
import java.util.HashMap;
import java.util.Map;

/**
* Implementation of abstract image classifier for BufferedImage-s using
* Convolutional network form Deep Netts.
*/
public class ImageClassifierNetwork extends AbstractImageClassifier<BufferedImage, ConvolutionalNetwork> {

// it seems that these are not used at the end, onlz in builder. Do we need them exposed here__
private int inputWidth, inputHeight;

public ImageClassifierNetwork(ConvolutionalNetwork network) {
super(BufferedImage.class, network);
}

@Override
public Map<String, Float> classify(BufferedImage inputImage) {
// create input for neural network from image
ExampleImage exImage = new ExampleImage(inputImage);

// get underlying ML model, in this case convolutional network
ConvolutionalNetwork neuralNet = getModel();
// set neural network input and get outputs
neuralNet.setInput(exImage.getInput());
float[] outputs = neuralNet.getOutput();

// get all class labels with corresponding output larger then classification threshold
Map<String, Float> results = new HashMap<>();
for (int i = 0; i < outputs.length; i++) {
if (outputs[i] >= getThreshold())
results.put(neuralNet.getOutputLabel(i), outputs[i]);
}

return results;
}

public int getInputWidth() {
return inputWidth;
}

public int getInputHeight() {
return inputHeight;
}

}
Loading

0 comments on commit c4f296c

Please sign in to comment.