3

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

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

4

1 回答 1

3

这就是我所做的...

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()方法时,无需显式添加策略即可实现相同目的的快捷方式。

于 2017-11-28T12:53:29.560 回答