You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Zero/ZeroLevel.NN/Architectures/AgeDetectors/GenderAgeEstimator.cs

38 lines
1.1 KiB

2 years ago
using Microsoft.ML.OnnxRuntime.Tensors;
using SixLabors.ImageSharp;
using ZeroLevel.NN.Models;
namespace ZeroLevel.NN
{
public class GenderAgeEstimator
: SSDNN
{
private const int INPUT_WIDTH = 64;
private const int INPUT_HEIGHT = 64;
public GenderAgeEstimator(string modelPath, bool gpu = false) : base(modelPath, gpu)
{
}
public (Gender, int) Predict(Image image)
{
var input = MakeInput(image,
new ImagePreprocessorOptions(INPUT_WIDTH, INPUT_HEIGHT, PredictorChannelType.ChannelFirst)
.ApplyNormilization()
.ApplyAxeInversion());
return Predict(input);
}
public (Gender, int) Predict(Tensor<float> input)
{
float[] variances = null;
Extract(new Dictionary<string, Tensor<float>> { { "input", input } }, d =>
{
variances = d.First().Value.ToArray();
});
var gender = Argmax(variances[0..2]) == 0 ? Gender.Male : Gender.Feemale;
return (gender, (int)variances[2]);
}
}
}

Powered by TurnKey Linux.