CINXE.COM

Train and serve a TensorFlow model with TensorFlow Serving  |  TFX

<!doctype html> <html lang="en" dir="ltr"> <head> <meta name="google-signin-client-id" content="157101835696-ooapojlodmuabs2do2vuhhnf90bccmoi.apps.googleusercontent.com"> <meta name="google-signin-scope" content="profile email https://www.googleapis.com/auth/developerprofiles https://www.googleapis.com/auth/developerprofiles.award"> <meta property="og:site_name" content="TensorFlow"> <meta property="og:type" content="website"><meta name="theme-color" content="#ff6f00"><meta charset="utf-8"> <meta content="IE=Edge" http-equiv="X-UA-Compatible"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="manifest" href="/_pwa/tensorflow/manifest.json" crossorigin="use-credentials"> <link rel="preconnect" href="//www.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.gstatic.com" crossorigin> <link rel="preconnect" href="//fonts.googleapis.com" crossorigin> <link rel="preconnect" href="//apis.google.com" crossorigin> <link rel="preconnect" href="//www.google-analytics.com" crossorigin><link rel="stylesheet" href="//fonts.googleapis.com/css?family=Google+Sans:400,500|Roboto:400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap"> <link rel="stylesheet" href="//fonts.googleapis.com/css2?family=Material+Icons&family=Material+Symbols+Outlined&display=block"><link rel="stylesheet" href="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/css/app.css"> <link rel="shortcut icon" href="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/images/favicon.png"> <link rel="apple-touch-icon" href="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/images/apple-touch-icon-180x180.png"><link rel="canonical" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple"><link rel="search" type="application/opensearchdescription+xml" title="TensorFlow" href="https://www.tensorflow.org/s/opensearch.xml"> <link rel="alternate" hreflang="en" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple" /><link rel="alternate" hreflang="x-default" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple" /><link rel="alternate" hreflang="ar" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=ar" /><link rel="alternate" hreflang="bn" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=bn" /><link rel="alternate" hreflang="fa" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=fa" /><link rel="alternate" hreflang="fr" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=fr" /><link rel="alternate" hreflang="he" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=he" /><link rel="alternate" hreflang="hi" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=hi" /><link rel="alternate" hreflang="id" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=id" /><link rel="alternate" hreflang="it" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=it" /><link rel="alternate" hreflang="ja" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=ja" /><link rel="alternate" hreflang="ko" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=ko" /><link rel="alternate" hreflang="pl" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=pl" /><link rel="alternate" hreflang="pt-BR" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=pt-br" /><link rel="alternate" hreflang="ru" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=ru" /><link rel="alternate" hreflang="es-419" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=es-419" /><link rel="alternate" hreflang="th" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=th" /><link rel="alternate" hreflang="tr" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=tr" /><link rel="alternate" hreflang="vi" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple?hl=vi" /><title>Train and serve a TensorFlow model with TensorFlow Serving &nbsp;|&nbsp; TFX</title> <meta property="og:title" content="Train and serve a TensorFlow model with TensorFlow Serving &nbsp;|&nbsp; TFX"><meta property="og:url" content="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple"><meta property="og:image" content="https://www.tensorflow.org/static/site-assets/images/project-logos/tensorflow-extended-tfx-logo-social.png"> <meta property="og:image:width" content="1200"> <meta property="og:image:height" content="675"><meta property="og:locale" content="en"><meta name="twitter:card" content="summary_large_image"><script type="application/ld+json"> { "@context": "https://schema.org", "@type": "Article", "headline": "Train and serve a TensorFlow model with TensorFlow Serving" } </script><script type="application/ld+json"> { "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{ "@type": "ListItem", "position": 1, "name": "For Production", "item": "https://www.tensorflow.org/tfx" },{ "@type": "ListItem", "position": 2, "name": "Train and serve a TensorFlow model with TensorFlow Serving", "item": "https://www.tensorflow.org/tfx/tutorials/serving/rest_simple" }] } </script> <link rel="stylesheet" href="/extras.css"></head> <body class="" template="page" theme="tensorflow-theme" type="article" layout="docs" display-toc pending> <devsite-progress type="indeterminate" id="app-progress"></devsite-progress> <section class="devsite-wrapper"> <devsite-cookie-notification-bar></devsite-cookie-notification-bar><devsite-header role="banner"> <div class="devsite-header--inner nocontent"> <div class="devsite-top-logo-row-wrapper-wrapper"> <div class="devsite-top-logo-row-wrapper"> <div class="devsite-top-logo-row"> <button type="button" id="devsite-hamburger-menu" class="devsite-header-icon-button button-flat material-icons gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Navigation menu button" visually-hidden aria-label="Open menu"> </button> <div class="devsite-product-name-wrapper"> <a href="/" class="devsite-site-logo-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Site logo" track-type="globalNav" track-name="tensorFlow" track-metadata-position="nav" track-metadata-eventDetail="nav"> <picture> <img src="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/images/lockup.svg" class="devsite-site-logo" alt="TensorFlow"> </picture> </a> <span class="devsite-product-name"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> </li> </ul> </span> </div> <div class="devsite-top-logo-row-middle"> <div class="devsite-header-upper-tabs"> <devsite-tabs class="upper-tabs"> <nav class="devsite-tabs-wrapper" aria-label="Upper tabs"> <tab > <a href="https://www.tensorflow.org/install" track-metadata-eventdetail="https://www.tensorflow.org/install" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - install" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Install" track-name="install" > Install </a> </tab> <tab class="devsite-dropdown devsite-active "> <a href="https://www.tensorflow.org/learn" track-metadata-eventdetail="https://www.tensorflow.org/learn" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - learn" track-metadata-module="primary nav" aria-label="Learn, selected" data-category="Site-Wide Custom Events" data-label="Tab: Learn" track-name="learn" > Learn </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Dropdown menu for Learn" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/learn" track-metadata-position="nav - learn" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Learn" track-name="learn" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></a> <div class="devsite-tabs-dropdown" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column tfo-menu-column-learn"> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/learn" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/learn" track-metadata-position="nav - learn" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Introduction </div> <div class="devsite-nav-item-description"> New to TensorFlow? </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/tutorials" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/tutorials" track-metadata-position="nav - learn" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Tutorials </div> <div class="devsite-nav-item-description"> Learn how to use TensorFlow with end-to-end examples </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/guide" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/guide" track-metadata-position="nav - learn" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Guide </div> <div class="devsite-nav-item-description"> Learn framework concepts and components </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/resources/learn-ml" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/resources/learn-ml" track-metadata-position="nav - learn" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Learn ML </div> <div class="devsite-nav-item-description"> Educational resources to master your path with TensorFlow </div> </a> </li> </ul> </div> </div> </div> </tab> <tab class="devsite-dropdown "> <a href="https://www.tensorflow.org/api" track-metadata-eventdetail="https://www.tensorflow.org/api" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - api" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: API" track-name="api" > API </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Dropdown menu for API" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/api" track-metadata-position="nav - api" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: API" track-name="api" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></a> <div class="devsite-tabs-dropdown" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/api/stable" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/api/stable" track-metadata-position="nav - api" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> TensorFlow (v2.16.1) </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/versions" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/versions" track-metadata-position="nav - api" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Versions… </div> </a> </li> </ul> </div> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://js.tensorflow.org/api/latest/" track-type="nav" track-metadata-eventdetail="https://js.tensorflow.org/api/latest/" track-metadata-position="nav - api" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> TensorFlow.js </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/lite/api_docs" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/lite/api_docs" track-metadata-position="nav - api" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> TensorFlow Lite </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/tfx/api_docs" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/tfx/api_docs" track-metadata-position="nav - api" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> TFX </div> </a> </li> </ul> </div> </div> </div> </tab> <tab class="devsite-dropdown "> <a href="https://www.tensorflow.org/resources/models-datasets" track-metadata-eventdetail="https://www.tensorflow.org/resources/models-datasets" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - ecosystem" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Ecosystem" track-name="ecosystem" > Ecosystem </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Dropdown menu for Ecosystem" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/resources/models-datasets" track-metadata-position="nav - ecosystem" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Ecosystem" track-name="ecosystem" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></a> <div class="devsite-tabs-dropdown" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-title" role="heading" tooltip>LIBRARIES</li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/js" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/js" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="libraries" tooltip > <div class="devsite-nav-item-title"> TensorFlow.js </div> <div class="devsite-nav-item-description"> Develop web ML applications in JavaScript </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/lite" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/lite" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="libraries" tooltip > <div class="devsite-nav-item-title"> TensorFlow Lite </div> <div class="devsite-nav-item-description"> Deploy ML on mobile, microcontrollers and other edge devices </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/tfx" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/tfx" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="libraries" tooltip > <div class="devsite-nav-item-title"> TFX </div> <div class="devsite-nav-item-description"> Build production ML pipelines </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/resources/libraries-extensions" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/resources/libraries-extensions" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="libraries" tooltip > <div class="devsite-nav-item-title"> All libraries </div> <div class="devsite-nav-item-description"> Create advanced models and extend TensorFlow </div> </a> </li> </ul> </div> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-title" role="heading" tooltip>RESOURCES</li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/resources/models-datasets" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/resources/models-datasets" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="resources" tooltip > <div class="devsite-nav-item-title"> Models & datasets </div> <div class="devsite-nav-item-description"> Pre-trained models and datasets built by Google and the community </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/resources/tools" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/resources/tools" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="resources" tooltip > <div class="devsite-nav-item-title"> Tools </div> <div class="devsite-nav-item-description"> Tools to support and accelerate TensorFlow workflows </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/responsible_ai" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/responsible_ai" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="resources" tooltip > <div class="devsite-nav-item-title"> Responsible AI </div> <div class="devsite-nav-item-description"> Resources for every stage of the ML workflow </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/resources/recommendation-systems" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/resources/recommendation-systems" track-metadata-position="nav - ecosystem" track-metadata-module="tertiary nav" track-metadata-module_headline="resources" tooltip > <div class="devsite-nav-item-title"> Recommendation systems </div> <div class="devsite-nav-item-description"> Build recommendation systems with open source tools </div> </a> </li> </ul> </div> </div> </div> </tab> <tab class="devsite-dropdown "> <a href="https://www.tensorflow.org/community" track-metadata-eventdetail="https://www.tensorflow.org/community" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - community" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" > Community </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Dropdown menu for Community" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/community" track-metadata-position="nav - community" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></a> <div class="devsite-tabs-dropdown" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/community/groups" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/community/groups" track-metadata-position="nav - community" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Groups </div> <div class="devsite-nav-item-description"> User groups, interest groups and mailing lists </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/community/contribute" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/community/contribute" track-metadata-position="nav - community" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Contribute </div> <div class="devsite-nav-item-description"> Guide for contributing to code and documentation </div> </a> </li> <li class="devsite-nav-item"> <a href="https://blog.tensorflow.org/" track-type="nav" track-metadata-eventdetail="https://blog.tensorflow.org/" track-metadata-position="nav - community" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Blog </div> <div class="devsite-nav-item-description"> Stay up to date with all things TensorFlow </div> </a> </li> <li class="devsite-nav-item"> <a href="https://discuss.tensorflow.org" track-type="nav" track-metadata-eventdetail="https://discuss.tensorflow.org" track-metadata-position="nav - community" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Forum </div> <div class="devsite-nav-item-description"> Discussion platform for the TensorFlow community </div> </a> </li> </ul> </div> </div> </div> </tab> <tab class="devsite-dropdown "> <a href="https://www.tensorflow.org/about" track-metadata-eventdetail="https://www.tensorflow.org/about" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - why tensorflow" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Why TensorFlow" track-name="why tensorflow" > Why TensorFlow </a> <a href="#" role="button" aria-haspopup="true" aria-expanded="false" aria-label="Dropdown menu for Why TensorFlow" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/about" track-metadata-position="nav - why tensorflow" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Why TensorFlow" track-name="why tensorflow" class="devsite-tabs-dropdown-toggle devsite-icon devsite-icon-arrow-drop-down"></a> <div class="devsite-tabs-dropdown" aria-label="submenu" hidden> <div class="devsite-tabs-dropdown-content"> <div class="devsite-tabs-dropdown-column "> <ul class="devsite-tabs-dropdown-section "> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/about" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/about" track-metadata-position="nav - why tensorflow" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> About </div> </a> </li> <li class="devsite-nav-item"> <a href="https://www.tensorflow.org/about/case-studies" track-type="nav" track-metadata-eventdetail="https://www.tensorflow.org/about/case-studies" track-metadata-position="nav - why tensorflow" track-metadata-module="tertiary nav" tooltip > <div class="devsite-nav-item-title"> Case studies </div> </a> </li> </ul> </div> </div> </div> </tab> </nav> </devsite-tabs> </div> <devsite-search enable-signin enable-search enable-suggestions enable-query-completion project-name="TFX" tenant-name="TensorFlow" > <form class="devsite-search-form" action="https://www.tensorflow.org/s/results" method="GET"> <div class="devsite-search-container"> <button type="button" search-open class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Open search"></button> <div class="devsite-searchbox"> <input aria-activedescendant="" aria-autocomplete="list" aria-label="Search" aria-expanded="false" aria-haspopup="listbox" autocomplete="off" class="devsite-search-field devsite-search-query" name="q" placeholder="Search" role="combobox" type="text" value="" > <div class="devsite-search-image material-icons" aria-hidden="true"> </div> <div class="devsite-search-shortcut-icon-container" aria-hidden="true"> <kbd class="devsite-search-shortcut-icon">/</kbd> </div> </div> </div> </form> <button type="button" search-close class="devsite-search-button devsite-header-icon-button button-flat material-icons" aria-label="Close search"></button> </devsite-search> </div> <devsite-language-selector> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" >English</a> </li> <li role="presentation"> <a role="menuitem" lang="es_419" >Español – América Latina</a> </li> <li role="presentation"> <a role="menuitem" lang="fr" >Français</a> </li> <li role="presentation"> <a role="menuitem" lang="id" >Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="it" >Italiano</a> </li> <li role="presentation"> <a role="menuitem" lang="pl" >Polski</a> </li> <li role="presentation"> <a role="menuitem" lang="pt_br" >Português – Brasil</a> </li> <li role="presentation"> <a role="menuitem" lang="vi" >Tiếng Việt</a> </li> <li role="presentation"> <a role="menuitem" lang="tr" >Türkçe</a> </li> <li role="presentation"> <a role="menuitem" lang="ru" >Русский</a> </li> <li role="presentation"> <a role="menuitem" lang="he" >עברית</a> </li> <li role="presentation"> <a role="menuitem" lang="ar" >العربيّة</a> </li> <li role="presentation"> <a role="menuitem" lang="fa" >فارسی</a> </li> <li role="presentation"> <a role="menuitem" lang="hi" >हिंदी</a> </li> <li role="presentation"> <a role="menuitem" lang="bn" >বাংলা</a> </li> <li role="presentation"> <a role="menuitem" lang="th" >ภาษาไทย</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_cn" >中文 – 简体</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" >日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" >한국어</a> </li> </ul> </devsite-language-selector> <a class="devsite-header-link devsite-top-button button gc-analytics-event" href="//github.com/tensorflow" data-category="Site-Wide Custom Events" data-label="Site header link" > GitHub </a> <devsite-user enable-profiles id="devsite-user"> <span class="button devsite-top-button" aria-hidden="true" visually-hidden>Sign in</span> </devsite-user> </div> </div> </div> <div class="devsite-collapsible-section "> <div class="devsite-header-background"> <div class="devsite-product-id-row" > <div class="devsite-product-description-row"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> <a href="https://www.tensorflow.org/tfx" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Lower Header" data-value="1" track-type="globalNav" track-name="breadcrumb" track-metadata-position="1" track-metadata-eventdetail="TFX" > For Production </a> </li> </ul> </div> </div> <div class="devsite-doc-set-nav-row"> <devsite-tabs class="lower-tabs"> <nav class="devsite-tabs-wrapper" aria-label="Lower tabs"> <tab > <a href="https://www.tensorflow.org/tfx" track-metadata-eventdetail="https://www.tensorflow.org/tfx" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - overview" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Overview" track-name="overview" > Overview </a> </tab> <tab class="devsite-active"> <a href="https://www.tensorflow.org/tfx/tutorials" track-metadata-eventdetail="https://www.tensorflow.org/tfx/tutorials" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - tutorials" track-metadata-module="primary nav" aria-label="Tutorials, selected" data-category="Site-Wide Custom Events" data-label="Tab: Tutorials" track-name="tutorials" > Tutorials </a> </tab> <tab > <a href="https://www.tensorflow.org/tfx/guide" track-metadata-eventdetail="https://www.tensorflow.org/tfx/guide" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - guide" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Guide" track-name="guide" > Guide </a> </tab> <tab > <a href="https://www.tensorflow.org/tfx/addons" track-metadata-eventdetail="https://www.tensorflow.org/tfx/addons" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - tfx-addons" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: TFX-Addons" track-name="tfx-addons" > TFX-Addons </a> </tab> <tab > <a href="https://www.tensorflow.org/tfx/api_overview" track-metadata-eventdetail="https://www.tensorflow.org/tfx/api_overview" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - api" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: API" track-name="api" > API </a> </tab> </nav> </devsite-tabs> </div> </div> </div> </div> </devsite-header> <devsite-book-nav scrollbars > <div class="devsite-book-nav-filter" > <span class="filter-list-icon material-icons" aria-hidden="true"></span> <input type="text" placeholder="Filter" aria-label="Type to filter" role="searchbox"> <span class="filter-clear-button hidden" data-title="Clear filter" aria-label="Clear filter" role="button" tabindex="0"></span> </div> <nav class="devsite-book-nav devsite-nav nocontent" aria-label="Side menu"> <div class="devsite-mobile-header"> <button type="button" id="devsite-close-nav" class="devsite-header-icon-button button-flat material-icons gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Close navigation" aria-label="Close navigation"> </button> <div class="devsite-product-name-wrapper"> <a href="/" class="devsite-site-logo-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Site logo" track-type="globalNav" track-name="tensorFlow" track-metadata-position="nav" track-metadata-eventDetail="nav"> <picture> <img src="https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/images/lockup.svg" class="devsite-site-logo" alt="TensorFlow"> </picture> </a> <span class="devsite-product-name"> <ul class="devsite-breadcrumb-list" > <li class="devsite-breadcrumb-item "> </li> </ul> </span> </div> </div> <div class="devsite-book-nav-wrapper"> <div class="devsite-mobile-nav-top"> <ul class="devsite-nav-list"> <li class="devsite-nav-item"> <a href="/install" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Install" track-name="install" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Install" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Install </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/learn" class="devsite-nav-title gc-analytics-event devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Learn" track-name="learn" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Learn" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Learn </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: Learn" track-name="learn" > <span class="devsite-nav-text" tooltip menu="Learn"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="Learn"> </span> </span> </li> </ul> <ul class="devsite-nav-responsive-tabs"> <li class="devsite-nav-item"> <a href="/tfx" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Overview" track-name="overview" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Overview" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Overview </span> </a> </li> <li class="devsite-nav-item"> <a href="/tfx/tutorials" class="devsite-nav-title gc-analytics-event devsite-nav-has-children devsite-nav-active" data-category="Site-Wide Custom Events" data-label="Tab: Tutorials" track-name="tutorials" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Tutorials" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip menu="_book"> Tutorials </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="_book"> </span> </a> </li> <li class="devsite-nav-item"> <a href="/tfx/guide" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Guide" track-name="guide" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Guide" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Guide </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/tfx/addons" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: TFX-Addons" track-name="tfx-addons" data-category="Site-Wide Custom Events" data-label="Responsive Tab: TFX-Addons" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TFX-Addons </span> </a> </li> <li class="devsite-nav-item"> <a href="/tfx/api_overview" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: API" track-name="api" data-category="Site-Wide Custom Events" data-label="Responsive Tab: API" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > API </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/api" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: API" track-name="api" data-category="Site-Wide Custom Events" data-label="Responsive Tab: API" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > API </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: API" track-name="api" > <span class="devsite-nav-text" tooltip menu="API"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="API"> </span> </span> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/resources/models-datasets" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Ecosystem" track-name="ecosystem" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Ecosystem" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Ecosystem </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: Ecosystem" track-name="ecosystem" > <span class="devsite-nav-text" tooltip menu="Ecosystem"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="Ecosystem"> </span> </span> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/community" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Community" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Community </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: Community" track-name="community" > <span class="devsite-nav-text" tooltip menu="Community"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="Community"> </span> </span> </li> </ul> </li> <li class="devsite-nav-item"> <a href="/about" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: Why TensorFlow" track-name="why tensorflow" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Why TensorFlow" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Why TensorFlow </span> </a> <ul class="devsite-nav-responsive-tabs devsite-nav-has-menu "> <li class="devsite-nav-item"> <span class="devsite-nav-title" tooltip data-category="Site-Wide Custom Events" data-label="Tab: Why TensorFlow" track-name="why tensorflow" > <span class="devsite-nav-text" tooltip menu="Why TensorFlow"> More </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="Why TensorFlow"> </span> </span> </li> </ul> </li> <li class="devsite-nav-item"> <a href="//github.com/tensorflow" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: GitHub" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > GitHub </span> </a> </li> </ul> </div> <div class="devsite-mobile-nav-bottom"> <ul class="devsite-nav-list" menu="_book"> <li class="devsite-nav-item"><a href="/tfx/tutorials" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials" ><span class="devsite-nav-text" tooltip>Get started with TFX</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>TFX: Getting started tutorials</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/penguin_simple" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/penguin_simple" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/penguin_simple" ><span class="devsite-nav-text" tooltip>1. Starter pipeline</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/penguin_tfdv" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/penguin_tfdv" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/penguin_tfdv" ><span class="devsite-nav-text" tooltip>2. Adding data validation</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/penguin_tft" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/penguin_tft" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/penguin_tft" ><span class="devsite-nav-text" tooltip>3. Adding feature engineering</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/penguin_tfma" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/penguin_tfma" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/penguin_tfma" ><span class="devsite-nav-text" tooltip>4. Adding model analysis</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>TFX: Interactive tutorials</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/components_keras" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/components_keras" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/components_keras" ><span class="devsite-nav-text" tooltip>Interactive tutorial (TF2 Keras)</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/components" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/components" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/components" ><span class="devsite-nav-text" tooltip>Interactive tutorial (Estimator)</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>TFX on Google Cloud</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/gcp/vertex_pipelines_simple" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/gcp/vertex_pipelines_simple" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/gcp/vertex_pipelines_simple" ><span class="devsite-nav-text" tooltip>Running on Vertex Pipelines</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/gcp/vertex_pipelines_bq" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/gcp/vertex_pipelines_bq" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/gcp/vertex_pipelines_bq" ><span class="devsite-nav-text" tooltip>Read data from BigQuery</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/gcp/vertex_pipelines_vertex_training" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/gcp/vertex_pipelines_vertex_training" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/gcp/vertex_pipelines_vertex_training" ><span class="devsite-nav-text" tooltip>Vertex AI Training and Serving</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/cloud-ai-platform-pipelines" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/cloud-ai-platform-pipelines" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/cloud-ai-platform-pipelines" ><span class="devsite-nav-text" tooltip>Cloud AI Platform Pipelines tutorial</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>TFX: Advanced tutorials</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/gpt2_finetuning_and_conversion" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/gpt2_finetuning_and_conversion" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/gpt2_finetuning_and_conversion" ><span class="devsite-nav-text" tooltip>LLM finetuning and conversion</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/python_function_component" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/python_function_component" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/python_function_component" ><span class="devsite-nav-text" tooltip>Custom component tutorial</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/recommenders" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/recommenders" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/recommenders" ><span class="devsite-nav-text" tooltip>Recommenders with TFX</span></a></li> <li class="devsite-nav-item"><a href="/recommenders/examples/ranking_tfx" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /recommenders/examples/ranking_tfx" track-type="bookNav" track-name="click" track-metadata-eventdetail="/recommenders/examples/ranking_tfx" ><span class="devsite-nav-text" tooltip>Ranking with TFX</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/airflow_workshop" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/airflow_workshop" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/airflow_workshop" ><span class="devsite-nav-text" tooltip>Airflow tutorial</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/neural_structured_learning" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/neural_structured_learning" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/neural_structured_learning" ><span class="devsite-nav-text" tooltip>Neural Structured Learning in TFX</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Data Validation</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/data_validation/tfdv_basic" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/data_validation/tfdv_basic" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/data_validation/tfdv_basic" ><span class="devsite-nav-text" tooltip>Get started with TFDV</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Transform</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/transform/simple" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/transform/simple" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/transform/simple" ><span class="devsite-nav-text" tooltip>Preprocess data (beginner)</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/transform/census" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/transform/census" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/transform/census" ><span class="devsite-nav-text" tooltip>Preprocess data (advanced)</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/transform/data_preprocessing_with_cloud" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/transform/data_preprocessing_with_cloud" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/transform/data_preprocessing_with_cloud" ><span class="devsite-nav-text" tooltip>Data preprocessing for ML with Google Cloud</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Model Analysis</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/model_analysis/tfma_basic" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/model_analysis/tfma_basic" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/model_analysis/tfma_basic" ><span class="devsite-nav-text" tooltip>Get started with TFMA</span></a></li> <li class="devsite-nav-item"><a href="/responsible_ai/fairness_indicators/tutorials/Fairness_Indicators_Example_Colab" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /responsible_ai/fairness_indicators/tutorials/Fairness_Indicators_Example_Colab" track-type="bookNav" track-name="click" track-metadata-eventdetail="/responsible_ai/fairness_indicators/tutorials/Fairness_Indicators_Example_Colab" ><span class="devsite-nav-text" tooltip>Fairness Indicators tutorial</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Deploy a trained model</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/serving/rest_simple" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/serving/rest_simple" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/serving/rest_simple" ><span class="devsite-nav-text" tooltip>Servers: TFX for TensorFlow Serving</span></a></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/tfx/tfx_for_mobile" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/tfx/tfx_for_mobile" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/tfx/tfx_for_mobile" ><span class="devsite-nav-text" tooltip>Mobile &amp; IoT: TFX for TensorFlow Lite</span></a></li> <li class="devsite-nav-item devsite-nav-heading"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>ML Metadata</span> </div></li> <li class="devsite-nav-item"><a href="/tfx/tutorials/mlmd/mlmd_tutorial" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfx/tutorials/mlmd/mlmd_tutorial" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfx/tutorials/mlmd/mlmd_tutorial" ><span class="devsite-nav-text" tooltip>Get started with MLMD</span></a></li> </ul> <ul class="devsite-nav-list" menu="Learn" aria-label="Side menu" hidden> <li class="devsite-nav-item"> <a href="/learn" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Introduction" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Introduction </span> </a> </li> <li class="devsite-nav-item"> <a href="/tutorials" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Tutorials" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Tutorials </span> </a> </li> <li class="devsite-nav-item"> <a href="/guide" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Guide" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Guide </span> </a> </li> <li class="devsite-nav-item"> <a href="/resources/learn-ml" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Learn ML" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Learn ML </span> </a> </li> </ul> <ul class="devsite-nav-list" menu="API" aria-label="Side menu" hidden> <li class="devsite-nav-item"> <a href="/api/stable" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TensorFlow (v2.16.1)" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TensorFlow (v2.16.1) </span> </a> </li> <li class="devsite-nav-item"> <a href="/versions" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Versions…" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Versions… </span> </a> </li> <li class="devsite-nav-item"> <a href="https://js.tensorflow.org/api/latest/" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TensorFlow.js" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TensorFlow.js </span> </a> </li> <li class="devsite-nav-item"> <a href="/lite/api_docs" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TensorFlow Lite" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TensorFlow Lite </span> </a> </li> <li class="devsite-nav-item"> <a href="/tfx/api_docs" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TFX" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TFX </span> </a> </li> </ul> <ul class="devsite-nav-list" menu="Ecosystem" aria-label="Side menu" hidden> <li class="devsite-nav-item devsite-nav-heading"> <span class="devsite-nav-title" tooltip > <span class="devsite-nav-text" tooltip > LIBRARIES </span> </span> </li> <li class="devsite-nav-item"> <a href="/js" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TensorFlow.js" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TensorFlow.js </span> </a> </li> <li class="devsite-nav-item"> <a href="/lite" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TensorFlow Lite" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TensorFlow Lite </span> </a> </li> <li class="devsite-nav-item"> <a href="/tfx" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: TFX" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TFX </span> </a> </li> <li class="devsite-nav-item"> <a href="/resources/libraries-extensions" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: All libraries" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > All libraries </span> </a> </li> <li class="devsite-nav-item devsite-nav-heading"> <span class="devsite-nav-title" tooltip > <span class="devsite-nav-text" tooltip > RESOURCES </span> </span> </li> <li class="devsite-nav-item"> <a href="/resources/models-datasets" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Models &amp; datasets" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Models &amp; datasets </span> </a> </li> <li class="devsite-nav-item"> <a href="/resources/tools" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Tools" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Tools </span> </a> </li> <li class="devsite-nav-item"> <a href="/responsible_ai" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Responsible AI" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Responsible AI </span> </a> </li> <li class="devsite-nav-item"> <a href="/resources/recommendation-systems" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Recommendation systems" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Recommendation systems </span> </a> </li> </ul> <ul class="devsite-nav-list" menu="Community" aria-label="Side menu" hidden> <li class="devsite-nav-item"> <a href="/community/groups" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Groups" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Groups </span> </a> </li> <li class="devsite-nav-item"> <a href="/community/contribute" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Contribute" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Contribute </span> </a> </li> <li class="devsite-nav-item"> <a href="https://blog.tensorflow.org/" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Blog" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Blog </span> </a> </li> <li class="devsite-nav-item"> <a href="https://discuss.tensorflow.org" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Forum" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Forum </span> </a> </li> </ul> <ul class="devsite-nav-list" menu="Why TensorFlow" aria-label="Side menu" hidden> <li class="devsite-nav-item"> <a href="/about" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: About" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > About </span> </a> </li> <li class="devsite-nav-item"> <a href="/about/case-studies" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Responsive Tab: Case studies" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Case studies </span> </a> </li> </ul> </div> </div> </nav> </devsite-book-nav> <section id="gc-wrapper"> <main role="main" class="devsite-main-content" has-book-nav has-sidebar > <div class="devsite-sidebar"> <div class="devsite-sidebar-content"> <devsite-toc class="devsite-nav" role="navigation" aria-label="On this page" depth="2" scrollbars ></devsite-toc> <devsite-recommendations-sidebar class="nocontent devsite-nav"> </devsite-recommendations-sidebar> </div> </div> <devsite-content> <article class="devsite-article"><style> /* Styles inlined from /site-assets/css/style.css */ /* override theme */ table img { max-width: 100%; } /* .devsite-terminal virtualenv prompt */ .tfo-terminal-venv::before { content: "(venv) $ " !important; } /* .devsite-terminal root prompt */ .tfo-terminal-root::before { content: "# " !important; } /* Used in links for type annotations in function/method signatures */ .tfo-signature-link a, .tfo-signature-link a:visited, .tfo-signature-link a:hover, .tfo-signature-link a:focus, .tfo-signature-link a:hover *, .tfo-signature-link a:focus * { text-decoration: none !important; } .tfo-signature-link a, .tfo-signature-link a:visited { border-bottom: 1px dotted #1a73e8; } .tfo-signature-link a:focus { border-bottom-style: solid; } /* .devsite-terminal Windows prompt */ .tfo-terminal-windows::before { content: "C:\\> " !important; } /* .devsite-terminal Windows prompt w/ virtualenv */ .tfo-terminal-windows-venv::before { content: "(venv) C:\\> " !important; } .tfo-diff-green-one-level + * { background: rgba(175, 245, 162, .6) !important; } .tfo-diff-green + * > * { background: rgba(175, 245, 162, .6) !important; } .tfo-diff-green-list + ul > li:first-of-type { background: rgba(175, 245, 162, .6) !important; } .tfo-diff-red-one-level + * { background: rgba(255, 230, 230, .6) !important; text-decoration: line-through !important; } .tfo-diff-red + * > * { background: rgba(255, 230, 230, .6) !important; text-decoration: line-through !important; } .tfo-diff-red-list + ul > li:first-of-type { background: rgba(255, 230, 230, .6) !important; text-decoration: line-through !important; } devsite-code .tfo-notebook-code-cell-output { max-height: 300px; overflow: auto; background: rgba(255, 247, 237, 1); /* orange bg to distinguish from input code cells */ } devsite-code .tfo-notebook-code-cell-output + .devsite-code-buttons-container button { background: rgba(255, 247, 237, .7); /* orange bg to distinguish from input code cells */ } devsite-code[dark-code] .tfo-notebook-code-cell-output { background: rgba(64, 78, 103, 1); /* medium slate */ } devsite-code[dark-code] .tfo-notebook-code-cell-output + .devsite-code-buttons-container button { background: rgba(64, 78, 103, .7); /* medium slate */ } /* override default table styles for notebook buttons */ .devsite-table-wrapper .tfo-notebook-buttons { display: inline-block; margin-left: 3px; width: auto; } .tfo-notebook-buttons td { padding-left: 0; padding-right: 20px; } .tfo-notebook-buttons a, .tfo-notebook-buttons :link, .tfo-notebook-buttons :visited { border-radius: 8px; box-shadow: 0 1px 2px 0 rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15); color: #202124; padding: 12px 17px; transition: box-shadow 0.2s; } .tfo-notebook-buttons a:hover, .tfo-notebook-buttons a:focus { box-shadow: 0 1px 2px 0 rgba(60, 64, 67, .3), 0 2px 6px 2px rgba(60, 64, 67, .15); } .tfo-notebook-buttons tr { background: 0; border: 0; } /* on rendered notebook page, remove link to webpage since we're already here */ .tfo-notebook-buttons:not(.tfo-api) td:first-child { display: none; } .tfo-notebook-buttons td > a { -webkit-box-align: center; -ms-flex-align: center; align-items: center; display: -webkit-box; display: -ms-flexbox; display: flex; } .tfo-notebook-buttons td > a > img { margin-right: 8px; } /* landing pages */ .tfo-landing-row-item-inset-white { background-color: #fff; padding: 32px; } .tfo-landing-row-item-inset-white ol, .tfo-landing-row-item-inset-white ul { padding-left: 20px; } /* colab callout button */ .colab-callout-row devsite-code { border-radius: 8px 8px 0 0; box-shadow: none; } .colab-callout-footer { background: #e3e4e7; border-radius: 0 0 8px 8px; color: #37474f; padding: 20px; } .colab-callout-row devsite-code[dark-code] + .colab-callout-footer { background: #3f4f66; } .colab-callout-footer > .button { margin-top: 4px; color: #ff5c00; } .colab-callout-footer > a > span { vertical-align: middle; color: #37474f; padding-left: 10px; font-size: 14px; } .colab-callout-row devsite-code[dark-code] + .colab-callout-footer > a > span { color: #fff; } a.colab-button { background: rgba(255, 255, 255, .75); border: solid 1px rgba(0, 0, 0, .08); border-bottom-color: rgba(0, 0, 0, .15); border-radius: 4px; color: #aaa; display: inline-block; font-size: 11px !important; font-weight: 300; line-height: 16px; padding: 4px 8px; text-decoration: none; text-transform: uppercase; } a.colab-button:hover { background: white; border-color: rgba(0, 0, 0, .2); color: #666; } a.colab-button span { background: url(/images/colab_logo_button.svg) no-repeat 1px 1px / 20px; border-radius: 4px; display: inline-block; padding-left: 24px; text-decoration: none; } @media screen and (max-width: 600px) { .tfo-notebook-buttons td { display: block; } } /* guide and tutorials landing page cards and sections */ .tfo-landing-page-card { padding: 16px; box-shadow: 0 0 36px rgba(0,0,0,0.1); border-radius: 10px; } /* Page section headings */ .tfo-landing-page-heading h2, h2.tfo-landing-page-heading { font-family: "Google Sans", sans-serif; color: #425066; font-size: 30px; font-weight: 700; line-height: 40px; } /* Item title headings */ .tfo-landing-page-heading h3, h3.tfo-landing-page-heading, .tfo-landing-page-card h3, h3.tfo-landing-page-card { font-family: "Google Sans", sans-serif; color: #425066; font-size: 20px; font-weight: 500; line-height: 26px; } /* List of tutorials notebooks for subsites */ .tfo-landing-page-resources-ul { padding-left: 15px } .tfo-landing-page-resources-ul > li { margin: 6px 0; } /* Temporary fix to hide product description in header on landing pages */ devsite-header .devsite-product-description { display: none; } </style> <div class="devsite-article-meta nocontent" role="navigation"> <ul class="devsite-breadcrumb-list" aria-label="Breadcrumb"> <li class="devsite-breadcrumb-item "> <a href="https://www.tensorflow.org/" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="1" track-type="globalNav" track-name="breadcrumb" track-metadata-position="1" track-metadata-eventdetail="TensorFlow" > TensorFlow </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://www.tensorflow.org/learn" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="2" track-type="globalNav" track-name="breadcrumb" track-metadata-position="2" track-metadata-eventdetail="" > Learn </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://www.tensorflow.org/tfx" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="3" track-type="globalNav" track-name="breadcrumb" track-metadata-position="3" track-metadata-eventdetail="TFX" > For Production </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://www.tensorflow.org/tfx/tutorials" class="devsite-breadcrumb-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Breadcrumbs" data-value="4" track-type="globalNav" track-name="breadcrumb" track-metadata-position="4" track-metadata-eventdetail="" > Tutorials </a> </li> </ul> <devsite-thumb-rating position="header"> </devsite-thumb-rating> </div> <h1 class="devsite-page-title" tabindex="-1"> Train and serve a TensorFlow model with TensorFlow Serving </h1> <devsite-feature-tooltip ack-key="AckCollectionsBookmarkTooltipDismiss" analytics-category="Site-Wide Custom Events" analytics-action-show="Callout Profile displayed" analytics-action-close="Callout Profile dismissed" analytics-label="Create Collection Callout" class="devsite-page-bookmark-tooltip nocontent" dismiss-button="true" id="devsite-collections-dropdown" dismiss-button-text="Dismiss" close-button-text="Got it"> <devsite-bookmark></devsite-bookmark> <span slot="popout-heading"> Stay organized with collections </span> <span slot="popout-contents"> Save and categorize content based on your preferences. </span> </devsite-feature-tooltip> <div class="devsite-page-title-meta"><devsite-view-release-notes></devsite-view-release-notes></div> <devsite-toc class="devsite-nav" depth="2" devsite-toc-embedded > </devsite-toc> <div class="devsite-article-body clearfix "> <p><devsite-mathjax config="TeX-AMS-MML_SVG"></devsite-mathjax> </p> <!-- DO NOT EDIT! Automatically generated file. --> <aside class="warning"><strong>Warning:</strong><span> This notebook is designed to be run in a Google Colab only**. It installs packages on the system and requires root access. If you want to run it in a local Jupyter notebook, please proceed with caution.</span></aside><aside class="note"><strong>Note:</strong><span> You can run this example right now in a Jupyter-style notebook, no setup required! Just click &quot;Run in Google Colab&quot;</span></aside> <div class="devsite-table-wrapper"><table class="tfo-notebook-buttons" align="left"> <tr><td><a target="_blank" href="https://www.tensorflow.org/tfx/tutorials/serving/rest_simple"> <img src="https://www.tensorflow.org/images/tf_logo_32px.png">View on TensorFlow.org</a></td> <td><a target="_blank" href="https://colab.research.google.com/github/tensorflow/tfx/blob/master/docs/tutorials/serving/rest_simple.ipynb"> <img src="https://www.tensorflow.org/images/colab_logo_32px.png">Run in Google Colab</a></td> <td><a target="_blank" href="https://github.com/tensorflow/tfx/blob/master/docs/tutorials/serving/rest_simple.ipynb"> <img width="32px" src="https://www.tensorflow.org/images/GitHub-Mark-32px.png">View source on GitHub</a></td> <td><a href="https://storage.googleapis.com/tensorflow_docs/tfx/docs/tutorials/serving/rest_simple.ipynb"><img src="https://www.tensorflow.org/images/download_logo_32px.png">Download notebook</a></td> </tr></table></div> <p>This guide trains a neural network model to classify <a href="https://github.com/zalandoresearch/fashion-mnist">images of clothing, like sneakers and shirts</a>, saves the trained model, and then serves it with <a href="https://www.tensorflow.org/tfx/guide/serving">TensorFlow Serving</a>. The focus is on TensorFlow Serving, rather than the modeling and training in TensorFlow, so for a complete example which focuses on the modeling and training see the <a href="https://github.com/tensorflow/docs/blob/master/site/en/r1/tutorials/keras/basic_classification.ipynb">Basic Classification example</a>.</p> <p>This guide uses <a href="https://github.com/tensorflow/docs/blob/master/site/en/r1/guide/keras.ipynb">tf.keras</a>, a high-level API to build and train models in TensorFlow.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">sys</span> <span class="devsite-syntax-c1"># Confirm that we're using Python 3</span> <span class="devsite-syntax-k">assert</span> <span class="devsite-syntax-n">sys</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">version_info</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">major</span> <span class="devsite-syntax-o">==</span> <span class="devsite-syntax-mi">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Oops, not running Python 3. Use Runtime &gt; Change runtime type'</span> </code></pre></devsite-code><div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-c1"># TensorFlow and tf.keras</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s2">"Installing dependencies for Colab environment"</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-err">!</span><span class="devsite-syntax-n">pip</span> <span class="devsite-syntax-n">install</span> <span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">Uq</span> <span class="devsite-syntax-n">grpcio</span><span class="devsite-syntax-o">==</span><span class="devsite-syntax-mf">1.26.0</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">tensorflow</span> <span class="devsite-syntax-k">as</span> <span class="devsite-syntax-nn">tf</span> <span class="devsite-syntax-kn">from</span> <span class="devsite-syntax-nn">tensorflow</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-n">keras</span> <span class="devsite-syntax-c1"># Helper libraries</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">numpy</span> <span class="devsite-syntax-k">as</span> <span class="devsite-syntax-nn">np</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">matplotlib.pyplot</span> <span class="devsite-syntax-k">as</span> <span class="devsite-syntax-nn">plt</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">os</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">subprocess</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'TensorFlow version: </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">tf</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">__version__</span><span class="devsite-syntax-p">))</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> 2024-04-30 10&colon;41&colon;08.716822&colon; E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc&colon;9261] Unable to register cuDNN factory&colon; Attempting to register factory for plugin cuDNN when one has already been registered 2024-04-30 10&colon;41&colon;08.716875&colon; E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc&colon;607] Unable to register cuFFT factory&colon; Attempting to register factory for plugin cuFFT when one has already been registered 2024-04-30 10&colon;41&colon;08.718684&colon; E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc&colon;1515] Unable to register cuBLAS factory&colon; Attempting to register factory for plugin cuBLAS when one has already been registered </pre></devsite-code> <h2 id="create_your_model" data-text="Create your model" tabindex="-1">Create your model</h2> <h3 id="import_the_fashion_mnist_dataset" data-text="Import the Fashion MNIST dataset" tabindex="-1">Import the Fashion MNIST dataset</h3> <p>This guide uses the <a href="https://github.com/zalandoresearch/fashion-mnist">Fashion MNIST</a> dataset which contains 70,000 grayscale images in 10 categories. The images show individual articles of clothing at low resolution (28 by 28 pixels), as seen here:</p> <table> <tr><td> <img src="https://tensorflow.org/images/fashion-mnist-sprite.png" alt="Fashion MNIST sprite" width="600"> </td></tr> <tr><td align="center"> <b>Figure 1.</b> <a href="https://github.com/zalandoresearch/fashion-mnist">Fashion-MNIST samples</a> (by Zalando, MIT License).<br/>&nbsp; </td></tr> </table> <p>Fashion MNIST is intended as a drop-in replacement for the classic <a href="http://yann.lecun.com/exdb/mnist/">MNIST</a> dataset—often used as the &quot;Hello, World&quot; of machine learning programs for computer vision. You can access the Fashion MNIST directly from TensorFlow, just import and load the data.</p> <aside class="note"><strong>Note:</strong><span> Although these are really images, they are loaded as NumPy arrays and not binary image objects.</span></aside><div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-n">fashion_mnist</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">datasets</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">fashion_mnist</span> <span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">train_images</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">train_labels</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">fashion_mnist</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">load_data</span><span class="devsite-syntax-p">()</span> <span class="devsite-syntax-c1"># scale the values to 0.0 to 1.0</span> <span class="devsite-syntax-n">train_images</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">train_images</span> <span class="devsite-syntax-o">/</span> <span class="devsite-syntax-mf">255.0</span> <span class="devsite-syntax-n">test_images</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">test_images</span> <span class="devsite-syntax-o">/</span> <span class="devsite-syntax-mf">255.0</span> <span class="devsite-syntax-c1"># reshape for feeding into the model</span> <span class="devsite-syntax-n">train_images</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">train_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">reshape</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">train_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">],</span> <span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">test_images</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">reshape</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">],</span> <span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">class_names</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-p">[</span><span class="devsite-syntax-s1">'T-shirt/top'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Trouser'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Pullover'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Dress'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Coat'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Sandal'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Shirt'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Sneaker'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Bag'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'Ankle boot'</span><span class="devsite-syntax-p">]</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-se">\n</span><span class="devsite-syntax-s1">train_images.shape: </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">, of </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">train_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">train_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">dtype</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'test_images.shape: </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">, of </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">dtype</span><span class="devsite-syntax-p">))</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Downloading data from https&colon;//storage.googleapis.com/tensorflow/tf-keras-datasets/train-labels-idx1-ubyte.gz 29515/29515 [==============================] - 0s 0us/step Downloading data from https&colon;//storage.googleapis.com/tensorflow/tf-keras-datasets/train-images-idx3-ubyte.gz 26421880/26421880 [==============================] - 0s 0us/step Downloading data from https&colon;//storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-labels-idx1-ubyte.gz 5148/5148 [==============================] - 0s 0us/step Downloading data from https&colon;//storage.googleapis.com/tensorflow/tf-keras-datasets/t10k-images-idx3-ubyte.gz 4422102/4422102 [==============================] - 0s 0us/step train_images.shape&colon; (60000, 28, 28, 1), of float64 test_images.shape&colon; (10000, 28, 28, 1), of float64 </pre></devsite-code> <h3 id="train_and_evaluate_your_model" data-text="Train and evaluate your model" tabindex="-1">Train and evaluate your model</h3> <p>Let&#39;s use the simplest possible CNN, since we&#39;re not focused on the modeling part.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-n">model</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Sequential</span><span class="devsite-syntax-p">([</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Conv2D</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">input_shape</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span><span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span><span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-n">filters</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-mi">8</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">kernel_size</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-mi">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">strides</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-mi">2</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s1">'relu'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s1">'Conv1'</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Flatten</span><span class="devsite-syntax-p">(),</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Dense</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">10</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s1">'Dense'</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-p">])</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">summary</span><span class="devsite-syntax-p">()</span> <span class="devsite-syntax-n">testing</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-kc">False</span> <span class="devsite-syntax-n">epochs</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-mi">5</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">compile</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">optimizer</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s1">'adam'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">loss</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">tf</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">losses</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">SparseCategoricalCrossentropy</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">from_logits</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">True</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-n">metrics</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">metrics</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">SparseCategoricalAccuracy</span><span class="devsite-syntax-p">()])</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">fit</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">train_images</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">train_labels</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">epochs</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">epochs</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">test_loss</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">test_acc</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">evaluate</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-se">\n</span><span class="devsite-syntax-s1">Test accuracy: </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_acc</span><span class="devsite-syntax-p">))</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Model&colon; &quot;sequential&quot; _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= Conv1 (Conv2D) (None, 13, 13, 8) 80 flatten (Flatten) (None, 1352) 0 Dense (Dense) (None, 10) 13530 ================================================================= Total params&colon; 13610 (53.16 KB) Trainable params&colon; 13610 (53.16 KB) Non-trainable params&colon; 0 (0.00 Byte) _________________________________________________________________ Epoch 1/5 WARNING&colon; All log messages before absl&colon;&colon;InitializeLog() is called are written to STDERR I0000 00&colon;00&colon;1714473676.987867 178558 device_compiler.h&colon;186] Compiled cluster using XLA! This line is logged at most once for the lifetime of the process. 1875/1875 [==============================] - 6s 2ms/step - loss&colon; 0.5614 - sparse_categorical_accuracy&colon; 0.8059 Epoch 2/5 1875/1875 [==============================] - 4s 2ms/step - loss&colon; 0.4274 - sparse_categorical_accuracy&colon; 0.8499 Epoch 3/5 1875/1875 [==============================] - 4s 2ms/step - loss&colon; 0.3859 - sparse_categorical_accuracy&colon; 0.8654 Epoch 4/5 1875/1875 [==============================] - 4s 2ms/step - loss&colon; 0.3561 - sparse_categorical_accuracy&colon; 0.8740 Epoch 5/5 1875/1875 [==============================] - 4s 2ms/step - loss&colon; 0.3328 - sparse_categorical_accuracy&colon; 0.8818 313/313 [==============================] - 1s 2ms/step - loss&colon; 0.3635 - sparse_categorical_accuracy&colon; 0.8706 Test accuracy&colon; 0.8705999851226807 </pre></devsite-code> <h2 id="save_your_model" data-text="Save your model" tabindex="-1">Save your model</h2> <p>To load our trained model into TensorFlow Serving we first need to save it in <a href="https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/saved_model">SavedModel</a> format. This will create a protobuf file in a well-defined directory hierarchy, and will include a version number. <a href="https://www.tensorflow.org/tfx/guide/serving">TensorFlow Serving</a> allows us to select which version of a model, or &quot;servable&quot; we want to use when we make inference requests. Each version will be exported to a different sub-directory under the given path.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-c1"># Fetch the Keras session and save the model</span> <span class="devsite-syntax-c1"># The signature definition is defined by the input and output tensors,</span> <span class="devsite-syntax-c1"># and stored with the default serving key</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">tempfile</span> <span class="devsite-syntax-n">MODEL_DIR</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">tempfile</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">gettempdir</span><span class="devsite-syntax-p">()</span> <span class="devsite-syntax-n">version</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-mi">1</span> <span class="devsite-syntax-n">export_path</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">os</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">path</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">join</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">MODEL_DIR</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-nb">str</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">version</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'export_path = </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-se">\n</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">export_path</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-n">tf</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">models</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">save_model</span><span class="devsite-syntax-p">(</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">export_path</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">overwrite</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">True</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">include_optimizer</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">True</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">save_format</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">None</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">signatures</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">None</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">options</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">None</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-se">\n</span><span class="devsite-syntax-s1">Saved model:'</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-err">!</span><span class="devsite-syntax-n">ls</span> <span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">l</span> <span class="devsite-syntax-p">{</span><span class="devsite-syntax-n">export_path</span><span class="devsite-syntax-p">}</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> export_path = /tmpfs/tmp/1 INFO&colon;tensorflow&colon;Assets written to&colon; /tmpfs/tmp/1/assets INFO&colon;tensorflow&colon;Assets written to&colon; /tmpfs/tmp/1/assets Saved model&colon; total 104 drwxr-xr-x 2 kbuilder kbuilder 4096 Apr 30 10&colon;41 assets -rw-rw-r-- 1 kbuilder kbuilder 54 Apr 30 10&colon;41 fingerprint.pb -rw-rw-r-- 1 kbuilder kbuilder 8798 Apr 30 10&colon;41 keras_metadata.pb -rw-rw-r-- 1 kbuilder kbuilder 78816 Apr 30 10&colon;41 saved_model.pb drwxr-xr-x 2 kbuilder kbuilder 4096 Apr 30 10&colon;41 variables </pre></devsite-code> <h2 id="examine_your_saved_model" data-text="Examine your saved model" tabindex="-1">Examine your saved model</h2> <p>We&#39;ll use the command line utility <code translate="no" dir="ltr">saved_model_cli</code> to look at the <a href="https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/MetaGraphDef">MetaGraphDefs</a> (the models) and <a href="https://www.tensorflow.org/tfx/serving/signature_defs">SignatureDefs</a> (the methods you can call) in our SavedModel. See <a href="https://github.com/tensorflow/docs/blob/master/site/en/r1/guide/saved_model.md#cli-to-inspect-and-execute-savedmodel">this discussion of the SavedModel CLI</a> in the TensorFlow Guide.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Bash"><code class='devsite-terminal' translate="no" dir="ltr">saved_model_cli<span class="devsite-syntax-w"> </span>show<span class="devsite-syntax-w"> </span>--dir<span class="devsite-syntax-w"> </span><span class="devsite-syntax-o">{</span>export_path<span class="devsite-syntax-o">}</span><span class="devsite-syntax-w"> </span>--all</code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> 2024-04-30 10&colon;41&colon;41.354485&colon; E external/local_xla/xla/stream_executor/cuda/cuda_dnn.cc&colon;9261] Unable to register cuDNN factory&colon; Attempting to register factory for plugin cuDNN when one has already been registered 2024-04-30 10&colon;41&colon;41.354542&colon; E external/local_xla/xla/stream_executor/cuda/cuda_fft.cc&colon;607] Unable to register cuFFT factory&colon; Attempting to register factory for plugin cuFFT when one has already been registered 2024-04-30 10&colon;41&colon;41.355947&colon; E external/local_xla/xla/stream_executor/cuda/cuda_blas.cc&colon;1515] Unable to register cuBLAS factory&colon; Attempting to register factory for plugin cuBLAS when one has already been registered MetaGraphDef with tag-set&colon; &#x27;serve&#x27; contains the following SignatureDefs&colon; signature_def[&#x27;__saved_model_init_op&#x27;]&colon; The given SavedModel SignatureDef contains the following input(s)&colon; The given SavedModel SignatureDef contains the following output(s)&colon; outputs[&#x27;__saved_model_init_op&#x27;] tensor_info&colon; dtype&colon; DT_INVALID shape&colon; unknown_rank name&colon; NoOp Method name is&colon; signature_def[&#x27;serving_default&#x27;]&colon; The given SavedModel SignatureDef contains the following input(s)&colon; inputs[&#x27;Conv1_input&#x27;] tensor_info&colon; dtype&colon; DT_FLOAT shape&colon; (-1, 28, 28, 1) name&colon; serving_default_Conv1_input&colon;0 The given SavedModel SignatureDef contains the following output(s)&colon; outputs[&#x27;Dense&#x27;] tensor_info&colon; dtype&colon; DT_FLOAT shape&colon; (-1, 10) name&colon; StatefulPartitionedCall&colon;0 Method name is&colon; tensorflow/serving/predict The MetaGraph with tag set [&#x27;serve&#x27;] contains the following ops&colon; {&#x27;SaveV2&#x27;, &#x27;Pack&#x27;, &#x27;ShardedFilename&#x27;, &#x27;NoOp&#x27;, &#x27;ReadVariableOp&#x27;, &#x27;Placeholder&#x27;, &#x27;Reshape&#x27;, &#x27;RestoreV2&#x27;, &#x27;StaticRegexFullMatch&#x27;, &#x27;Const&#x27;, &#x27;Identity&#x27;, &#x27;Select&#x27;, &#x27;Conv2D&#x27;, &#x27;AssignVariableOp&#x27;, &#x27;Relu&#x27;, &#x27;BiasAdd&#x27;, &#x27;MergeV2Checkpoints&#x27;, &#x27;DisableCopyOnRead&#x27;, &#x27;StringJoin&#x27;, &#x27;StatefulPartitionedCall&#x27;, &#x27;VarHandleOp&#x27;, &#x27;MatMul&#x27;} Concrete Functions&colon; Function Name&colon; &#x27;__call__&#x27; Option #1 Callable with&colon; Argument #1 Conv1_input&colon; TensorSpec(shape=(None, 28, 28, 1), dtype=tf.float32, name=&#x27;Conv1_input&#x27;) Argument #2 DType&colon; bool Value&colon; False Argument #3 DType&colon; NoneType Value&colon; None Option #2 Callable with&colon; Argument #1 Conv1_input&colon; TensorSpec(shape=(None, 28, 28, 1), dtype=tf.float32, name=&#x27;Conv1_input&#x27;) Argument #2 DType&colon; bool Value&colon; True Argument #3 DType&colon; NoneType Value&colon; None Function Name&colon; &#x27;_default_save_signature&#x27; Option #1 Callable with&colon; Argument #1 Conv1_input&colon; TensorSpec(shape=(None, 28, 28, 1), dtype=tf.float32, name=&#x27;Conv1_input&#x27;) Function Name&colon; &#x27;call_and_return_all_conditional_losses&#x27; Option #1 Callable with&colon; Argument #1 Conv1_input&colon; TensorSpec(shape=(None, 28, 28, 1), dtype=tf.float32, name=&#x27;Conv1_input&#x27;) Argument #2 DType&colon; bool Value&colon; False Argument #3 DType&colon; NoneType Value&colon; None Option #2 Callable with&colon; Argument #1 Conv1_input&colon; TensorSpec(shape=(None, 28, 28, 1), dtype=tf.float32, name=&#x27;Conv1_input&#x27;) Argument #2 DType&colon; bool Value&colon; True Argument #3 DType&colon; NoneType Value&colon; None </pre></devsite-code> <p>That tells us a lot about our model! In this case we just trained our model, so we already know the inputs and outputs, but if we didn&#39;t this would be important information. It doesn&#39;t tell us everything, like the fact that this is grayscale image data for example, but it&#39;s a great start.</p> <h2 id="serve_your_model_with_tensorflow_serving" data-text="Serve your model with TensorFlow Serving" tabindex="-1">Serve your model with TensorFlow Serving</h2> <aside class="warning"><strong>Warning:</strong><span> If you are running this NOT on a Google Colab,** following cells will install packages on the system with root access. If you want to run it in a local Jupyter notebook, please proceed with caution.</span></aside> <h3 id="add_tensorflow_serving_distribution_uri_as_a_package_source" data-text="Add TensorFlow Serving distribution URI as a package source:" tabindex="-1">Add TensorFlow Serving distribution URI as a package source:</h3> <p>We&#39;re preparing to install TensorFlow Serving using <a href="https://wiki.debian.org/Aptitude">Aptitude</a> since this Colab runs in a Debian environment. We&#39;ll add the <code translate="no" dir="ltr">tensorflow-model-server</code> package to the list of packages that Aptitude knows about. Note that we&#39;re running as root.</p> <aside class="note"><strong>Note:</strong><span> This example is running TensorFlow Serving natively, but <a href="https://www.tensorflow.org/tfx/serving/docker">you can also run it in a Docker container</a>, which is one of the easiest ways to get started using TensorFlow Serving.</span></aside><div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">sys</span> <span class="devsite-syntax-c1"># We need sudo prefix if not on a Google Colab.</span> <span class="devsite-syntax-k">if</span> <span class="devsite-syntax-s1">'google.colab'</span> <span class="devsite-syntax-ow">not</span> <span class="devsite-syntax-ow">in</span> <span class="devsite-syntax-n">sys</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">modules</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-n">SUDO_IF_NEEDED</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-s1">'sudo'</span> <span class="devsite-syntax-k">else</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-n">SUDO_IF_NEEDED</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-s1">''</span> </code></pre></devsite-code><div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-c1"># This is the same as you would do from your command line, but without the [arch=amd64], and no sudo</span> <span class="devsite-syntax-c1"># You would instead do:</span> <span class="devsite-syntax-c1"># echo "deb [arch=amd64] http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal" | sudo tee /etc/apt/sources.list.d/tensorflow-serving.list &amp;&amp; \</span> <span class="devsite-syntax-c1"># curl https://storage.googleapis.com/tensorflow-serving-apt/tensorflow-serving.release.pub.gpg | sudo apt-key add -</span> <span class="devsite-syntax-err">!</span><span class="devsite-syntax-n">echo</span> <span class="devsite-syntax-s2">"deb http://storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal"</span> <span class="devsite-syntax-o">|</span> <span class="devsite-syntax-p">{</span><span class="devsite-syntax-n">SUDO_IF_NEEDED</span><span class="devsite-syntax-p">}</span> <span class="devsite-syntax-n">tee</span> <span class="devsite-syntax-o">/</span><span class="devsite-syntax-n">etc</span><span class="devsite-syntax-o">/</span><span class="devsite-syntax-n">apt</span><span class="devsite-syntax-o">/</span><span class="devsite-syntax-n">sources</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">list</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">d</span><span class="devsite-syntax-o">/</span><span class="devsite-syntax-n">tensorflow</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">serving</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">list</span> &amp;&amp; \ <span class="devsite-syntax-n">curl</span> <span class="devsite-syntax-n">https</span><span class="devsite-syntax-p">:</span><span class="devsite-syntax-o">//</span><span class="devsite-syntax-n">storage</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">googleapis</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">com</span><span class="devsite-syntax-o">/</span><span class="devsite-syntax-n">tensorflow</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">serving</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">apt</span><span class="devsite-syntax-o">/</span><span class="devsite-syntax-n">tensorflow</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">serving</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">release</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">pub</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">gpg</span> <span class="devsite-syntax-o">|</span> <span class="devsite-syntax-p">{</span><span class="devsite-syntax-n">SUDO_IF_NEEDED</span><span class="devsite-syntax-p">}</span> <span class="devsite-syntax-n">apt</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">key</span> <span class="devsite-syntax-n">add</span> <span class="devsite-syntax-o">-</span> <span class="devsite-syntax-err">!</span><span class="devsite-syntax-p">{</span><span class="devsite-syntax-n">SUDO_IF_NEEDED</span><span class="devsite-syntax-p">}</span> <span class="devsite-syntax-n">apt</span> <span class="devsite-syntax-n">update</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> deb http&colon;//storage.googleapis.com/tensorflow-serving-apt stable tensorflow-model-server tensorflow-model-server-universal % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 2943 100 2943 0 0 52553 0 --&colon;--&colon;-- --&colon;--&colon;-- --&colon;--&colon;-- 53509 OK Hit&colon;1 http&colon;//us-central1.gce.archive.ubuntu.com/ubuntu focal InRelease Hit&colon;2 http&colon;//us-central1.gce.archive.ubuntu.com/ubuntu focal-updates InRelease Hit&colon;3 http&colon;//us-central1.gce.archive.ubuntu.com/ubuntu focal-backports InRelease Hit&colon;4 https&colon;//download.docker.com/linux/ubuntu focal InRelease Get&colon;5 https&colon;//nvidia.github.io/libnvidia-container/stable/ubuntu18.04/amd64 InRelease [1484 B] Hit&colon;6 https&colon;//nvidia.github.io/nvidia-container-runtime/stable/ubuntu18.04/amd64 InRelease Hit&colon;7 https&colon;//nvidia.github.io/nvidia-docker/ubuntu18.04/amd64 InRelease Hit&colon;8 http&colon;//security.ubuntu.com/ubuntu focal-security InRelease Get&colon;9 http&colon;//storage.googleapis.com/tensorflow-serving-apt stable InRelease [3026 B] Hit&colon;10 https&colon;//developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 InRelease Hit&colon;11 http&colon;//ppa.launchpad.net/deadsnakes/ppa/ubuntu focal InRelease Hit&colon;13 http&colon;//ppa.launchpad.net/longsleep/golang-backports/ubuntu focal InRelease Hit&colon;14 http&colon;//ppa.launchpad.net/openjdk-r/ppa/ubuntu focal InRelease Hit&colon;12 https&colon;//apt.llvm.org/focal llvm-toolchain-focal-17 InRelease Get&colon;15 http&colon;//storage.googleapis.com/tensorflow-serving-apt stable/tensorflow-model-server amd64 Packages [341 B] Get&colon;16 http&colon;//storage.googleapis.com/tensorflow-serving-apt stable/tensorflow-model-server-universal amd64 Packages [349 B] Fetched 5200 B in 2s (3446 B/s) 235 packages can be upgraded. Run &#x27;apt list --upgradable&#x27; to see them. </pre></devsite-code> <h3 id="install_tensorflow_serving" data-text="Install TensorFlow Serving" tabindex="-1">Install TensorFlow Serving</h3> <p>This is all you need - one command line!</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Bash"><code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-c1"># TODO: Use the latest model server version when colab supports it.</span></code> <code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-c1">#!{SUDO_IF_NEEDED} apt-get install tensorflow-model-server</span></code> <code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-c1"># We need to install Tensorflow Model server 2.8 instead of latest version</span></code> <code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-c1"># Tensorflow Serving >2.9.0 required `GLIBC_2.29` and `GLIBCXX_3.4.26`. Currently colab environment doesn't support latest version of`GLIBC`,so workaround is to use specific version of Tensorflow Serving `2.8.0` to mitigate issue.</span></code> <code class='devsite-terminal' translate="no" dir="ltr">wget<span class="devsite-syntax-w"> </span><span class="devsite-syntax-s1">'http://storage.googleapis.com/tensorflow-serving-apt/pool/tensorflow-model-server-2.8.0/t/tensorflow-model-server/tensorflow-model-server_2.8.0_all.deb'</span></code> <code class='devsite-terminal' translate="no" dir="ltr">dpkg<span class="devsite-syntax-w"> </span>-i<span class="devsite-syntax-w"> </span>tensorflow-model-server_2.8.0_all.deb</code> <code class='devsite-terminal' translate="no" dir="ltr">pip3<span class="devsite-syntax-w"> </span>install<span class="devsite-syntax-w"> </span>tensorflow-serving-api<span class="devsite-syntax-o">==</span><span class="devsite-syntax-m">2</span>.8.0</code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> --2024-04-30 10&colon;41&colon;50-- http&colon;//storage.googleapis.com/tensorflow-serving-apt/pool/tensorflow-model-server-2.8.0/t/tensorflow-model-server/tensorflow-model-server_2.8.0_all.deb Resolving storage.googleapis.com (storage.googleapis.com)... 142.251.172.207, 142.251.180.207, 142.251.183.207, ... Connecting to storage.googleapis.com (storage.googleapis.com)|142.251.172.207|&colon;80... connected. HTTP request sent, awaiting response... 200 OK Length&colon; 340152790 (324M) [application/x-debian-package] Saving to&colon; ‘tensorflow-model-server_2.8.0_all.deb’ tensorflow-model-se 100%[===================&gt;] 324.39M 223MB/s in 1.5s 2024-04-30 10&colon;41&colon;51 (223 MB/s) - ‘tensorflow-model-server_2.8.0_all.deb’ saved [340152790/340152790] dpkg&colon; error&colon; requested operation requires superuser privilege Collecting tensorflow-serving-api==2.8.0 Downloading tensorflow_serving_api-2.8.0-py2.py3-none-any.whl.metadata (1.8 kB) Requirement already satisfied&colon; grpcio&lt;2,&gt;=1.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow-serving-api==2.8.0) (1.26.0) Requirement already satisfied&colon; protobuf&gt;=3.6.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow-serving-api==2.8.0) (3.20.3) Requirement already satisfied&colon; tensorflow&lt;3,&gt;=2.8.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow-serving-api==2.8.0) (2.15.1) Requirement already satisfied&colon; six&gt;=1.5.2 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from grpcio&lt;2,&gt;=1.0-&gt;tensorflow-serving-api==2.8.0) (1.16.0) Requirement already satisfied&colon; absl-py&gt;=1.0.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (1.4.0) Requirement already satisfied&colon; astunparse&gt;=1.6.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (1.6.3) Requirement already satisfied&colon; flatbuffers&gt;=23.5.26 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (24.3.25) Requirement already satisfied&colon; gast!=0.5.0,!=0.5.1,!=0.5.2,&gt;=0.2.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.5.4) Requirement already satisfied&colon; google-pasta&gt;=0.1.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.2.0) Requirement already satisfied&colon; h5py&gt;=2.9.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.11.0) Requirement already satisfied&colon; libclang&gt;=13.0.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (18.1.1) Requirement already satisfied&colon; ml-dtypes~=0.3.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.3.2) Requirement already satisfied&colon; numpy&lt;2.0.0,&gt;=1.23.5 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (1.26.4) Requirement already satisfied&colon; opt-einsum&gt;=2.3.2 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.3.0) Requirement already satisfied&colon; packaging in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (24.0) Requirement already satisfied&colon; setuptools in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (69.5.1) Requirement already satisfied&colon; termcolor&gt;=1.1.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.4.0) Requirement already satisfied&colon; typing-extensions&gt;=3.6.6 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (4.11.0) Requirement already satisfied&colon; wrapt&lt;1.15,&gt;=1.11.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (1.14.1) Requirement already satisfied&colon; tensorflow-io-gcs-filesystem&gt;=0.23.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.36.0) Requirement already satisfied&colon; tensorboard&lt;2.16,&gt;=2.15 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.15.2) Requirement already satisfied&colon; tensorflow-estimator&lt;2.16,&gt;=2.15.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.15.0) Requirement already satisfied&colon; keras&lt;2.16,&gt;=2.15.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.15.0) Requirement already satisfied&colon; wheel&lt;1.0,&gt;=0.23.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from astunparse&gt;=1.6.0-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.43.0) Collecting grpcio&lt;2,&gt;=1.0 (from tensorflow-serving-api==2.8.0) Downloading grpcio-1.62.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (4.0 kB) Requirement already satisfied&colon; google-auth&lt;3,&gt;=1.6.3 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.29.0) Requirement already satisfied&colon; google-auth-oauthlib&lt;2,&gt;=0.5 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (1.2.0) Requirement already satisfied&colon; markdown&gt;=2.6.8 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.6) Requirement already satisfied&colon; requests&lt;3,&gt;=2.21.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.31.0) Requirement already satisfied&colon; tensorboard-data-server&lt;0.8.0,&gt;=0.7.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.7.2) Requirement already satisfied&colon; werkzeug&gt;=1.0.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.0.2) Requirement already satisfied&colon; cachetools&lt;6.0,&gt;=2.0.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from google-auth&lt;3,&gt;=1.6.3-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (5.3.3) Requirement already satisfied&colon; pyasn1-modules&gt;=0.2.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from google-auth&lt;3,&gt;=1.6.3-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.4.0) Requirement already satisfied&colon; rsa&lt;5,&gt;=3.1.4 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from google-auth&lt;3,&gt;=1.6.3-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (4.9) Requirement already satisfied&colon; requests-oauthlib&gt;=0.7.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from google-auth-oauthlib&lt;2,&gt;=0.5-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.0.0) Requirement already satisfied&colon; importlib-metadata&gt;=4.4 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from markdown&gt;=2.6.8-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (7.1.0) Requirement already satisfied&colon; charset-normalizer&lt;4,&gt;=2 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from requests&lt;3,&gt;=2.21.0-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.3.2) Requirement already satisfied&colon; idna&lt;4,&gt;=2.5 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from requests&lt;3,&gt;=2.21.0-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.7) Requirement already satisfied&colon; urllib3&lt;3,&gt;=1.21.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from requests&lt;3,&gt;=2.21.0-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (1.26.18) Requirement already satisfied&colon; certifi&gt;=2017.4.17 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from requests&lt;3,&gt;=2.21.0-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2024.2.2) Requirement already satisfied&colon; MarkupSafe&gt;=2.1.1 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from werkzeug&gt;=1.0.1-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (2.1.5) Requirement already satisfied&colon; zipp&gt;=0.5 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from importlib-metadata&gt;=4.4-&gt;markdown&gt;=2.6.8-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.18.1) Requirement already satisfied&colon; pyasn1&lt;0.7.0,&gt;=0.4.6 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from pyasn1-modules&gt;=0.2.1-&gt;google-auth&lt;3,&gt;=1.6.3-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (0.6.0) Requirement already satisfied&colon; oauthlib&gt;=3.0.0 in /tmpfs/src/tf_docs_env/lib/python3.9/site-packages (from requests-oauthlib&gt;=0.7.0-&gt;google-auth-oauthlib&lt;2,&gt;=0.5-&gt;tensorboard&lt;2.16,&gt;=2.15-&gt;tensorflow&lt;3,&gt;=2.8.0-&gt;tensorflow-serving-api==2.8.0) (3.2.2) Downloading tensorflow_serving_api-2.8.0-py2.py3-none-any.whl (37 kB) Downloading grpcio-1.62.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.6 MB) Installing collected packages&colon; grpcio, tensorflow-serving-api Attempting uninstall&colon; grpcio Found existing installation&colon; grpcio 1.26.0 Uninstalling grpcio-1.26.0&colon; Successfully uninstalled grpcio-1.26.0 Attempting uninstall&colon; tensorflow-serving-api Found existing installation&colon; tensorflow-serving-api 2.15.1 Uninstalling tensorflow-serving-api-2.15.1&colon; Successfully uninstalled tensorflow-serving-api-2.15.1 ERROR&colon; pip&#x27;s dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. tf-keras 2.16.0 requires tensorflow&lt;2.17,&gt;=2.16, but you have tensorflow 2.15.1 which is incompatible. tfx 1.15.0 requires tensorflow-serving-api&lt;2.16,&gt;=2.15, but you have tensorflow-serving-api 2.8.0 which is incompatible. tfx-bsl 1.15.1 requires tensorflow-serving-api&lt;3,&gt;=2.13.0, but you have tensorflow-serving-api 2.8.0 which is incompatible. Successfully installed grpcio-1.62.2 tensorflow-serving-api-2.8.0 </pre></devsite-code> <h3 id="start_running_tensorflow_serving" data-text="Start running TensorFlow Serving" tabindex="-1">Start running TensorFlow Serving</h3> <p>This is where we start running TensorFlow Serving and load our model. After it loads we can start making inference requests using REST. There are some important parameters:</p> <ul> <li><code translate="no" dir="ltr">rest_api_port</code>: The port that you&#39;ll use for REST requests.</li> <li><code translate="no" dir="ltr">model_name</code>: You&#39;ll use this in the URL of REST requests. It can be anything.</li> <li><code translate="no" dir="ltr">model_base_path</code>: This is the path to the directory where you&#39;ve saved your model.</li> </ul> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-n">os</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">environ</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-s2">"MODEL_DIR"</span><span class="devsite-syntax-p">]</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">MODEL_DIR</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Bash"><code class='devsite-terminal' translate="no" dir="ltr">nohup<span class="devsite-syntax-w"> </span>tensorflow_model_server<span class="devsite-syntax-w"> </span><span class="devsite-syntax-se">\</span></code> <code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-w"> </span>--rest_api_port<span class="devsite-syntax-o">=</span><span class="devsite-syntax-m">8501</span><span class="devsite-syntax-w"> </span><span class="devsite-syntax-se">\</span></code> <code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-w"> </span>--model_name<span class="devsite-syntax-o">=</span>fashion_model<span class="devsite-syntax-w"> </span><span class="devsite-syntax-se">\</span></code> <code class='devsite-terminal' translate="no" dir="ltr"><span class="devsite-syntax-w"> </span>--model_base_path<span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"</span><span class="devsite-syntax-si">${</span><span class="devsite-syntax-nv">MODEL_DIR</span><span class="devsite-syntax-si">}</span><span class="devsite-syntax-s2">"</span><span class="devsite-syntax-w"> </span>>server.log<span class="devsite-syntax-w"> </span><span class="devsite-syntax-m">2</span>><span class="devsite-syntax-p">&</span><span class="devsite-syntax-m">1</span></code></pre></devsite-code> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Bash"><code class='devsite-terminal' translate="no" dir="ltr">tail<span class="devsite-syntax-w"> </span>server.log</code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> nohup&colon; failed to run command &#x27;tensorflow_model_server&#x27;&colon; No such file or directory </pre></devsite-code> <h2 id="make_a_request_to_your_model_in_tensorflow_serving" data-text="Make a request to your model in TensorFlow Serving" tabindex="-1">Make a request to your model in TensorFlow Serving</h2> <p>First, let&#39;s take a look at a random example from our test data.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-k">def</span> <span class="devsite-syntax-nf">show</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">idx</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">title</span><span class="devsite-syntax-p">):</span> <span class="devsite-syntax-n">plt</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">figure</span><span class="devsite-syntax-p">()</span> <span class="devsite-syntax-n">plt</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">imshow</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">idx</span><span class="devsite-syntax-p">]</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">reshape</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">,</span><span class="devsite-syntax-mi">28</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-n">plt</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">axis</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'off'</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">plt</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">title</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-se">\n\n</span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">title</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-n">fontdict</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">{</span><span class="devsite-syntax-s1">'size'</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-mi">16</span><span class="devsite-syntax-p">})</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">random</span> <span class="devsite-syntax-n">rando</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">random</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">randint</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">,</span><span class="devsite-syntax-nb">len</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-p">)</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">show</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">rando</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'An Example Image: </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">class_names</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">rando</span><span class="devsite-syntax-p">]]))</span> </code></pre></devsite-code> <p><img src="/static/tfx/tutorials/serving/rest_simple_files/output_Luqm_Jyff9iR_0.png" alt="png"></p> <p>Ok, that looks interesting. How hard is that for you to recognize? Now let&#39;s create the JSON object for a batch of three inference requests, and see how well our model recognizes things:</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">json</span> <span class="devsite-syntax-n">data</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">json</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">dumps</span><span class="devsite-syntax-p">({</span><span class="devsite-syntax-s2">"signature_name"</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-s2">"serving_default"</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s2">"instances"</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-n">test_images</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">:</span><span class="devsite-syntax-mi">3</span><span class="devsite-syntax-p">]</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">tolist</span><span class="devsite-syntax-p">()})</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'Data: </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1"> ... </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">data</span><span class="devsite-syntax-p">[:</span><span class="devsite-syntax-mi">50</span><span class="devsite-syntax-p">],</span> <span class="devsite-syntax-n">data</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-nb">len</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">data</span><span class="devsite-syntax-p">)</span><span class="devsite-syntax-o">-</span><span class="devsite-syntax-mi">52</span><span class="devsite-syntax-p">:]))</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Data&colon; {&quot;signature_name&quot;&colon; &quot;serving_default&quot;, &quot;instances&quot;&colon; ... [0.0], [0.0], [0.0], [0.0], [0.0], [0.0], [0.0]]]]} </pre></devsite-code> <h3 id="make_rest_requests" data-text="Make REST requests" tabindex="-1">Make REST requests</h3> <h4 id="newest_version_of_the_servable" data-text="Newest version of the servable" tabindex="-1">Newest version of the servable</h4> <p>We&#39;ll send a predict request as a POST to our server&#39;s REST endpoint, and pass it three examples. We&#39;ll ask our server to give us the latest version of our servable by not specifying a particular version.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-c1"># docs_infra: no_execute</span> <span class="devsite-syntax-err">!</span><span class="devsite-syntax-n">pip</span> <span class="devsite-syntax-n">install</span> <span class="devsite-syntax-o">-</span><span class="devsite-syntax-n">q</span> <span class="devsite-syntax-n">requests</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">requests</span> <span class="devsite-syntax-n">headers</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-p">{</span><span class="devsite-syntax-s2">"content-type"</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-s2">"application/json"</span><span class="devsite-syntax-p">}</span> <span class="devsite-syntax-n">json_response</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">requests</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">post</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'http://localhost:8501/v1/models/fashion_model:predict'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">data</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">data</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">headers</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">headers</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">predictions</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">json</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">loads</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">json_response</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">text</span><span class="devsite-syntax-p">)[</span><span class="devsite-syntax-s1">'predictions'</span><span class="devsite-syntax-p">]</span> <span class="devsite-syntax-n">show</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'The model thought this was a </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1"> (class </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">), and it was actually a </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1"> (class </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">)'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span> <span class="devsite-syntax-n">class_names</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">np</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">argmax</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">predictions</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">])],</span> <span class="devsite-syntax-n">np</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">argmax</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">predictions</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">]),</span> <span class="devsite-syntax-n">class_names</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">]],</span> <span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">]))</span> </code></pre></devsite-code> <h4 id="a_particular_version_of_the_servable" data-text="A particular version of the servable" tabindex="-1">A particular version of the servable</h4> <p>Now let&#39;s specify a particular version of our servable. Since we only have one, let&#39;s select version 1. We&#39;ll also look at all three results.</p> <div></div><devsite-code><pre class="devsite-click-to-copy" translate="no" dir="ltr" is-upgraded syntax="Python"><code translate="no" dir="ltr"><span class="devsite-syntax-c1"># docs_infra: no_execute</span> <span class="devsite-syntax-n">headers</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-p">{</span><span class="devsite-syntax-s2">"content-type"</span><span class="devsite-syntax-p">:</span> <span class="devsite-syntax-s2">"application/json"</span><span class="devsite-syntax-p">}</span> <span class="devsite-syntax-n">json_response</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">requests</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">post</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s1">'http://localhost:8501/v1/models/fashion_model/versions/1:predict'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">data</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">data</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">headers</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">headers</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">predictions</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">json</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">loads</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">json_response</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">text</span><span class="devsite-syntax-p">)[</span><span class="devsite-syntax-s1">'predictions'</span><span class="devsite-syntax-p">]</span> <span class="devsite-syntax-k">for</span> <span class="devsite-syntax-n">i</span> <span class="devsite-syntax-ow">in</span> <span class="devsite-syntax-nb">range</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">0</span><span class="devsite-syntax-p">,</span><span class="devsite-syntax-mi">3</span><span class="devsite-syntax-p">):</span> <span class="devsite-syntax-n">show</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">i</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-s1">'The model thought this was a </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1"> (class </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">), and it was actually a </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1"> (class </span><span class="devsite-syntax-si">{}</span><span class="devsite-syntax-s1">)'</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">format</span><span class="devsite-syntax-p">(</span> <span class="devsite-syntax-n">class_names</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">np</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">argmax</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">predictions</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">i</span><span class="devsite-syntax-p">])],</span> <span class="devsite-syntax-n">np</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">argmax</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">predictions</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">i</span><span class="devsite-syntax-p">]),</span> <span class="devsite-syntax-n">class_names</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">i</span><span class="devsite-syntax-p">]],</span> <span class="devsite-syntax-n">test_labels</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">i</span><span class="devsite-syntax-p">]))</span> </code></pre></devsite-code> </div> <devsite-thumb-rating position="footer"> </devsite-thumb-rating> <div class="devsite-floating-action-buttons"> </div> </article> <devsite-content-footer class="nocontent"> <p>Except as otherwise noted, the content of this page is licensed under the <a href="https://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 License</a>, and code samples are licensed under the <a href="https://www.apache.org/licenses/LICENSE-2.0">Apache 2.0 License</a>. For details, see the <a href="https://developers.google.com/site-policies">Google Developers Site Policies</a>. Java is a registered trademark of Oracle and/or its affiliates.</p> <p>Last updated 2024-04-30 UTC.</p> </devsite-content-footer> <devsite-notification > </devsite-notification> <div class="devsite-content-data"> <template class="devsite-content-data-template"> [[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-30 UTC."],[],[]] </template> </div> </devsite-content> </main> <devsite-footer-promos class="devsite-footer"> </devsite-footer-promos> <devsite-footer-linkboxes class="devsite-footer"> <nav class="devsite-footer-linkboxes nocontent" aria-label="Footer links"> <ul class="devsite-footer-linkboxes-list"> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">Stay connected</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="//blog.tensorflow.org" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Blog </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//discuss.tensorflow.org" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > Forum </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//github.com/tensorflow/" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > GitHub </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//twitter.com/tensorflow" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > Twitter </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//youtube.com/tensorflow" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 5)" > YouTube </a> </li> </ul> </li> <li class="devsite-footer-linkbox "> <h3 class="devsite-footer-linkbox-heading no-link">Support</h3> <ul class="devsite-footer-linkbox-list"> <li class="devsite-footer-linkbox-item"> <a href="//github.com/tensorflow/tensorflow/issues" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 1)" > Issue tracker </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//github.com/tensorflow/tensorflow/blob/master/RELEASE.md" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 2)" > Release notes </a> </li> <li class="devsite-footer-linkbox-item"> <a href="//stackoverflow.com/questions/tagged/tensorflow" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 3)" > Stack Overflow </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/extras/tensorflow_brand_guidelines.pdf" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 4)" > Brand guidelines </a> </li> <li class="devsite-footer-linkbox-item"> <a href="/about/bib" class="devsite-footer-linkbox-link gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Footer Link (index 5)" > Cite TensorFlow </a> </li> </ul> </li> </ul> </nav> </devsite-footer-linkboxes> <devsite-footer-utility class="devsite-footer"> <div class="devsite-footer-utility nocontent"> <nav class="devsite-footer-utility-links" aria-label="Utility links"> <ul class="devsite-footer-utility-list"> <li class="devsite-footer-utility-item "> <a class="devsite-footer-utility-link gc-analytics-event" href="//policies.google.com/terms" data-category="Site-Wide Custom Events" data-label="Footer Terms link" > Terms </a> </li> <li class="devsite-footer-utility-item "> <a class="devsite-footer-utility-link gc-analytics-event" href="//policies.google.com/privacy" data-category="Site-Wide Custom Events" data-label="Footer Privacy link" > Privacy </a> </li> <li class="devsite-footer-utility-item glue-cookie-notification-bar-control"> <a class="devsite-footer-utility-link gc-analytics-event" href="#" data-category="Site-Wide Custom Events" data-label="Footer Manage cookies link" aria-hidden="true" > Manage cookies </a> </li> <li class="devsite-footer-utility-item devsite-footer-utility-button"> <span class="devsite-footer-utility-description">Sign up for the TensorFlow newsletter</span> <a class="devsite-footer-utility-link gc-analytics-event" href="//www.tensorflow.org/subscribe" data-category="Site-Wide Custom Events" data-label="Footer Subscribe link" > Subscribe </a> </li> </ul> <devsite-language-selector> <ul role="presentation"> <li role="presentation"> <a role="menuitem" lang="en" >English</a> </li> <li role="presentation"> <a role="menuitem" lang="es_419" >Español – América Latina</a> </li> <li role="presentation"> <a role="menuitem" lang="fr" >Français</a> </li> <li role="presentation"> <a role="menuitem" lang="id" >Indonesia</a> </li> <li role="presentation"> <a role="menuitem" lang="it" >Italiano</a> </li> <li role="presentation"> <a role="menuitem" lang="pl" >Polski</a> </li> <li role="presentation"> <a role="menuitem" lang="pt_br" >Português – Brasil</a> </li> <li role="presentation"> <a role="menuitem" lang="vi" >Tiếng Việt</a> </li> <li role="presentation"> <a role="menuitem" lang="tr" >Türkçe</a> </li> <li role="presentation"> <a role="menuitem" lang="ru" >Русский</a> </li> <li role="presentation"> <a role="menuitem" lang="he" >עברית</a> </li> <li role="presentation"> <a role="menuitem" lang="ar" >العربيّة</a> </li> <li role="presentation"> <a role="menuitem" lang="fa" >فارسی</a> </li> <li role="presentation"> <a role="menuitem" lang="hi" >हिंदी</a> </li> <li role="presentation"> <a role="menuitem" lang="bn" >বাংলা</a> </li> <li role="presentation"> <a role="menuitem" lang="th" >ภาษาไทย</a> </li> <li role="presentation"> <a role="menuitem" lang="zh_cn" >中文 – 简体</a> </li> <li role="presentation"> <a role="menuitem" lang="ja" >日本語</a> </li> <li role="presentation"> <a role="menuitem" lang="ko" >한국어</a> </li> </ul> </devsite-language-selector> </nav> </div> </devsite-footer-utility> <devsite-panel></devsite-panel> </section></section> <devsite-sitemask></devsite-sitemask> <devsite-snackbar></devsite-snackbar> <devsite-tooltip ></devsite-tooltip> <devsite-heading-link></devsite-heading-link> <devsite-analytics> <script type="application/json" analytics>[{&#34;dimensions&#34;: {&#34;dimension1&#34;: &#34;Signed out&#34;, &#34;dimension12&#34;: false, &#34;dimension6&#34;: &#34;en&#34;, &#34;dimension3&#34;: false, &#34;dimension5&#34;: &#34;en&#34;, &#34;dimension4&#34;: &#34;TFX&#34;}, &#34;gaid&#34;: &#34;UA-69864048-1&#34;, &#34;metrics&#34;: {&#34;ratings_count&#34;: &#34;metric2&#34;, &#34;ratings_value&#34;: &#34;metric1&#34;}, &#34;purpose&#34;: 0}]</script> <script type="application/json" tag-management>{&#34;at&#34;: &#34;True&#34;, &#34;ga4&#34;: [], &#34;ga4p&#34;: [], &#34;gtm&#34;: [{&#34;id&#34;: &#34;GTM-MXSL34P&#34;, &#34;purpose&#34;: 0}], &#34;parameters&#34;: {&#34;internalUser&#34;: &#34;False&#34;, &#34;language&#34;: {&#34;machineTranslated&#34;: &#34;False&#34;, &#34;requested&#34;: &#34;en&#34;, &#34;served&#34;: &#34;en&#34;}, &#34;pageType&#34;: &#34;article&#34;, &#34;projectName&#34;: &#34;TFX&#34;, &#34;signedIn&#34;: &#34;False&#34;, &#34;tenant&#34;: &#34;tensorflow&#34;, &#34;recommendations&#34;: {&#34;sourcePage&#34;: &#34;&#34;, &#34;sourceType&#34;: 0, &#34;sourceRank&#34;: 0, &#34;sourceIdenticalDescriptions&#34;: 0, &#34;sourceTitleWords&#34;: 0, &#34;sourceDescriptionWords&#34;: 0, &#34;experiment&#34;: &#34;&#34;}, &#34;experiment&#34;: {&#34;ids&#34;: &#34;&#34;}}}</script> </devsite-analytics> <devsite-badger></devsite-badger> <script nonce="SNbBpk4DWZ5VQL9IF+TthPLvohhQc/"> (function(d,e,v,s,i,t,E){d['GoogleDevelopersObject']=i; t=e.createElement(v);t.async=1;t.src=s;E=e.getElementsByTagName(v)[0]; E.parentNode.insertBefore(t,E);})(window, document, 'script', 'https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/js/app_loader.js', '[15,"en",null,"/js/devsite_app_module.js","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow","https://tensorflow-dot-devsite-v2-prod-3p.appspot.com",null,null,["/_pwa/tensorflow/manifest.json","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/images/video-placeholder.svg","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/images/favicon.png","https://www.gstatic.com/devrel-devsite/prod/v870e399c64f7c43c99a3043db4b3a74327bb93d0914e84a0c3dba90bbfd67625/tensorflow/images/lockup.svg","https://fonts.googleapis.com/css?family=Google+Sans:400,500|Roboto:400,400italic,500,500italic,700,700italic|Roboto+Mono:400,500,700&display=swap"],1,null,[1,6,8,12,14,17,21,25,50,52,63,70,75,76,80,87,91,92,93,97,98,100,101,102,103,104,105,107,108,109,110,112,113,117,118,120,122,124,125,126,127,129,130,131,132,133,134,135,136,138,140,141,147,148,149,151,152,156,157,158,159,161,163,164,168,169,170,179,180,182,183,186,191,193,196],"AIzaSyCNm9YxQumEXwGJgTDjxoxXK6m1F-9720Q","AIzaSyCc76DZePGtoyUjqKrLdsMGk_ry7sljLbY","www.tensorflow.org","AIzaSyB9bqgQ2t11WJsOX8qNsCQ6U-w91mmqF-I","AIzaSyAdYnStPdzjcJJtQ0mvIaeaMKj7_t6J_Fg",null,null,null,["MiscFeatureFlags__emergency_css","DevPro__enable_cloud_innovators_plus","MiscFeatureFlags__enable_explain_this_code","Cloud__enable_cloudx_ping","Profiles__enable_page_saving","CloudShell__cloud_code_overflow_menu","MiscFeatureFlags__developers_footer_image","Cloud__enable_free_trial_server_call","MiscFeatureFlags__enable_firebase_utm","TpcFeatures__enable_required_headers","TpcFeatures__enable_mirror_tenant_redirects","Profiles__enable_release_notes_notifications","Cloud__enable_cloud_facet_chat","CloudShell__cloud_shell_button","Experiments__reqs_query_experiments","MiscFeatureFlags__enable_view_transitions","Cloud__enable_cloud_dlp_service","Cloud__enable_cloudx_experiment_ids","Cloud__enable_cloud_shell","Search__enable_dynamic_content_confidential_banner","DevPro__enable_developer_subscriptions","Analytics__enable_clearcut_logging","Profiles__enable_profile_collections","BookNav__enable_tenant_cache_key","Search__enable_suggestions_from_borg","Profiles__enable_dashboard_curated_recommendations","Profiles__require_profile_eligibility_for_signin","MiscFeatureFlags__enable_variable_operator","MiscFeatureFlags__enable_project_variables","Search__enable_ai_eligibility_checks","EngEduTelemetry__enable_engedu_telemetry","MiscFeatureFlags__developers_footer_dark_image","Profiles__enable_public_developer_profiles","Profiles__enable_recognition_badges","Search__enable_page_map","Profiles__enable_complete_playlist_endpoint","Profiles__enable_completecodelab_endpoint","Cloud__enable_legacy_calculator_redirect","Profiles__enable_developer_profiles_callout","Concierge__enable_pushui","SignIn__enable_refresh_access_tokens","Profiles__enable_awarding_url","Cloud__enable_llm_concierge_chat","Cloud__enable_cloud_shell_fte_user_flow"],null,null,"AIzaSyA58TaKli1DculwmAmbpzLVGuWc8eCQgQc","https://developerscontentserving-pa.googleapis.com","AIzaSyDWBU60w0P9hEkr29kkksYs8Z7gvZ8u_wc","https://developerscontentsearch-pa.googleapis.com",2,4,null,"https://developerprofiles-pa.googleapis.com",[15,"tensorflow","TensorFlow","www.tensorflow.org",null,"tensorflow-dot-devsite-v2-prod-3p.appspot.com",null,null,[null,1,null,null,null,null,null,null,null,null,null,[1],null,null,null,null,null,null,[1],[1,null,null,[1]],null,null,null,[1,null,1],[1,1,null,1,1]],null,[25,null,null,null,null,null,"/images/lockup.svg","/images/logo.png",null,null,null,1,1,null,null,null,null,null,null,null,null,1,null,null,null,null,[]],[],null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,[6,1],null,[[],[1,1]],[[["UA-69864048-1"],["UA-69864048-4"],null,null,["UA-69864048-5"],["GTM-MXSL34P"],null,null,[["UA-69864048-1",1]],null,[["UA-69864048-5",1]],[["GTM-MXSL34P",1]],1],[[5,4],[6,5],[4,3],[1,1],[3,2],[12,8]],[[1,1],[2,2]]],null,4]]') </script> <devsite-a11y-announce></devsite-a11y-announce> </body> </html>

Pages: 1 2 3 4 5 6 7 8 9 10