- 移除重复的 ResultFiles 内部类和相关工具方法实现 - Anime2Segmenter 和 AnimeSegmenter 继承自抽象基类 Segmenter - Anime2SegmentationResult与 AnimeSegmentationResult 继承 SegmentationResult - 重命名 LabelPalette 为 BiSeNetLabelPalette 并调整其引用 - 更新模型路径配置以匹配新的文件命名约定 - 删除冗余的 getLabels() 和 getPalette() 方法定义 - 简化 segmentAndSave 方法中的类型转换逻辑- 移除已被继承方法替代的手动资源管理代码 - 调整 import 语句以反映包结构调整- 清理不再需要的独立主测试函数入口点- 修改字段访问权限以符合继承设计模式 - 替换具体的返回类型为更通用的 SegmentationResult 接口- 整合公共功能至基类减少子类间重复代码 - 统一分割后处理流程提高模块复用性 - 引入泛型支持增强 Wrapper 类型安全性 - 更新注释文档保持与最新架构同步 - 优化异常处理策略统一关闭资源方式 - 规范文件命名规则便于未来维护扩展 - 提取共通逻辑到父类降低耦合度 - 完善类型检查避免运行时 ClassCastException 风险
34 lines
1.2 KiB
Java
34 lines
1.2 KiB
Java
package com.chuangzhou.vivid2D.test;
|
|
|
|
import com.chuangzhou.vivid2D.ai.face_parsing.BiSeNetVividModelWrapper;
|
|
|
|
import java.io.PrintStream;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.file.Paths;
|
|
import java.util.Set;
|
|
|
|
/**
|
|
* 测试人脸解析模型
|
|
*/
|
|
public class AITest {
|
|
public static void main(String[] args) throws Exception {
|
|
System.setOut(new PrintStream(System.out, true, StandardCharsets.UTF_8));
|
|
System.setErr(new PrintStream(System.err, true, StandardCharsets.UTF_8));
|
|
BiSeNetVividModelWrapper wrapper = BiSeNetVividModelWrapper.load(Paths.get("C:\\models\\bisenet_face_parsing.pt"));
|
|
|
|
// 使用 BiSeNet 人脸解析模型的 18 个非背景标签
|
|
Set<String> faceLabels = Set.of(
|
|
"skin", "nose", "eye_left", "eye_right", "eyebrow_left",
|
|
"eyebrow_right", "ear_left", "ear_right", "mouth", "lip_upper",
|
|
"lip_lower", "hair", "hat", "earring", "necklace", "clothes",
|
|
"facial_hair", "neck"
|
|
);
|
|
|
|
wrapper.segmentAndSave(
|
|
Paths.get("C:\\Users\\Administrator\\Desktop\\b_f4881214f0d18b6cf848b6736f554821.png").toFile(),
|
|
faceLabels,
|
|
Paths.get("C:\\models\\out")
|
|
);
|
|
}
|
|
}
|