概述

本文简要描述使用Wolfram Mathematica训练一个分类器和人脸识别分类器

代码

分类器

训练集代码,共六张图片

c = Classify[{ \!\(\*
GraphicsBox[
TagBox[RasterBox[CompressedData["
###
<Photos> -> "identify"
###
"], {{0, 191}, {264, 
         0}}, {0, 255},
ColorFunction->RGBColor],
BoxForm`ImageTag["Byte", ColorSpace -> "RGB", Interleaving -> True],
Selectable->False],
DefaultBaseStyle->"ImageGraphics",
ImageSize->Automatic,
ImageSizeRaw->{264, 191},
PlotRange->{{0, 264}, {0, 191}}]\) -> "bird"},  

代码预览:

以下是分类器的训练结果

ClassifierFunction[
Association[
 "ExampleNumber" -> 6, "ClassNumber" -> 3, 
  "Input" -> Association[
   "Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
Association[
      "Input" -> Association["f1" -> Association["Type" -> "Image"]], 
       "Output" -> Association[
        "f1" -> Association["Type" -> "Image", "Weight" -> 1]], 
       "Preprocessor" -> MachineLearning`MLProcessor["Sequence", 
Association["Processors" -> {
MachineLearning`MLProcessor["List"], 
MachineLearning`MLProcessor["WrapMLDataset", 
Association[
             "FeatureTypes" -> {"Image"}, "FeatureKeys" -> {"f1"}, 
              "FeatureWeights" -> Automatic, 
              "ExampleWeights" -> Automatic, 
              "RawExample" -> Missing["KeyAbsent", "RawExample"]]]}]],
        "ScalarFeature" -> True, "Invertibility" -> "Perfect", 
       "Missing" -> "Allowed"]], 
    "Processor" -> MachineLearning`MLProcessor["Sequence", 
Association[
      "Input" -> Association[
        "f1" -> Association["Type" -> "Image", "Weight" -> 1]], 
       "Output" -> Association[
        "f1" -> Association[
          "Type" -> "NumericalVector", "Weight" -> 1]], 
       "Processors" -> {
MachineLearning`MLProcessor["ImageExtractNumericalVector", 
Association[
          "Invertibility" -> "Impossible", "Missing" -> "Forbidden", 
           "Input" -> Association[
            "f1" -> Association["Type" -> "Image", "Weight" -> 1]], 
           "ExtractorName" -> "ImageGeneric", 
           "ExtractorVersion" -> "V1", "FeatureNumber" -> Automatic, 
           "Shake" -> False, "Version" -> {12., 0}, 
           "ID" -> 3346607681367433095, 
           "Output" -> Association[
            "f1" -> Association[
              "Type" -> "NumericalVector", "Weight" -> 1]]]], 
MachineLearning`MLProcessor["DimensionReduceNumericalVector", 
Association[
          "Invertibility" -> "Approximate", "Missing" -> "Imputed", 
           "Input" -> Association[
            "f1" -> Association[
              "Type" -> "NumericalVector", "Weight" -> 1]], 
           "Reducer" -> DimensionReducerFunction[
Association[
             "ExampleNumber" -> 6, 
              "Imputer" -> MachineLearning`MLProcessor[
               "ImputeMissing", 
Association[
                "Invertibility" -> "Perfect", "Missing" -> "Imputed", 
                 "Input" -> Association[
                  "f1" -> Association[
                    "Type" -> "NumericalVector", "Weight" -> 1]], 
                 "Fill" -> CompressedData["
1:eJxt
###
Omitting Compressed Data ...
###
89//8Ddf6Hyg==
"],"UnsignedInteger8"], "Byte", 
            ColorSpace -> "RGB", Interleaving -> True]}, 
         "ID" -> 7806654962102425149]], 
Association[
      "RawExample" -> False, "ExampleNumber" -> 1, 
       "ExampleWeights" -> 1, "LogDensityRatios" -> 0]], 
    "TrainingTime" -> 2.315137, "MaxTrainingMemory" -> 88886472, 
    "DataMemory" -> 2495998, "FunctionMemory" -> 1720184, 
    "LanguageVersion" -> {12., 0}, 
    "Date" -> DateObject[{
      2019, 10, 31, 11, 22, 11.160906`7.800274436570366}, "Instant", 
      "Gregorian", 8.], "ProcessorCount" -> 6, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", 
    "SystemWordLength" -> 64, "Evaluations" -> {}]]]

人脸分类

代码

ClassifierFunction[
Association[
 "ExampleNumber" -> 8, "ClassNumber" -> 2, 
  "Input" -> Association[
   "Preprocessor" -> MachineLearning`MLProcessor["ToMLDataset", 
Association[
      "Input" -> Association["f1" -> Association["Type" -> "Image"]], 
       "Output" -> Association[
        "f1" -> Association["Type" -> "Image", "Weight" -> 1]], 
       "Preprocessor" -> MachineLearning`MLProcessor["Sequence", 
Association["Processors" -> {
MachineLearning`MLProcessor["List"], 
MachineLearning`MLProcessor["WrapMLDataset", 
Association[
             "FeatureTypes" -> {"Image"}, "FeatureKeys" -> {"f1"}, 
              "FeatureWeights" -> Automatic, 
              "ExampleWeights" -> Automatic, 
              "RawExample" -> Missing["KeyAbsent", "RawExample"]]]}]],
        "ScalarFeature" -> True, "Invertibility" -> "Perfect", 
       "Missing" -> "Allowed"]], 
    "Processor" -> MachineLearning`MLProcessor["Sequence", 
Association[
      "Input" -> Association[
        "f1" -> Association["Type" -> "Image", "Weight" -> 1]], 
       "Output" -> Association[
        "f1" -> Association[
          "Type" -> "NumericalVector", "Weight" -> 1]], 
       "Processors" -> {
MachineLearning`MLProcessor["ImputeMissing", 
Association[
          "Invertibility" -> "Perfect", "Missing" -> "Imputed", 
           "Input" -> Association[
            "f1" -> Association["Type" -> "Image", "Weight" -> 1]], 
           "Fill" -> Image[NumericArray[CompressedData["
1:eJx
###
Omitting Compressed Data
###
eMTQ==
"],"UnsignedInteger8"], 
              "RGB", "XYZ"], Interleaving -> True]}, 
         "ID" -> 326628518844981278]], 
Association[
      "ExampleNumber" -> 1, "ExampleWeights" -> 1, 
       "LogDensityRatios" -> 0, "RawExample" -> False]], 
    "TrainingTime" -> 1.228831, "MaxTrainingMemory" -> 11714360, 
    "DataMemory" -> 618120, "FunctionMemory" -> 637720, 
    "LanguageVersion" -> {12., 0}, 
    "Date" -> DateObject[{
      2019, 10, 29, 14, 56, 10.679697`7.781133917674143}, "Instant", 
      "Gregorian", 8.], "ProcessorCount" -> 6, 
    "ProcessorType" -> "x86-64", "OperatingSystem" -> "MacOSX", 
    "SystemWordLength" -> 64, "Evaluations" -> {}]]]
0%