gpt4 book ai didi

java - 在 ND4J/DL4J 中重用归一化器

转载 作者:行者123 更新时间:2023-12-05 04:09:43 26 4
gpt4 key购买 nike

我想知道在 ND4J/DL4J 中重用标准化器的正确方法是什么。目前,我保存如下:

final DataNormalization normalizer = new NormalizerStandardize();
normalizer.fit( trainingData );
normalizer.transform( trainingData );
normalizer.transform( testData );

try {
final NormalizerSerializer normalizerSerializer = new NormalizerSerializer();
normalizerSerializer.addStrategy( new StandardizeSerializerStrategy() );
normalizerSerializer.write( normalizer, path );
} catch ( final IOException e ) {
// ...
}

并通过以下方式加载它:

try {
final NormalizerSerializer normalizerSerializer = new NormalizerSerializer();
normalizerSerializer.addStrategy( new StandardizeSerializerStrategy() );
final DataNormalization normalizer = normalizerSerializer.restore( path );
} catch ( final Exception e ) { // Throws Exception instead of IOException.
// ...
}

可以吗?遗憾的是,我无法在文档中找到更多信息。

最佳答案

这就是我做的...

DataNormalization normalizer = new NormaizerStandardize();
normalizer.fit(trainingData);
normalizer.transform(trainingData);

保存

NormalizerSerializer saver = NormalizerSerializer.getDefaults();
File normalsFile = new File("fileName");
saver.write(normalizer,normalsFile);

恢复它

NormalizerSerializer loader = NormalizerSerializer.getDefaults();
DataNormalization restoredNormalizer = loader.restore(normalsFile);
restoredNormalizer.transform(testData);

ND4J Java 文档说 .getDefaults() 获取一个序列化器,配置了内置规范化器实现的策略。当您使用 NormalizerStandardize 时,getDefaults() 提供了一种无需显式添加策略即可达到相同目的的快捷方式。

关于java - 在 ND4J/DL4J 中重用归一化器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45332181/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com