<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # R 中的 TF 核心 API 我們在第 1 章中了解了 TensorFlow 核心 API。在 R 中,該 API 使用 `tensorflow` R 包實現。 作為一個例子,我們提供了 MLP 模型的演練,用于在以下鏈接中對來自 MNIST 數據集的手寫數字進行分類: [https://tensorflow.rstudio.com/tensorflow/articles/examples/mnist_softmax.html](https://tensorflow.rstudio.com/tensorflow/articles/examples/mnist_softmax.html) 。 您可以按照 Jupyter R 筆記本中的代碼`ch-17a_TFCore_in_R`。 1. 首先,加載庫: ```r library(tensorflow) ``` 1. 定義超參數: ```r batch_size <- 128 num_classes <- 10 steps <- 1000 ``` 1. 準備數據: ```r datasets <- tf$contrib$learn$datasets mnist <- datasets$mnist$read_data_sets("MNIST-data", one_hot = TRUE) ``` 數據從 TensorFlow 數據集庫加載,并已標準化為[0,1]范圍。 1. 定義模型: ```r # Create the model x <- tf$placeholder(tf$float32, shape(NULL, 784L)) W <- tf$Variable(tf$zeros(shape(784L, num_classes))) b <- tf$Variable(tf$zeros(shape(num_classes))) y <- tf$nn$softmax(tf$matmul(x, W) + b) # Define loss and optimizer y_ <- tf$placeholder(tf$float32, shape(NULL, num_classes)) cross_entropy <- tf$reduce_mean(-tf$reduce_sum(y_ * log(y), reduction_indices=1L)) train_step <- tf$train$GradientDescentOptimizer(0.5)$minimize(cross_entropy) ``` 1. 訓練模型: ```r # Create session and initialize variables sess <- tf$Session() sess$run(tf$global_variables_initializer()) # Train for (i in 1:steps) { batches <- mnist$train$next_batch(batch_size) batch_xs <- batches[[1]] batch_ys <- batches[[2]] sess$run(train_step, feed_dict = dict(x = batch_xs, y_ = batch_ys)) } ``` 1. 評估模型: ```r correct_prediction <- tf$equal(tf$argmax(y, 1L), tf$argmax(y_, 1L)) accuracy <- tf$reduce_mean(tf$cast(correct_prediction, tf$float32)) score <-sess$run(accuracy, feed_dict = dict(x = mnist$test$images, y_ = mnist$test$labels)) cat('Test accuracy:', score, '\n') ``` 輸出如下: ```r Test accuracy: 0.9185 ``` 太酷了! 通過以下鏈接查找 R 中 TF Core 的更多示例:[https://tensorflow.rstudio.com/tensorflow/articles/examples/](https://tensorflow.rstudio.com/tensorflow/articles/examples/) 有關`tensorflow` R 包的更多文檔可以在以下鏈接中找到:[https://tensorflow.rstudio.com/tensorflow/reference/](https://tensorflow.rstudio.com/tensorflow/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>

                              哎呀哎呀视频在线观看