forked from mymagicpower/AIAS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e20414
commit 9c57080
Showing
857 changed files
with
4,940 additions
and
54,165 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 |
---|---|---|
|
@@ -12,7 +12,11 @@ | |
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
*/ | ||
public final class AnimalsClassExample { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AnimalsClassExample.class); | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,10 @@ | |
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Calvin | ||
* @email [email protected] | ||
*/ | ||
public class AnimalTranslator implements Translator<Image, Classifications> { | ||
List<String> classes; | ||
|
||
|
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 |
---|---|---|
|
@@ -19,10 +19,12 @@ | |
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
// https://www.paddlepaddle.org.cn/hubdetail?name=resnet50_vd_animals&en_category=ImageClassification | ||
// | ||
// Users/calvin/Desktop/Download/browser/PaddleHub-release-v2.1/modules/image/classification/resnet50_vd_animals | ||
|
||
/** | ||
* Animals Classification | ||
* https://www.paddlepaddle.org.cn/hubdetail?name=resnet50_vd_animals&en_category=ImageClassification | ||
* @author Calvin | ||
* @email [email protected] | ||
*/ | ||
public final class AnimalsClassification { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(AnimalsClassification.class); | ||
|
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 |
---|---|---|
|
@@ -20,9 +20,10 @@ | |
import java.nio.file.Paths; | ||
|
||
// https://www.paddlepaddle.org.cn/hubdetail?name=mobilenet_v2_animals&en_category=ImageClassification | ||
// | ||
// /Users/calvin/Desktop/Download/browser/PaddleHub-release-v2.1/modules/image/classification/mobilenet_v2_animals | ||
|
||
/** | ||
* @author Calvin | ||
* @email [email protected] | ||
*/ | ||
public final class LightAnimalsClassification { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(LightAnimalsClassification.class); | ||
|
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 |
---|---|---|
|
@@ -12,7 +12,11 @@ | |
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
*/ | ||
public final class DishesClassificationExample { | ||
private static final Logger logger = LoggerFactory.getLogger(DishesClassificationExample.class); | ||
|
||
|
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 |
---|---|---|
|
@@ -12,7 +12,11 @@ | |
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
*/ | ||
public final class LightDishesClassExample { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(LightDishesClassExample.class); | ||
|
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 |
---|---|---|
|
@@ -18,6 +18,11 @@ | |
import java.io.InputStream; | ||
import java.util.List; | ||
|
||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
*/ | ||
public class DishTranslator implements Translator<Image, Classifications> { | ||
List<String> classes; | ||
|
||
|
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 |
---|---|---|
|
@@ -19,8 +19,13 @@ | |
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
// https://www.paddlepaddle.org.cn/hubdetail?name=resnet50_vd_dishes&en_category=ImageClassification | ||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
*/ | ||
public final class DishesClassification { | ||
// https://www.paddlepaddle.org.cn/hubdetail?name=resnet50_vd_dishes&en_category=ImageClassification | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(DishesClassification.class); | ||
|
||
|
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 |
---|---|---|
|
@@ -20,9 +20,11 @@ | |
import java.nio.file.Paths; | ||
|
||
// https://www.paddlepaddle.org.cn/hubdetail?name=mobilenet_v2_dishes&en_category=ImageClassification | ||
// | ||
// /Users/calvin/Desktop/Download/browser/PaddleHub-release-v2.1/modules/image/classification/mobilenet_v2_dishes | ||
|
||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
*/ | ||
public final class LightDishesClassification { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(LightDishesClassification.class); | ||
|
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 |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
import java.nio.file.Paths; | ||
|
||
/** | ||
* 图片比对 - 1:1. | ||
* | ||
* Feature Comparison - 1:1. | ||
* 特征比对 - 1:1. | ||
* @author Calvin | ||
* @date 2021-07-10 | ||
* @email [email protected] | ||
|
@@ -43,11 +43,13 @@ public static void main(String[] args) throws IOException, ModelException, Trans | |
float[] feature1 = predictor.predict(img1); | ||
float[] feature2 = predictor.predict(img2); | ||
|
||
//欧式距离 | ||
// 欧式距离 | ||
// Euclidean distance | ||
float dis = FeatureComparison.dis(feature1, feature2); | ||
logger.info(Float.toString(dis)); | ||
|
||
//余弦相似度 | ||
// 余弦相似度 | ||
// Cosine similarity | ||
float cos = FeatureComparison.cosineSim(feature1, feature2); | ||
logger.info(Float.toString(cos)); | ||
} | ||
|
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 |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
/** | ||
* 图片特征提取 (512维特征) | ||
* | ||
* Image feature extraction (512-dimensional features) | ||
* @author Calvin | ||
* @date 2021-07-10 | ||
* @email [email protected] | ||
|
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 |
---|---|---|
|
@@ -3,12 +3,17 @@ | |
/** | ||
* 特征相似度计算 | ||
* https://zhuanlan.zhihu.com/p/88117781?utm_source=wechat_session | ||
*/ | ||
* Feature Similarity Calculation | ||
* @author Calvin | ||
* @date 2021-07-10 | ||
* @email [email protected] | ||
**/ | ||
public final class FeatureComparison { | ||
private FeatureComparison() {} | ||
|
||
/** | ||
* 余弦相似度 | ||
* Cosine similarity | ||
* @param feature1 | ||
* @param feature2 | ||
* @return | ||
|
@@ -29,6 +34,7 @@ public static float cosineSim(float[] feature1, float[] feature2) { | |
|
||
/** | ||
* 欧式距离 | ||
* Euclidean distance | ||
* @param feature1 | ||
* @param feature2 | ||
* @return | ||
|
@@ -44,6 +50,7 @@ public static float dis(float[] feature1, float[] feature2) { | |
|
||
/** | ||
* 内积 | ||
* Inner product | ||
* @param feature1 | ||
* @param feature2 | ||
* @return | ||
|
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
|
||
/** | ||
* 图片特征提取模型 | ||
* Image Feature Extraction Model | ||
* | ||
* @author Calvin | ||
* @date 2021-12-19 | ||
|
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
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 |
---|---|---|
|
@@ -9,6 +9,11 @@ | |
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
**/ | ||
public class FirstOrder { | ||
|
||
public FirstOrder() {} | ||
|
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 |
---|---|---|
|
@@ -15,18 +15,26 @@ | |
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.Iterator; | ||
|
||
/** | ||
* Image Utils | ||
* @author Calvin | ||
* | ||
* @email [email protected] | ||
**/ | ||
public class ImageUtils { | ||
|
||
public static Image bufferedImage2DJLImage(BufferedImage img) { | ||
return ImageFactory.getInstance().fromImage(img); | ||
} | ||
|
||
public static void saveImage(BufferedImage img, String name, String path) { | ||
Image newImage = ImageFactory.getInstance().fromImage(img); // 支持多种图片格式,自动适配 | ||
// 支持多种图片格式,自动适配 | ||
// Supports multiple image formats and automatically adapts | ||
Image newImage = ImageFactory.getInstance().fromImage(img); | ||
Path outputDir = Paths.get(path); | ||
Path imagePath = outputDir.resolve(name); | ||
// OpenJDK 不能保存 jpg 图片的 alpha channel | ||
// OpenJDK cannot save the alpha channel of jpg images | ||
try { | ||
newImage.save(Files.newOutputStream(imagePath), "png"); | ||
} catch (IOException e) { | ||
|
@@ -38,6 +46,7 @@ public static void saveImage(Image img, String name, String path) { | |
Path outputDir = Paths.get(path); | ||
Path imagePath = outputDir.resolve(name); | ||
// OpenJDK 不能保存 jpg 图片的 alpha channel | ||
// OpenJDK cannot save the alpha channel of jpg images | ||
try { | ||
img.save(Files.newOutputStream(imagePath), "png"); | ||
} catch (IOException e) { | ||
|
@@ -58,10 +67,12 @@ public static void saveBoundingBoxImage( | |
|
||
public static void drawImageRect(BufferedImage image, int x, int y, int width, int height) { | ||
// 将绘制图像转换为Graphics2D | ||
// Convert the drawing image to Graphics2D | ||
Graphics2D g = (Graphics2D) image.getGraphics(); | ||
try { | ||
g.setColor(new Color(246, 96, 0)); | ||
// 声明画笔属性 :粗 细(单位像素)末端无修饰 折线处呈尖角 | ||
// Declare pen attributes: thick (in pixels), no decoration at the end, pointed at the corner of the broken line | ||
BasicStroke bStroke = new BasicStroke(4, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); | ||
g.setStroke(bStroke); | ||
g.drawRect(x, y, width, height); | ||
|
@@ -74,10 +85,12 @@ public static void drawImageRect(BufferedImage image, int x, int y, int width, i | |
public static void drawImageRect( | ||
BufferedImage image, int x, int y, int width, int height, Color c) { | ||
// 将绘制图像转换为Graphics2D | ||
// Convert the drawing image to Graphics2D | ||
Graphics2D g = (Graphics2D) image.getGraphics(); | ||
try { | ||
g.setColor(c); | ||
// 声明画笔属性 :粗 细(单位像素)末端无修饰 折线处呈尖角 | ||
// Declare pen attributes: thick (in pixels), no decoration at the end, pointed at the corner of the broken line | ||
BasicStroke bStroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER); | ||
g.setStroke(bStroke); | ||
g.drawRect(x, y, width, height); | ||
|
@@ -101,20 +114,29 @@ public static void drawImageText(BufferedImage image, String text) { | |
} | ||
} | ||
|
||
/** 返回外扩人脸 factor = 1, 100%, factor = 0.2, 20% */ | ||
/** | ||
* 返回外扩人脸 factor = 1, 100%, factor = 0.2, 20% | ||
* Return the expanded face with factor = 1, 100%, factor = 0.2, 20% | ||
* @param img | ||
* @param box | ||
* @param factor | ||
* @return | ||
*/ | ||
public static Image getSubImage(Image img, BoundingBox box, float factor) { | ||
Rectangle rect = box.getBounds(); | ||
// 左上角坐标 | ||
// Upper left corner coordinates | ||
int x1 = (int) (rect.getX() * img.getWidth()); | ||
int y1 = (int) (rect.getY() * img.getHeight()); | ||
// 宽度,高度 | ||
// width, height | ||
int w = (int) (rect.getWidth() * img.getWidth()); | ||
int h = (int) (rect.getHeight() * img.getHeight()); | ||
// 左上角坐标 | ||
|
||
int x2 = x1 + w; | ||
int y2 = y1 + h; | ||
|
||
// 外扩大100%,防止对齐后人脸出现黑边 | ||
// Expand by 100% to prevent black edges from appearing on the aligned face | ||
int new_x1 = Math.max((int) (x1 + x1 * factor / 2 - x2 * factor / 2), 0); | ||
int new_x2 = Math.min((int) (x2 + x2 * factor / 2 - x1 * factor / 2), img.getWidth() - 1); | ||
int new_y1 = Math.max((int) (y1 + y1 * factor / 2 - y2 * factor / 2), 0); | ||
|
@@ -154,14 +176,14 @@ public static void drawBoundingBoxImage(Image img, DetectedObjects detection) { | |
|
||
public static int getX(Image img, BoundingBox box) { | ||
Rectangle rect = box.getBounds(); | ||
// 左上角x坐标 | ||
// Upper left corner x coordinate | ||
int x = (int) (rect.getX() * img.getWidth()); | ||
return x; | ||
} | ||
|
||
public static int getY(Image img, BoundingBox box) { | ||
Rectangle rect = box.getBounds(); | ||
// 左上角y坐标 | ||
// Upper left corner y coordinate | ||
int y = (int) (rect.getY() * img.getHeight()); | ||
return y; | ||
} | ||
|
Oops, something went wrong.