Search in sources :

Example 1 with KerasSequentialClassifier

use of com.alibaba.alink.pipeline.classification.KerasSequentialClassifier in project Alink by alibaba.

the class Chap25 method cnn.

public static void cnn(BatchOperator<?> train_set, BatchOperator<?> test_set) throws Exception {
    BatchOperator.setParallelism(1);
    new Pipeline().add(new VectorFunction().setSelectedCol("vec").setFuncName("Scale").setWithVariable(1.0 / 255.0)).add(new VectorToTensor().setTensorDataType("float").setTensorShape(28, 28).setSelectedCol("vec").setOutputCol("tensor").setReservedCols("label")).add(new KerasSequentialClassifier().setTensorCol("tensor").setLabelCol("label").setPredictionCol("pred").setLayers("Reshape((28, 28, 1))", "Conv2D(32, kernel_size=(3, 3), activation='relu')", "MaxPooling2D(pool_size=(2, 2))", "Conv2D(64, kernel_size=(3, 3), activation='relu')", "MaxPooling2D(pool_size=(2, 2))", "Flatten()", "Dropout(0.5)").setNumEpochs(20).setValidationSplit(0.1).setSaveBestOnly(true).setBestMetric("sparse_categorical_accuracy")).fit(train_set).transform(test_set).link(new EvalMultiClassBatchOp().setLabelCol("label").setPredictionCol("pred").lazyPrintMetrics());
    BatchOperator.execute();
}
Also used : KerasSequentialClassifier(com.alibaba.alink.pipeline.classification.KerasSequentialClassifier) EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) VectorFunction(com.alibaba.alink.pipeline.dataproc.vector.VectorFunction) VectorToTensor(com.alibaba.alink.pipeline.dataproc.VectorToTensor) Pipeline(com.alibaba.alink.pipeline.Pipeline)

Example 2 with KerasSequentialClassifier

use of com.alibaba.alink.pipeline.classification.KerasSequentialClassifier in project Alink by alibaba.

the class Chap25 method dnn.

public static void dnn(BatchOperator<?> train_set, BatchOperator<?> test_set) throws Exception {
    BatchOperator.setParallelism(1);
    new Pipeline().add(new VectorFunction().setSelectedCol("vec").setFuncName("Scale").setWithVariable(1.0 / 255.0)).add(new VectorToTensor().setTensorDataType("float").setSelectedCol("vec").setOutputCol("tensor").setReservedCols("label")).add(new KerasSequentialClassifier().setTensorCol("tensor").setLabelCol("label").setPredictionCol("pred").setLayers("Dense(256, activation='relu')", "Dense(128, activation='relu')").setNumEpochs(50).setBatchSize(512).setValidationSplit(0.1).setSaveBestOnly(true).setBestMetric("sparse_categorical_accuracy")).fit(train_set).transform(test_set).link(new EvalMultiClassBatchOp().setLabelCol("label").setPredictionCol("pred").lazyPrintMetrics());
    BatchOperator.execute();
}
Also used : KerasSequentialClassifier(com.alibaba.alink.pipeline.classification.KerasSequentialClassifier) EvalMultiClassBatchOp(com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp) VectorFunction(com.alibaba.alink.pipeline.dataproc.vector.VectorFunction) VectorToTensor(com.alibaba.alink.pipeline.dataproc.VectorToTensor) Pipeline(com.alibaba.alink.pipeline.Pipeline)

Aggregations

EvalMultiClassBatchOp (com.alibaba.alink.operator.batch.evaluation.EvalMultiClassBatchOp)2 Pipeline (com.alibaba.alink.pipeline.Pipeline)2 KerasSequentialClassifier (com.alibaba.alink.pipeline.classification.KerasSequentialClassifier)2 VectorToTensor (com.alibaba.alink.pipeline.dataproc.VectorToTensor)2 VectorFunction (com.alibaba.alink.pipeline.dataproc.vector.VectorFunction)2