Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // set up a learning pipeline
- var pipeline = mlContext.Transforms
- // step 1: load the images
- .LoadImages(
- outputColumnName: "input",
- imageFolder: "images",
- inputColumnName: nameof(ImageNetData.ImagePath))
- // step 2: resize the images to 224x224
- .Append(mlContext.Transforms.ResizeImages(
- outputColumnName: "input",
- imageWidth: 224,
- imageHeight: 224,
- inputColumnName: "input"))
- // step 3: extract pixels in a format the TF model can understand
- // these interleave and offset values are identical to the images the model was trained on
- .Append(mlContext.Transforms.ExtractPixels(
- outputColumnName: "input",
- interleavePixelColors: true,
- offsetImage: 117))
- // step 4: load the TensorFlow model
- .Append(mlContext.Model.LoadTensorFlowModel("models/tensorflow_inception_graph.pb")
- // step 5: score the images using the TF model
- .ScoreTensorFlowModel(
- outputColumnNames: new[] { "softmax2" },
- inputColumnNames: new[] { "input" },
- addBatchDimensionInput:true));
- // train the model on the data file
- Console.WriteLine("Start training model....");
- var model = pipeline.Fit(data);
- Console.WriteLine("Model training complete!");
- // the rest of the code goes here....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement