在ND4J / DL4J中重复使用标准化器

时间:2017-07-26 16:06:23

标签: java deeplearning4j nd4j

我想知道在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.
    // ...
}

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

1 个答案:

答案 0 :(得分:2)

这就是我做的......

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 Docs说.getDefaults()获得了一个序列化程序,配置了内置规范化器实现的策略。当您使用NormalizerStandardize时,getDefaults()提供了实现相同目标的简便方法,而无需明确添加策略。