mlpack
inception_score_impl.hpp
Go to the documentation of this file.
1 
12 #ifndef MLPACK_METHODS_METRICS_INCEPTION_SCORE_IMPL_HPP
13 #define MLPACK_METHODS_METRICS_INCEPTION_SCORE_IMPL_HPP
14 
15 // In case it hasn't been included yet.
16 #include "inception_score.hpp"
17 
18 namespace mlpack {
19 namespace ann /* Artificial Neural Network */ {
20 
21 template <typename ModelType>
22 double InceptionScore(ModelType model,
23  arma::mat images,
24  size_t splits)
25 {
26  size_t samples = images.n_cols;
27  size_t splitSize = samples / splits;
28  size_t remainder = samples % splits;
29  arma::mat preds;
30  model.Predict(images, preds);
31 
32  size_t index = 0;
33  arma::vec scores = arma::vec(splits);
34 
35  for (size_t i = 0; i < splits; ++i)
36  {
37  size_t curSize = splitSize;
38  if (remainder)
39  {
40  curSize++;
41  remainder--;
42  }
43  arma::mat curPreds =
44  arma::mat(preds.colptr(index), preds.n_rows, curSize, false, true);
45  arma::colvec c = arma::log(arma::mean(curPreds, 1));
46  arma::mat temp = arma::log(curPreds);
47  temp.each_col() -= c;
48  curPreds %= temp;
49  scores(i) = exp(arma::as_scalar(arma::mean(arma::sum(curPreds, 0))));
50  index += curSize;
51  }
52 
53  return arma::mean(scores);
54 }
55 
56 } // namespace ann
57 } // namespace mlpack
58 
59 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
double InceptionScore(ModelType Model, arma::mat images, size_t splits=1)
Function that computes Inception Score for a set of images produced by a GAN.
Definition: inception_score_impl.hpp:22