mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-27 20:36:31 -08:00
AutoBone: Add bulk recording loading, add height diff stat
This commit is contained in:
2 files changed
+79
-51
No files matched your search
@@ -115,38 +115,30 @@ public class SkeletonConfig extends EJBag {
|
||||
public void run() {
|
||||
try {
|
||||
File saveRecording = new File("ABRecording.abf");
|
||||
File loadRecording = new File("ABRecording_Load.abf");
|
||||
File recordFolder = new File("LoadRecordings");
|
||||
|
||||
if (loadRecording.exists()) {
|
||||
FastList<PoseFrame[]> frameRecordings = new FastList<PoseFrame[]>();
|
||||
|
||||
if (recordFolder.isDirectory()) {
|
||||
setText("Load");
|
||||
LogManager.log.info("[AutoBone] Detected recording at \"" + loadRecording.getPath() + "\", loading frames...");
|
||||
PoseFrame[] frames = PoseRecordIO.readFromFile(loadRecording);
|
||||
|
||||
if (frames == null) {
|
||||
throw new NullPointerException("Reading frames from \"" + loadRecording.getPath() + "\" failed...");
|
||||
}
|
||||
for (File file : recordFolder.listFiles()) {
|
||||
if (file.isFile() && org.apache.commons.lang3.StringUtils.endsWithIgnoreCase(file.getName(), ".abf")) {
|
||||
LogManager.log.info("[AutoBone] Detected recording at \"" + file.getPath() + "\", loading frames...");
|
||||
PoseFrame[] frames = PoseRecordIO.readFromFile(file);
|
||||
|
||||
FastList<PoseFrame> newFrames = new FastList<PoseFrame>(frames);
|
||||
int recordNumber = 1;
|
||||
for (;;) {
|
||||
File loadRecordingI = new File("ABRecording_Load" + recordNumber++ + ".abf");
|
||||
|
||||
if (loadRecordingI.exists()) {
|
||||
PoseFrame[] framesI = PoseRecordIO.readFromFile(loadRecordingI);
|
||||
|
||||
if (framesI == null) {
|
||||
throw new NullPointerException("Reading frames from \"" + loadRecordingI.getPath() + "\" failed...");
|
||||
if (frames == null) {
|
||||
LogManager.log.severe("Reading frames from \"" + file.getPath() + "\" failed...");
|
||||
} else {
|
||||
frameRecordings.add(frames);
|
||||
}
|
||||
|
||||
newFrames.addAll(framesI);
|
||||
} else {
|
||||
frames = newFrames.toArray(frames);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
autoBone.setFrames(frames);
|
||||
|
||||
if (frameRecordings.size() > 0) {
|
||||
setText("Wait");
|
||||
LogManager.log.info("[AutoBone] Done loading frames! Processing frames...");
|
||||
} else {
|
||||
@@ -161,37 +153,60 @@ public class SkeletonConfig extends EJBag {
|
||||
setText("Wait");
|
||||
LogManager.log.info("[AutoBone] Done recording! Exporting frames to \"" + saveRecording.getPath() + "\"...");
|
||||
PoseRecordIO.writeToFile(saveRecording, autoBone.getFrames());
|
||||
frameRecordings.add(autoBone.getFrames());
|
||||
|
||||
LogManager.log.info("[AutoBone] Done exporting! Processing frames...");
|
||||
}
|
||||
|
||||
int epochs = server.config.getInt("autobone.epochCount", AutoBone.NUM_EPOCHS);
|
||||
boolean calcInitError = server.config.getBoolean("autobone.calculateInitialError", true);
|
||||
float adjustRate = server.config.getFloat("autobone.adjustRate", AutoBone.INITIAL_ADJUSTMENT_RATE);
|
||||
float adjustRateDecay = server.config.getFloat("autobone.adjustRateDecay", AutoBone.ADJUSTMENT_RATE_DECAY);
|
||||
int minDataDist = server.config.getInt("autobone.minimumDataDistance", AutoBone.MIN_DATA_DISTANCE);
|
||||
int maxDataDist = server.config.getInt("autobone.maximumDataDistance", AutoBone.MAX_DATA_DISTANCE);
|
||||
float targetHeight = server.config.getFloat("autobone.manualTargetHeight", -1f);
|
||||
autoBone.processFrames(epochs, calcInitError, adjustRate, adjustRateDecay, minDataDist, maxDataDist, targetHeight);
|
||||
FastList<Float> heightPercentError = new FastList<Float>(frameRecordings.size());
|
||||
for (PoseFrame[] recording : frameRecordings) {
|
||||
autoBone.setFrames(recording);
|
||||
|
||||
LogManager.log.info("[AutoBone] Done processing!");
|
||||
int epochs = server.config.getInt("autobone.epochCount", AutoBone.NUM_EPOCHS);
|
||||
boolean calcInitError = server.config.getBoolean("autobone.calculateInitialError", true);
|
||||
float adjustRate = server.config.getFloat("autobone.adjustRate", AutoBone.INITIAL_ADJUSTMENT_RATE);
|
||||
float adjustRateDecay = server.config.getFloat("autobone.adjustRateDecay", AutoBone.ADJUSTMENT_RATE_DECAY);
|
||||
int minDataDist = server.config.getInt("autobone.minimumDataDistance", AutoBone.MIN_DATA_DISTANCE);
|
||||
int maxDataDist = server.config.getInt("autobone.maximumDataDistance", AutoBone.MAX_DATA_DISTANCE);
|
||||
float targetHeight = server.config.getFloat("autobone.manualTargetHeight", -1f);
|
||||
heightPercentError.add(autoBone.processFrames(epochs, calcInitError, adjustRate, adjustRateDecay, minDataDist, maxDataDist, targetHeight));
|
||||
|
||||
boolean first = true;
|
||||
StringBuilder configInfo = new StringBuilder("[");
|
||||
LogManager.log.info("[AutoBone] Done processing!");
|
||||
|
||||
for (Entry<String, Float> entry : autoBone.configs.entrySet()) {
|
||||
if (!first) {
|
||||
configInfo.append(", ");
|
||||
} else {
|
||||
first = false;
|
||||
boolean first = true;
|
||||
StringBuilder configInfo = new StringBuilder("[");
|
||||
|
||||
for (Entry<String, Float> entry : autoBone.configs.entrySet()) {
|
||||
if (!first) {
|
||||
configInfo.append(", ");
|
||||
} else {
|
||||
first = false;
|
||||
}
|
||||
|
||||
configInfo.append("{" + entry.getKey() + ": " + StringUtils.prettyNumber(entry.getValue()) + "}");
|
||||
}
|
||||
|
||||
configInfo.append("{" + entry.getKey() + ": " + StringUtils.prettyNumber(entry.getValue()) + "}");
|
||||
configInfo.append(']');
|
||||
|
||||
LogManager.log.info("[AutoBone] Length values: " + configInfo.toString());
|
||||
}
|
||||
|
||||
configInfo.append(']');
|
||||
if (heightPercentError.size() > 0) {
|
||||
float mean = 0f;
|
||||
for (float val : heightPercentError) {
|
||||
mean += val;
|
||||
}
|
||||
mean /= heightPercentError.size();
|
||||
|
||||
LogManager.log.info("[AutoBone] Length values: " + configInfo.toString());
|
||||
float std = 0f;
|
||||
for (float val : heightPercentError) {
|
||||
float stdVal = val - mean;
|
||||
std += stdVal * stdVal;
|
||||
}
|
||||
std = (float)Math.sqrt(std / heightPercentError.size());
|
||||
|
||||
LogManager.log.info("[AutoBone] Average height error: " + StringUtils.prettyNumber(mean, 6) + " (SD " + StringUtils.prettyNumber(std, 6) + ")");
|
||||
}
|
||||
|
||||
// Update GUI values after adjustment
|
||||
refreshAll();
|
||||
|
||||
@@ -18,12 +18,12 @@ import io.eiren.vr.processor.HumanSkeletonWithWaist;
|
||||
public class AutoBone {
|
||||
|
||||
public final static int MIN_DATA_DISTANCE = 1;
|
||||
public final static int MAX_DATA_DISTANCE = 2;
|
||||
public final static int MAX_DATA_DISTANCE = 1;
|
||||
|
||||
public final static int NUM_EPOCHS = 50;
|
||||
|
||||
public final static float INITIAL_ADJUSTMENT_RATE = 1f;
|
||||
public final static float ADJUSTMENT_RATE_DECAY = 1.01f;
|
||||
public final static float ADJUSTMENT_RATE_DECAY = 1.1f;
|
||||
|
||||
protected final static float SLIDE_ERROR_FACTOR = 1.0f;
|
||||
protected final static float OFFSET_ERROR_FACTOR = 0.0f;
|
||||
@@ -251,7 +251,7 @@ public class AutoBone {
|
||||
processFrames(epochs, calcInitError, adjustRate, adjustRateDecay, minDataDist, maxDataDist, -1f);
|
||||
}
|
||||
|
||||
public void processFrames(int epochs, boolean calcInitError, float adjustRate, float adjustRateDecay, int minDataDist, int maxDataDist, float targetHeight) {
|
||||
public float processFrames(int epochs, boolean calcInitError, float adjustRate, float adjustRateDecay, int minDataDist, int maxDataDist, float targetHeight) {
|
||||
Set<Entry<String, Float>> configSet = configs.entrySet();
|
||||
|
||||
SimpleSkeleton skeleton1 = new SimpleSkeleton(configSet);
|
||||
@@ -383,12 +383,14 @@ public class AutoBone {
|
||||
|
||||
if (finalNewLength > 0f) {
|
||||
// Keep values within a reasonable range
|
||||
/*
|
||||
Float val;
|
||||
switch (entry.getKey()) {
|
||||
/*
|
||||
case "Neck":
|
||||
val = configs.get("Waist");
|
||||
if (val == null || finalNewLength <= NECK_WAIST_RATIO_MIN * val || finalNewLength >= NECK_WAIST_RATIO_MAX * val) {
|
||||
if (val == null) {
|
||||
break;
|
||||
} else if (finalNewLength <= NECK_WAIST_RATIO_MIN * val || finalNewLength >= NECK_WAIST_RATIO_MAX * val) {
|
||||
entry.setValue(Math.min(Math.max(finalNewLength, NECK_WAIST_RATIO_MIN * val), NECK_WAIST_RATIO_MAX * val));
|
||||
} else {
|
||||
entry.setValue(finalNewLength);
|
||||
@@ -397,7 +399,9 @@ public class AutoBone {
|
||||
|
||||
case "Chest":
|
||||
val = configs.get("Waist");
|
||||
if (val == null || finalNewLength <= CHEST_WAIST_RATIO_MIN * val || finalNewLength >= CHEST_WAIST_RATIO_MAX * val) {
|
||||
if (val == null) {
|
||||
break;
|
||||
} else if (finalNewLength <= CHEST_WAIST_RATIO_MIN * val || finalNewLength >= CHEST_WAIST_RATIO_MAX * val) {
|
||||
entry.setValue(Math.min(Math.max(finalNewLength, CHEST_WAIST_RATIO_MIN * val), CHEST_WAIST_RATIO_MAX * val));
|
||||
} else {
|
||||
entry.setValue(finalNewLength);
|
||||
@@ -406,7 +410,9 @@ public class AutoBone {
|
||||
|
||||
case "Hips width":
|
||||
val = configs.get("Waist");
|
||||
if (val == null || finalNewLength < HIP_MIN || finalNewLength >= HIP_WAIST_RATIO_MAX * val) {
|
||||
if (val == null) {
|
||||
break;
|
||||
} else if (finalNewLength < HIP_MIN || finalNewLength >= HIP_WAIST_RATIO_MAX * val) {
|
||||
entry.setValue(Math.min(Math.max(finalNewLength, HIP_MIN), HIP_WAIST_RATIO_MAX * val));
|
||||
} else {
|
||||
entry.setValue(finalNewLength);
|
||||
@@ -415,7 +421,9 @@ public class AutoBone {
|
||||
|
||||
case "Legs length":
|
||||
val = configs.get("Waist");
|
||||
if (val == null || finalNewLength <= LEG_WAIST_RATIO_MIN * val || finalNewLength >= LEG_WAIST_RATIO_MAX * val) {
|
||||
if (val == null) {
|
||||
break;
|
||||
} else if (finalNewLength <= LEG_WAIST_RATIO_MIN * val || finalNewLength >= LEG_WAIST_RATIO_MAX * val) {
|
||||
entry.setValue(Math.min(Math.max(finalNewLength, LEG_WAIST_RATIO_MIN * val), LEG_WAIST_RATIO_MAX * val));
|
||||
} else {
|
||||
entry.setValue(finalNewLength);
|
||||
@@ -424,7 +432,9 @@ public class AutoBone {
|
||||
|
||||
case "Knee height":
|
||||
val = configs.get("Legs length");
|
||||
if (val == null || finalNewLength <= KNEE_LEG_RATIO_MIN * val || finalNewLength >= KNEE_LEG_RATIO_MAX * val) {
|
||||
if (val == null) {
|
||||
break;
|
||||
} else if (finalNewLength <= KNEE_LEG_RATIO_MIN * val || finalNewLength >= KNEE_LEG_RATIO_MAX * val) {
|
||||
entry.setValue(Math.min(Math.max(finalNewLength, KNEE_LEG_RATIO_MIN * val), KNEE_LEG_RATIO_MAX * val));
|
||||
} else {
|
||||
entry.setValue(finalNewLength);
|
||||
@@ -447,7 +457,8 @@ public class AutoBone {
|
||||
} while (++frameCursor1 < frames.length && ++frameCursor2 < frames.length);
|
||||
}
|
||||
|
||||
LogManager.log.info("[AutoBone] Target height: " + targetHeight + " New height: " + getHeight(configs));
|
||||
float finalHeight = getHeight(configs);
|
||||
LogManager.log.info("[AutoBone] Target height: " + targetHeight + " New height: " + finalHeight);
|
||||
|
||||
try {
|
||||
LogManager.log.info("[AutoBone] Ratios: [{Neck-Waist: " + StringUtils.prettyNumber(configs.get("Neck") / configs.get("Waist")) +
|
||||
@@ -464,6 +475,8 @@ public class AutoBone {
|
||||
LogManager.log.info("[AutoBone] Applying to skeleton failed, only saving configs...");
|
||||
saveConfigs();
|
||||
}
|
||||
|
||||
return Math.abs(finalHeight - targetHeight);
|
||||
}
|
||||
|
||||
protected static float getErrorDeriv(SimpleSkeleton skeleton1, SimpleSkeleton skeleton2, float heightChange) {
|
||||
|
||||
Reference in new issue
Block a user