Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. // set up a learning pipeline
  2. var pipeline = mlContext.Transforms
  3.  
  4. // step 1: load the images
  5. .LoadImages(
  6. outputColumnName: "input",
  7. imageFolder: "images",
  8. inputColumnName: nameof(ImageNetData.ImagePath))
  9.  
  10. // step 2: resize the images to 224x224
  11. .Append(mlContext.Transforms.ResizeImages(
  12. outputColumnName: "input",
  13. imageWidth: 224,
  14. imageHeight: 224,
  15. inputColumnName: "input"))
  16.  
  17. // step 3: extract pixels in a format the TF model can understand
  18. // these interleave and offset values are identical to the images the model was trained on
  19. .Append(mlContext.Transforms.ExtractPixels(
  20. outputColumnName: "input",
  21. interleavePixelColors: true,
  22. offsetImage: 117))
  23.  
  24. // step 4: load the TensorFlow model
  25. .Append(mlContext.Model.LoadTensorFlowModel("models/tensorflow_inception_graph.pb")
  26.  
  27. // step 5: score the images using the TF model
  28. .ScoreTensorFlowModel(
  29. outputColumnNames: new[] { "softmax2" },
  30. inputColumnNames: new[] { "input" },
  31. addBatchDimensionInput:true));
  32.  
  33. // train the model on the data file
  34. Console.WriteLine("Start training model....");
  35. var model = pipeline.Fit(data);
  36. Console.WriteLine("Model training complete!");
  37.  
  38. // the rest of the code goes here....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement