From e3b125f2443fd0f8a324aadeb10be500820032df Mon Sep 17 00:00:00 2001 From: ButterscotchVanilla Date: Sat, 14 Aug 2021 03:41:33 -0400 Subject: [PATCH] AutoBone: Add bulk recording loading, add height diff stat --- .../java/io/eiren/gui/SkeletonConfig.java | 97 +++++++++++-------- .../java/io/eiren/gui/autobone/AutoBone.java | 33 +++++-- 2 files changed, 79 insertions(+), 51 deletions(-) diff --git a/src/main/java/io/eiren/gui/SkeletonConfig.java b/src/main/java/io/eiren/gui/SkeletonConfig.java index fe16ec3b8..4dce27191 100644 --- a/src/main/java/io/eiren/gui/SkeletonConfig.java +++ b/src/main/java/io/eiren/gui/SkeletonConfig.java @@ -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 frameRecordings = new FastList(); + + 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 newFrames = new FastList(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 heightPercentError = new FastList(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 entry : autoBone.configs.entrySet()) { - if (!first) { - configInfo.append(", "); - } else { - first = false; + boolean first = true; + StringBuilder configInfo = new StringBuilder("["); + + for (Entry 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(); diff --git a/src/main/java/io/eiren/gui/autobone/AutoBone.java b/src/main/java/io/eiren/gui/autobone/AutoBone.java index 461a2b7f4..5279369b2 100644 --- a/src/main/java/io/eiren/gui/autobone/AutoBone.java +++ b/src/main/java/io/eiren/gui/autobone/AutoBone.java @@ -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> 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) {