Created
          December 17, 2024 11:00 
        
      - 
      
- 
        Save thomvolker/52589e75795d6af73584bfcbe0022c5e to your computer and use it in GitHub Desktop. 
    Using Google Colab with R and tensorflow.ipynb
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "nbformat": 4, | |
| "nbformat_minor": 0, | |
| "metadata": { | |
| "colab": { | |
| "provenance": [], | |
| "gpuType": "V28", | |
| "authorship_tag": "ABX9TyMRFvdOHdFlv3/J5rbICLhq", | |
| "include_colab_link": true | |
| }, | |
| "kernelspec": { | |
| "name": "ir", | |
| "display_name": "R" | |
| }, | |
| "language_info": { | |
| "name": "R" | |
| }, | |
| "accelerator": "TPU" | |
| }, | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": { | |
| "id": "view-in-github", | |
| "colab_type": "text" | |
| }, | |
| "source": [ | |
| "<a href=\"https://colab.research.google.com/gist/thomvolker/52589e75795d6af73584bfcbe0022c5e/using-google-colab-with-r-and-tensorflow.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "source": [ | |
| "First, we specify that we want to run `R` in `python`, which can be done by going to `Runtime > Change runtime type` and changing runtime type to `R`.\n", | |
| "\n", | |
| "Second, we can proceed as usual. The following code should get you started." | |
| ], | |
| "metadata": { | |
| "id": "jvT54p1qT-Q6" | |
| } | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "# Load the required packages\n", | |
| "install.packages(\"tidyverse\")\n", | |
| "install.packages(\"keras\")" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "Xrsb1lJHUlFe", | |
| "outputId": "77055e7c-2f26-4be6-db1c-2b84e8ae9d0b" | |
| }, | |
| "execution_count": 1, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "Installing package into ‘/usr/local/lib/R/site-library’\n", | |
| "(as ‘lib’ is unspecified)\n", | |
| "\n", | |
| "Installing package into ‘/usr/local/lib/R/site-library’\n", | |
| "(as ‘lib’ is unspecified)\n", | |
| "\n", | |
| "also installing the dependencies ‘RcppTOML’, ‘here’, ‘png’, ‘config’, ‘tfautograph’, ‘reticulate’, ‘tensorflow’, ‘tfruns’, ‘zeallot’\n", | |
| "\n", | |
| "\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "library(tidyverse)\n", | |
| "library(keras)\n" | |
| ], | |
| "metadata": { | |
| "colab": { | |
| "base_uri": "https://localhost:8080/" | |
| }, | |
| "id": "FOJttu3qVGIG", | |
| "outputId": "a2c6fac9-052a-4687-8513-cd64b43d7e6a" | |
| }, | |
| "execution_count": 2, | |
| "outputs": [ | |
| { | |
| "output_type": "stream", | |
| "name": "stderr", | |
| "text": [ | |
| "── \u001b[1mAttaching core tidyverse packages\u001b[22m ──────────────────────── tidyverse 2.0.0 ──\n", | |
| "\u001b[32m✔\u001b[39m \u001b[34mdplyr \u001b[39m 1.1.4 \u001b[32m✔\u001b[39m \u001b[34mreadr \u001b[39m 2.1.5\n", | |
| "\u001b[32m✔\u001b[39m \u001b[34mforcats \u001b[39m 1.0.0 \u001b[32m✔\u001b[39m \u001b[34mstringr \u001b[39m 1.5.1\n", | |
| "\u001b[32m✔\u001b[39m \u001b[34mggplot2 \u001b[39m 3.5.1 \u001b[32m✔\u001b[39m \u001b[34mtibble \u001b[39m 3.2.1\n", | |
| "\u001b[32m✔\u001b[39m \u001b[34mlubridate\u001b[39m 1.9.4 \u001b[32m✔\u001b[39m \u001b[34mtidyr \u001b[39m 1.3.1\n", | |
| "\u001b[32m✔\u001b[39m \u001b[34mpurrr \u001b[39m 1.0.2 \n", | |
| "── \u001b[1mConflicts\u001b[22m ────────────────────────────────────────── tidyverse_conflicts() ──\n", | |
| "\u001b[31m✖\u001b[39m \u001b[34mdplyr\u001b[39m::\u001b[32mfilter()\u001b[39m masks \u001b[34mstats\u001b[39m::filter()\n", | |
| "\u001b[31m✖\u001b[39m \u001b[34mdplyr\u001b[39m::\u001b[32mlag()\u001b[39m masks \u001b[34mstats\u001b[39m::lag()\n", | |
| "\u001b[36mℹ\u001b[39m Use the conflicted package (\u001b[3m\u001b[34m<http://conflicted.r-lib.org/>\u001b[39m\u001b[23m) to force all conflicts to become errors\n" | |
| ] | |
| } | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "mnist <- dataset_mnist()" | |
| ], | |
| "metadata": { | |
| "id": "nPjXFpgYVpnM" | |
| }, | |
| "execution_count": 3, | |
| "outputs": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "source": [ | |
| "plot_img <- function(img, col = gray.colors(255, start = 1, end = 0), ...) {\n", | |
| " image(t(img), asp = 1, ylim = c(1.1, -0.1), col = col, bty = \"n\", axes = FALSE, ...)\n", | |
| "}" | |
| ], | |
| "metadata": { | |
| "collapsed": true, | |
| "id": "qjVA8sCQV3E6" | |
| }, | |
| "execution_count": 4, | |
| "outputs": [] | |
| } | |
| ] | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment