• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FeatureUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.nd4j.linalg.util.FeatureUtil的典型用法代码示例。如果您正苦于以下问题:Java FeatureUtil类的具体用法?Java FeatureUtil怎么用?Java FeatureUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



FeatureUtil类属于org.nd4j.linalg.util包,在下文中一共展示了FeatureUtil类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: convertMat

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public Pair<INDArray, opencv_core.Mat> convertMat(byte[] byteFeature) {
    INDArray label = FeatureUtil.toOutcomeVector(byteFeature[0], NUM_LABELS);; // first value in the 3073 byte array
    opencv_core.Mat image = new opencv_core.Mat(HEIGHT, WIDTH, CV_8UC(CHANNELS)); // feature are 3072
    ByteBuffer imageData = image.createBuffer();

    for (int i = 0; i < HEIGHT * WIDTH; i++) {
        imageData.put(3 * i, byteFeature[i + 1 + 2 * HEIGHT * WIDTH]); // blue
        imageData.put(3 * i + 1, byteFeature[i + 1 + HEIGHT * WIDTH]); // green
        imageData.put(3 * i + 2, byteFeature[i + 1]); // red
    }
    //        if (useSpecialPreProcessCifar) {
    //            image = convertCifar(image);
    //        }

    return new Pair<>(label, image);
}
 
开发者ID:deeplearning4j,项目名称:DataVec,代码行数:17,代码来源:CifarLoader.java


示例2: testSplitTestAndTrain

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testSplitTestAndTrain() throws Exception {
    INDArray labels = FeatureUtil.toOutcomeMatrix(new int[] {0, 0, 0, 0, 0, 0, 0, 0}, 1);
    DataSet data = new DataSet(Nd4j.rand(8, 1), labels);

    SplitTestAndTrain train = data.splitTestAndTrain(6, new Random(1));
    assertEquals(train.getTrain().getLabels().length(), 6);

    SplitTestAndTrain train2 = data.splitTestAndTrain(6, new Random(1));
    assertEquals(getFailureMessage(), train.getTrain().getFeatureMatrix(), train2.getTrain().getFeatureMatrix());

    DataSet x0 = new IrisDataSetIterator(150, 150).next();
    SplitTestAndTrain testAndTrain = x0.splitTestAndTrain(10);
    assertArrayEquals(new int[] {10, 4}, testAndTrain.getTrain().getFeatureMatrix().shape());
    assertEquals(x0.getFeatureMatrix().getRows(ArrayUtil.range(0, 10)), testAndTrain.getTrain().getFeatureMatrix());
    assertEquals(x0.getLabels().getRows(ArrayUtil.range(0, 10)), testAndTrain.getTrain().getLabels());


}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:20,代码来源:DataSetTest.java


示例3: testStringListLabels

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testStringListLabels() {
    INDArray trueOutcome = FeatureUtil.toOutcomeVector(0, 2);
    INDArray predictedOutcome = FeatureUtil.toOutcomeVector(0, 2);

    List<String> labelsList = new ArrayList<>();
    labelsList.add("hobbs");
    labelsList.add("cal");

    Evaluation eval = new Evaluation(labelsList);

    eval.eval(trueOutcome, predictedOutcome);
    assertEquals(1, eval.classCount(0));
    assertEquals(labelsList.get(0), eval.getClassLabel(0));

}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:17,代码来源:EvalTest.java


示例4: testStringHashLabels

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testStringHashLabels() {
    INDArray trueOutcome = FeatureUtil.toOutcomeVector(0, 2);
    INDArray predictedOutcome = FeatureUtil.toOutcomeVector(0, 2);

    Map<Integer, String> labelsMap = new HashMap<>();
    labelsMap.put(0, "hobbs");
    labelsMap.put(1, "cal");

    Evaluation eval = new Evaluation(labelsMap);

    eval.eval(trueOutcome, predictedOutcome);
    assertEquals(1, eval.classCount(0));
    assertEquals(labelsMap.get(0), eval.getClassLabel(0));

}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:17,代码来源:EvalTest.java


