深度学习-异常检测

该博客探讨了如何使用DL4J库中的无预训练自编码网络进行异常检测,特别是在识别异常手写数字上的应用。正常数字在重构过程中产生的误差较低,而异常数字则表现出较高的重构误差。
摘要由CSDN通过智能技术生成

我们看看dl4j用无预训练的自编码网络来识别异常手写数字,常规数字重构错误低,异常数字重构错误高

public class MNISTAnomalyExample {

    public static void main(String[] args) throws Exception {

        //Set up network. 784 in/out (as MNIST images are 28x28).//设置网络,老套路,图片是28*28
        //784 -> 250 -> 10 -> 250 -> 784自编码各层节点数量是784,250,10,250,784,最后肯定只用前3层
        MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
                .seed(12345)
                .iterations(1)
                .weightInit(WeightInit.XAVIER)
                .updater(Updater.ADAGRAD)//更新器采用自动更改学习速率,梯度越大,学习率衰减越快,梯度越小,学习率衰减越慢,与以往梯度模之和的开平方成反比
                .activation("relu")
                .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT)
                .learningRate(0.05)
                .regularization(true).l2(0.0001)
                .list()
                .layer(0, new DenseLayer.Builder().nIn(784).nOut(250)
                        .build())
                .layer(1, new DenseLayer.Builder().nIn(250).nOut(10)
                        .build())
                .layer(2, new DenseLayer.Builder().nIn(10).nOut(250)
                        .build())
                .layer(3, new OutputLayer.Builder().nIn(250).nOut(784)
                        .lossFunction(LossFunctions.LossFunction.MSE)
                        .build())
                .pretrain(false).backprop(true)
                .build();

        MultiLayerNetwork net = new MultiLayerNetwork(conf);
        net.setListeners(Collections.singletonList((IterationListener) new ScoreIterationListener(1)));

        //Load data and split into training and testing sets. 40000 train, 10000 test//装载数据划分训练测试集,4w训练,1w测试
        DataSetIterator iter = new MnistDataSetIterator(100,50000,false);//手写数据迭代器,批大小100,5w是数据量,是否二值化否

        List<INDArray> featuresTrain = new ArrayList<>();
        List<INDArray> featuresTest = new ArrayList<>();
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值