<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # R 中的 TF 估計器 API 我們在第 2 章中了解了 TensorFlow 估計器 API。在 R 中,此 API 使用 `tfestimator` R 包實現。 例如,我們提供了 MLP 模型的演練,用于在以下鏈接中對來自 MNIST 數據集的手寫數字進行分類: [https://tensorflow.rstudio.com/tfestimators/articles/examples/mnist.html](https://tensorflow.rstudio.com/tfestimators/articles/examples/mnist.html) 。 您可以按照 Jupyter R 筆記本中的代碼`ch-17b_TFE_Ttimator_in_R`。 1. 首先,加載庫: ```r library(tensorflow) library(tfestimators) ``` 1. 定義超參數: ```r batch_size <- 128 n_classes <- 10 n_steps <- 100 ``` 1. 準備數據: ```r # initialize data directory data_dir <- "~/datasets/mnist" dir.create(data_dir, recursive = TRUE, showWarnings = FALSE) # download the MNIST data sets, and read them into R sources <- list( train = list( x = "https://storage.googleapis.com/cvdf-datasets/mnist/train-images-idx3-ubyte.gz", y = "https://storage.googleapis.com/cvdf-datasets/mnist/train-labels-idx1-ubyte.gz" ), test = list( x = "https://storage.googleapis.com/cvdf-datasets/mnist/t10k-images-idx3-ubyte.gz", y = "https://storage.googleapis.com/cvdf-datasets/mnist/t10k-labels-idx1-ubyte.gz" ) ) # read an MNIST file (encoded in IDX format) read_idx <- function(file) { # create binary connection to file conn <- gzfile(file, open = "rb") on.exit(close(conn), add = TRUE) # read the magic number as sequence of 4 bytes magic <- readBin(conn, what="raw", n=4, endian="big") ndims <- as.integer(magic[[4]]) # read the dimensions (32-bit integers) dims <- readBin(conn,what="integer",n=ndims,endian="big") # read the rest in as a raw vector data <- readBin(conn,what="raw",n=prod(dims),endian="big") # convert to an integer vecto converted <- as.integer(data) # return plain vector for 1-dim array if (length(dims) == 1) return(converted) # wrap 3D data into matrix matrix(converted,nrow=dims[1],ncol=prod(dims[-1]),byrow=TRUE) } mnist <- rapply(sources,classes="character",how ="list",function(url) { # download + extract the file at the URL target <- file.path(data_dir, basename(url)) if (!file.exists(target)) download.file(url, target) # read the IDX file read_idx(target) }) # convert training data intensities to 0-1 range mnist$train$x <- mnist$train$x / 255 mnist$test$x <- mnist$test$x / 255 ``` 從下載的 gzip 文件中讀取數據,然后歸一化以落入[0,1]范圍。 1. 定義模型: ```r # construct a linear classifier classifier <- linear_classifier( feature_columns = feature_columns( column_numeric("x", shape = shape(784L)) ), n_classes = n_classes # 10 digits ) # construct an input function generator mnist_input_fn <- function(data, ...) { input_fn( data, response = "y", features = "x", batch_size = batch_size, ... ) } ``` 1. 訓練模型: ```r train(classifier,input_fn=mnist_input_fn(mnist$train),steps=n_steps) ``` 1. 評估模型: ```r evaluate(classifier,input_fn=mnist_input_fn(mnist$test),steps=200) ``` 輸出如下: ```r Evaluation completed after 79 steps but 200 steps was specified ``` | average_loss | 損失 | global_step | 準確性 | | --- | --- | --- | --- | | 0.35656 | 45.13418 | 100 | 0.9057 | 太酷!! 通過以下鏈接查找 R 中 TF 估計器的更多示例:[https://tensorflow.rstudio.com/tfestimators/articles/examples/ ](https://tensorflow.rstudio.com/tfestimators/articles/examples/) 有關`tensorflow` R 包的更多文檔可以在以下鏈接中找到:[https://tensorflow.rstudio.com/tfestimators/reference/](https://tensorflow.rstudio.com/tfestimators/reference/)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看