示例5: convert

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Override
public DataSet convert(Collection<Collection<Writable>> records, int numLabels) {
    //all but last label
    DataSet ret = new DataSet(Nd4j.create(records.size(), records.iterator().next().size() - 1),
                    Nd4j.create(records.size(), numLabels));
    //  INDArray ret = Nd4j.create(records.size(),records.iterator().next().size() - 1);
    int count = 0;
    for (Collection<Writable> record : records) {
        List<Writable> list;
        if (record instanceof List) {
            list = (List<Writable>) record;
        } else
            list = new ArrayList<>(record);
        DataSet d = new DataSet(Nd4j.create(record.size() - 1),
                        FeatureUtil.toOutcomeVector(list.get(list.size() - 1).toInt(), numLabels));
        ret.addRow(d, count++);

    }


    return ret;
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:23,代码来源:CSVRecordToDataSet.java


示例6: setOutcome

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Sets the outcome of a particular example
 * @param example the example to applyTransformToDestination
 * @param label the label of the outcome
 */
@Override
public void setOutcome(int example, int label) {
    if(example > numExamples())
        throw new IllegalArgumentException("No example at " + example);
    if(label > numOutcomes() || label < 0)
        throw new IllegalArgumentException("Illegal label");

    INDArray outcome = FeatureUtil.toOutcomeVector(label, numOutcomes());
    getLabels().putRow(example,outcome);
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:16,代码来源:DataSet.java


示例7: setOutcome

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Sets the outcome of a particular example
 *
 * @param example the example to transform
 * @param label   the label of the outcome
 */
@Override
public void setOutcome(int example, int label) {
    if (example > numExamples())
        throw new IllegalArgumentException("No example at " + example);
    if (label > numOutcomes() || label < 0)
        throw new IllegalArgumentException("Illegal label");

    INDArray outcome = FeatureUtil.toOutcomeVector(label, numOutcomes());
    getLabels().putRow(example, outcome);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:17,代码来源:DataSet.java


示例8: getDataFor

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public DataSet getDataFor(int i) {
    File image = new File(images.get(i));
    int outcome = outcomes.indexOf(image.getParentFile().getAbsolutePath());
    try {
        return new DataSet(loader.asRowVector(image), FeatureUtil.toOutcomeVector(outcome, outcomes.size()));
    } catch (Exception e) {
        throw new IllegalStateException("Unable to getFromOrigin data for image " + i + " for path " + images.get(i));
    }
}
 
开发者ID:jpatanooga,项目名称:Canova,代码行数:10,代码来源:LFWLoader.java


示例9: fit

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Fit the model
 *
 * @param examples the examples to classify (one example in each row)
 * @param labels   the labels for each example (the number of labels must match
 */
@Override
public void fit(INDArray examples, int[] labels) {
    INDArray outcomeMatrix = FeatureUtil.toOutcomeMatrix(labels, numLabels());
    fit(examples, outcomeMatrix);

}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:13,代码来源:LossLayer.java


示例10: fit

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Fit the model
 *
 * @param examples the examples to classify (one example in each row)
 * @param labels   the labels for each example (the number of labels must match
 */
@Override
public void fit(INDArray examples, int[] labels) {
    org.deeplearning4j.nn.conf.layers.OutputLayer layerConf =
                    (org.deeplearning4j.nn.conf.layers.OutputLayer) getOutputLayer().conf().getLayer();
    fit(examples, FeatureUtil.toOutcomeMatrix(labels, layerConf.getNOut()));
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:13,代码来源:MultiLayerNetwork.java


示例11: fromCache

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
private DataSet fromCache() {
    INDArray outcomes = null;
    INDArray input = null;
    input = Nd4j.create(batch, vec.lookupTable().layerSize() * vec.getWindow());
    outcomes = Nd4j.create(batch, labels.size());
    for (int i = 0; i < batch; i++) {
        input.putRow(i, WindowConverter.asExampleMatrix(cache.get(i), vec));
        int idx = labels.indexOf(cache.get(i).getLabel());
        if (idx < 0)
            idx = 0;
        outcomes.putRow(i, FeatureUtil.toOutcomeVector(idx, labels.size()));
    }
    return new DataSet(input, outcomes);

}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:16,代码来源:Word2VecDataFetcher.java


示例12: toLabelMatrix

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public static INDArray toLabelMatrix(List<String> labels, List<Window> windows) {
    int columns = labels.size();
    INDArray ret = Nd4j.create(windows.size(), columns);
    for (int i = 0; i < ret.rows(); i++) {
        ret.putRow(i, FeatureUtil.toOutcomeVector(labels.indexOf(windows.get(i).getLabel()), labels.size()));
    }
    return ret;
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:9,代码来源:WordConverter.java


示例13: vectorize

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 * Vectorizes the passed in text treating it as one document
 *
 * @param text  the text to vectorize
 * @param label the label of the text
 * @return a dataset with a transform of weights(relative to impl; could be word counts or tfidf scores)
 */
@Override
public DataSet vectorize(String text, String label) {
    INDArray input = transform(text);
    INDArray labelMatrix = FeatureUtil.toOutcomeVector(labelsSource.indexOf(label), labelsSource.size());

    return new DataSet(input, labelMatrix);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:15,代码来源:TfidfVectorizer.java


示例14: vectorize

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Override
public DataSet vectorize(String text, String label) {
    INDArray input = transform(text);
    INDArray labelMatrix = FeatureUtil.toOutcomeVector(labelsSource.indexOf(label), labelsSource.size());

    return new DataSet(input, labelMatrix);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:8,代码来源:BagOfWordsVectorizer.java


示例15: testEval

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testEval() {
    int classNum = 5;
    Evaluation eval = new Evaluation(classNum);

    // Testing the edge case when some classes do not have true positive
    INDArray trueOutcome = FeatureUtil.toOutcomeVector(0, 5); //[1,0,0,0,0]
    INDArray predictedOutcome = FeatureUtil.toOutcomeVector(0, 5); //[1,0,0,0,0]
    eval.eval(trueOutcome, predictedOutcome);
    assertEquals(1, eval.classCount(0));
    assertEquals(1.0, eval.f1(), 1e-1);

    // Testing more than one sample. eval() does not reset the Evaluation instance
    INDArray trueOutcome2 = FeatureUtil.toOutcomeVector(1, 5); //[0,1,0,0,0]
    INDArray predictedOutcome2 = FeatureUtil.toOutcomeVector(0, 5); //[1,0,0,0,0]
    eval.eval(trueOutcome2, predictedOutcome2);
    // Verified with sklearn in Python
    // from sklearn.metrics import classification_report
    // classification_report(['a', 'a'], ['a', 'b'], labels=['a', 'b', 'c', 'd', 'e'])
    assertEquals(eval.f1(), 0.6, 1e-1);
    // The first entry is 0 label
    assertEquals(1, eval.classCount(0));
    // The first entry is 1 label
    assertEquals(1, eval.classCount(1));
    // Class 0: one positive, one negative -> (one true positive, one false positive); no true/false negatives
    assertEquals(1, eval.positive().get(0), 0);
    assertEquals(1, eval.negative().get(0), 0);
    assertEquals(1, eval.truePositives().get(0), 0);
    assertEquals(1, eval.falsePositives().get(0), 0);
    assertEquals(0, eval.trueNegatives().get(0), 0);
    assertEquals(0, eval.falseNegatives().get(0), 0);


    // The rest are negative
    assertEquals(1, eval.negative().get(0), 0);
    // 2 rows and only the first is correct
    assertEquals(0.5, eval.accuracy(), 0);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:39,代码来源:EvalTest.java


示例16: testDenseToOutputLayer

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
@Test
public void testDenseToOutputLayer() {
    final int numRows = 76;
    final int numColumns = 76;
    int nChannels = 3;
    int outputNum = 6;
    int seed = 123;

    //setup the network
    MultiLayerConfiguration.Builder builder = new NeuralNetConfiguration.Builder().seed(seed)
                    .l1(1e-1).l2(2e-4).dropOut(0.5).miniBatch(true)
                    .optimizationAlgo(OptimizationAlgorithm.CONJUGATE_GRADIENT).list()
                    .layer(0, new ConvolutionLayer.Builder(5, 5).nOut(5).dropOut(0.5).weightInit(WeightInit.XAVIER)
                                    .activation(Activation.RELU).build())
                    .layer(1, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
                                    .build())
                    .layer(2, new ConvolutionLayer.Builder(3, 3).nOut(10).dropOut(0.5).weightInit(WeightInit.XAVIER)
                                    .activation(Activation.RELU).build())
                    .layer(3, new SubsamplingLayer.Builder(SubsamplingLayer.PoolingType.MAX, new int[] {2, 2})
                                    .build())
                    .layer(4, new DenseLayer.Builder().nOut(100).activation(Activation.RELU).build())
                    .layer(5, new OutputLayer.Builder(LossFunctions.LossFunction.NEGATIVELOGLIKELIHOOD)
                                    .nOut(outputNum).weightInit(WeightInit.XAVIER).activation(Activation.SOFTMAX)
                                    .build())
                    .backprop(true).pretrain(false)
                    .setInputType(InputType.convolutional(numRows, numColumns, nChannels));

    DataSet d = new DataSet(Nd4j.rand(12345, 10, nChannels, numRows, numColumns),
                    FeatureUtil.toOutcomeMatrix(new int[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 6));
    MultiLayerNetwork network = new MultiLayerNetwork(builder.build());
    network.init();
    network.fit(d);

}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:35,代码来源:ConvolutionLayerSetupTest.java


示例17: getData

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
private static INDArray getData() {
    Random r = new Random(1);
    int[] result = new int[window];
    for (int i = 0; i < window; i++) {
        result[i] = r.nextInt(nIn);
    }
    return FeatureUtil.toOutcomeMatrix(result, nIn);
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:9,代码来源:GravesLSTMOutputTest.java


示例18: fromLabeledPoint

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
/**
 *
 * @param point
 * @param numPossibleLabels
 * @return {@link DataSet}
 */
private static DataSet fromLabeledPoint(LabeledPoint point, int numPossibleLabels) {
    Vector features = point.features();
    double label = point.label();
    return new DataSet(Nd4j.create(features.toArray()),
                    FeatureUtil.toOutcomeVector((int) label, numPossibleLabels));
}
 
开发者ID:deeplearning4j,项目名称:deeplearning4j,代码行数:13,代码来源:MLLibUtil.java


示例19: main

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public static void main(String[] args) {
    SparkConf conf = new SparkConf().setMaster("spark://babar1.musigma.com:7077")
            .setAppName("Mnist Classification Pipeline (Java)");
    SparkContext jsc = new SparkContext(conf);
    SQLContext jsql = new SQLContext(jsc);

    String imagesPath =  "file://" + System.getProperty("user.home") + "/MNIST/images-idx1-ubyte";
    String labelsPath =  "file://" + System.getProperty("user.home") + "/MNIST/labels-idx1-ubyte";
    Map<String, String> params = new HashMap<>();
    params.put("imagesPath", imagesPath);
    params.put("labelsPath", labelsPath);
    params.put("recordsPerPartition", "400");
    params.put("maxRecords", "2000");

    DataFrame data = jsql.read().format(DefaultSource.class.getName())
            .options(params).load();

    System.out.println("\nLoaded Mnist dataframe:");
    data.show(100);

    DataFrame trainingData = data.sample(false, 0.8, 123);
    DataFrame testData = data.except(trainingData);

    StandardScaler scaler = new StandardScaler()
            .setInputCol("features")
            .setOutputCol("scaledFeatures");
    NeuralNetworkClassification classification = new NeuralNetworkClassification()
            .setFeaturesCol("scaledFeatures")
            .setEpochs(2)
            .setConf(getConfiguration());
    Pipeline pipeline = new Pipeline().setStages(new PipelineStage[]{
            scaler, classification});

    System.out.println("\nTraining...");
    PipelineModel model = pipeline.fit(trainingData);

    System.out.println("\nTesting...");
    DataFrame predictions = model.transform(testData);
    predictions.cache();

    System.out.println("\nTest Results:");
    predictions.show(100);

    Evaluation eval = new Evaluation(outputNum);
    Row[] rows = predictions.select("label","prediction").collect();
    for(int i = 0; i < rows.length; i++) {
        INDArray label = FeatureUtil.toOutcomeVector((int) rows[i].getDouble(0), outputNum);
        INDArray prediction = FeatureUtil.toOutcomeVector((int) rows[i].getDouble(1), outputNum);
        eval.eval(label, prediction);
    }

    System.out.println(eval.stats());
}
 
开发者ID:nitish11,项目名称:deeplearning4j-spark-ml-examples,代码行数:54,代码来源:JavaMnistClassification.java


示例20: main

import org.nd4j.linalg.util.FeatureUtil; //导入依赖的package包/类
public static void main(String[] args) {
    SparkConf conf = new SparkConf().setMaster("local[*]")
            .setAppName("Cards Identification Pipeline (Java)");
    SparkContext jsc = new SparkContext(conf);
    SQLContext jsql = new SQLContext(jsc);

    String imagesPath =  "file://" + System.getProperty("user.home") + "/MNIST/images-idx1-ubyte";
    String labelsPath =  "file://" + System.getProperty("user.home") + "/MNIST/labels-idx1-ubyte";
    Map<String, String> params = new HashMap<>();
    params.put("imagesPath", imagesPath);
    params.put("labelsPath", labelsPath);
    params.put("recordsPerPartition", "400");
    params.put("maxRecords", "2000");

    DataFrame data = jsql.read().format(DefaultSource.class.getName())
            .options(params).load();

    System.out.println("\nLoaded Card Images dataframe:");
    data.show(100);

    DataFrame trainingData = data.sample(false, 0.8, 123);
    DataFrame testData = data.except(trainingData);

    StandardScaler scaler = new StandardScaler()
            .setInputCol("features")
            .setOutputCol("scaledFeatures");
    NeuralNetworkClassification classification = new NeuralNetworkClassification()
            .setFeaturesCol("scaledFeatures")
            .setEpochs(2)
            .setConf(getConfiguration());
    Pipeline pipeline = new Pipeline().setStages(new PipelineStage[]{
            scaler, classification});

    System.out.println("\nTraining...");
    PipelineModel model = pipeline.fit(trainingData);

    System.out.println("\nTesting...");
    DataFrame predictions = model.transform(testData);
    predictions.cache();

    System.out.println("\nTest Results:");
    predictions.show(100);

    Evaluation eval = new Evaluation(outputNum);
    Row[] rows = predictions.select("label","prediction").collect();
    for(int i = 0; i < rows.length; i++) {
        INDArray label = FeatureUtil.toOutcomeVector((int) rows[i].getDouble(0), outputNum);
        INDArray prediction = FeatureUtil.toOutcomeVector((int) rows[i].getDouble(1), outputNum);
        eval.eval(label, prediction);
    }

    System.out.println(eval.stats());
}
 
开发者ID:nitish11,项目名称:deeplearning4j-spark-ml-examples,代码行数:54,代码来源:JavaCardsIdentification.java



注:本文中的org.nd4j.linalg.util.FeatureUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UserProvider类代码示例发布时间:2022-05-23
下一篇:
Java CaretListener类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap