mirror of
https://gitee.com/open-visual/face-search.git
synced 2025-07-25 19:41:42 +08:00
update:修改已知的BUG和添加工具函数
This commit is contained in:
parent
74cad35d80
commit
6f57210267
@ -0,0 +1,39 @@
|
||||
package com.visual.face.search.core.utils;
|
||||
|
||||
import java.util.function.DoubleUnaryOperator;
|
||||
|
||||
|
||||
/**
|
||||
* SigmoidUtil
|
||||
*/
|
||||
public class SigmoidUtil {
|
||||
|
||||
private static final DoubleUnaryOperator sigmoid = p ->1/(1+ Math.exp(-1 * p));
|
||||
|
||||
/**
|
||||
* sigmoid
|
||||
* @param tensor
|
||||
* @return
|
||||
*/
|
||||
public static double[] sigmoid(double[] tensor){
|
||||
double[] result = new double[tensor.length];
|
||||
for (int i = 0; i < result.length; i++){
|
||||
result[i] = sigmoid.applyAsDouble(tensor[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* sigmoid
|
||||
* @param tensor
|
||||
* @return
|
||||
*/
|
||||
public static double[][] sigmoid(double[][] tensor){
|
||||
double[][] result = new double[tensor.length][];
|
||||
for (int i = 0; i < result.length; i++){
|
||||
result[i] = sigmoid(tensor[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
package com.visual.face.search.core.utils;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* SoftMaxUtil
|
||||
*/
|
||||
public class SoftMaxUtil {
|
||||
|
||||
/**
|
||||
* softMax
|
||||
* @param tensor
|
||||
* @return
|
||||
*/
|
||||
public static double[] softMax(double[] tensor){
|
||||
if(Arrays.stream(tensor).max().isPresent()){
|
||||
double maxValue = Arrays.stream(tensor).max().getAsDouble();
|
||||
double[] value = Arrays.stream(tensor).map(y-> Math.exp(y - maxValue)).toArray();
|
||||
double total = Arrays.stream(value).sum();
|
||||
return Arrays.stream(value).map(p -> p/total).toArray();
|
||||
}else{
|
||||
throw new NoSuchElementException("No value present");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* softMax
|
||||
* @param tensor
|
||||
* @return
|
||||
*/
|
||||
public double[][] softMax(double[][] tensor){
|
||||
double[][] result = new double[tensor.length][];
|
||||
for (int i = 0; i < result.length; i++){
|
||||
result[i] = softMax(tensor[i]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,7 @@
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>face-search-util</artifactId>
|
||||
<artifactId>face-search-engine</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
@ -24,7 +24,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.visual.face.search</groupId>
|
||||
<artifactId>face-search-util</artifactId>
|
||||
<artifactId>face-search-engine</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -90,6 +90,9 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
4
pom.xml
4
pom.xml
@ -18,7 +18,7 @@
|
||||
<module>face-search-core</module>
|
||||
<module>face-search-server</module>
|
||||
<module>face-search-client</module>
|
||||
<module>face-search-util</module>
|
||||
<module>face-search-engine</module>
|
||||
<module>face-search-test</module>
|
||||
</modules>
|
||||
|
||||
@ -55,7 +55,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.visual.face.search</groupId>
|
||||
<artifactId>face-search-util</artifactId>
|
||||
<artifactId>face-search-engine</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user