TensorFlow.NET.Samples/ImageProcessing/RetrainImageClassifierTransferLearningTFNET.cs
/// <summary>
/// Runs a final evaluation on an eval graph using the test data set.
/// </summary>
/// <param name="train_session"></param>
/// <param name="module_spec"></param>
/// <param name="class_count"></param>
/// <param name="image_lists"></param>
/// <param name="jpeg_data_tensor"></param>
/// <param name="decoded_image_tensor"></param>
/// <param name="resized_image_tensor"></param>
/// <param name="bottleneck_tensor"></param>
Runs a final evaluation on an eval graph using the test data set.
Runs a final evaluation on an eval graph using the test data set .
private (float, NDArray) run_final_eval(Session train_session, object module_spec, int class_count,
            Dictionary<string, Dictionary<string, string[]>> image_lists,
            Tensor jpeg_data_tensor, Tensor decoded_image_tensor,
            Tensor resized_image_tensor, Tensor bottleneck_tensor)
        {
            var (test_bottlenecks, test_ground_truth, test_filenames) = get_random_cached_bottlenecks(train_session, image_lists,
                                    test_batch_size, "testing", bottleneck_dir, images_folder_for_training, jpeg_data_tensor,
                                    decoded_image_tensor, resized_image_tensor, bottleneck_tensor, tfhub_module);
            var (eval_session, _, bottleneck_input, ground_truth_input, evaluation_step,
                prediction) = build_eval_session(class_count);
            var results = eval_session.run(new Tensor[] { evaluation_step, prediction },
                  new FeedItem(bottleneck_input, test_bottlenecks),
                  new FeedItem(ground_truth_input, test_ground_truth));
            print($"final test accuracy: {((float)results[0] * 100).ToString("G4")}% (N={len(test_bottlenecks)})");
            return (results[0], results[1]);
        }
private ( float , NDArray ) run_final_eval ( Session train_session , object module_spec , int class_count , Dictionary < string , Dictionary < string , string [ ] > > image_lists , Tensor jpeg_data_tensor , Tensor decoded_image_tensor , Tensor resized_image_tensor , Tensor bottleneck_tensor ) { var ( test_bottlenecks , test_ground_truth , test_filenames ) = get_random_cached_bottlenecks ( train_session , image_lists , test_batch_size , " " , bottleneck_dir , images_folder_for_training , jpeg_data_tensor , decoded_image_tensor , resized_image_tensor , bottleneck_tensor , tfhub_module ) ; var ( eval_session , _ , bottleneck_input , ground_truth_input , evaluation_step , prediction ) = build_eval_session ( class_count ) ; var results = eval_session . run ( new Tensor [ ] { evaluation_step , prediction } , new FeedItem ( bottleneck_input , test_bottlenecks ) , new FeedItem ( ground_truth_input , test_ground_truth ) ) ; print ( $" final test accuracy:  { ( ( float ) results [ 0 ] * 100 ) . ToString ( " " ) } % (N= { len ( test_bottlenecks ) } ) " ) ; return ( results [ 0 ] , results [ 1 ] ) ; }
Runs a final evaluation on an eval graph using the test data set.
Runs a final evaluation on an eval graph using the test data set .
train_session
Session
None
module_spec
object
None
class_count
int
None
image_lists
Dictionary<string, Dictionary<string, string[]>>
None
jpeg_data_tensor
Tensor
None
decoded_image_tensor
Tensor
None
resized_image_tensor
Tensor
None
bottleneck_tensor
Tensor
None