fix(translator): 修复 RecognitionTranslator 中 BGR/RGB 通道顺序错误#33
Open
SickoGt wants to merge 1 commit into
Open
Conversation
问题: - cv2.imread() 返回 BGR 通道顺序 - DJL Image.toNDArray(manager, Image.Flag.COLOR) 返回 RGB 通道顺序 - 通道不对齐导致归一化结果与 Python 参考实现偏差显著 根本原因: - 模型训练时使用 OpenCV 读取图像,输入为 BGR 格式 - DJL 未做通道转换直接送入模型,导致推理结果异常 - 实测均值偏差约 1.0(预期 < 0.02) 修复方案: - 在 toNDArray() 后添加 NDArray.flip(2),翻转通道顺序 RGB → BGR - flip 在 resize 之前执行,保证预处理流程与 Python 一致 验证结果: Python : mean=-0.4013394 min=-3.0466321 max=2.1347151 Java : mean=-0.4169087 min=-2.9247181 max=2.1143961 Δmean : 0.016(可接受范围,来自 resize 插值算法差异) 影响范围:RecognitionTranslator#processInput
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题:
根本原因:
修复方案:
验证结果:
Python : mean=-0.4013394 min=-3.0466321 max=2.1347151
Java : mean=-0.4169087 min=-2.9247181 max=2.1143961
Δmean : 0.016(可接受范围,来自 resize 插值算法差异)
影响范围:RecognitionTranslator#processInput