CINXE.COM
The Sequential model | TensorFlow Core
<!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/guide/keras/sequential_model"><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/guide/keras/sequential_model" /><link rel="alternate" hreflang="x-default" href="https://www.tensorflow.org/guide/keras/sequential_model" /><link rel="alternate" hreflang="ar" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=ar" /><link rel="alternate" hreflang="bn" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=bn" /><link rel="alternate" hreflang="fa" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=fa" /><link rel="alternate" hreflang="fr" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=fr" /><link rel="alternate" hreflang="he" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=he" /><link rel="alternate" hreflang="hi" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=hi" /><link rel="alternate" hreflang="id" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=id" /><link rel="alternate" hreflang="it" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=it" /><link rel="alternate" hreflang="ja" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=ja" /><link rel="alternate" hreflang="ko" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=ko" /><link rel="alternate" hreflang="pl" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=pl" /><link rel="alternate" hreflang="pt-BR" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=pt-br" /><link rel="alternate" hreflang="ru" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=ru" /><link rel="alternate" hreflang="es-419" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=es-419" /><link rel="alternate" hreflang="th" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=th" /><link rel="alternate" hreflang="tr" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=tr" /><link rel="alternate" hreflang="vi" href="https://www.tensorflow.org/guide/keras/sequential_model?hl=vi" /><title>The Sequential model | TensorFlow Core</title> <meta property="og:title" content="The Sequential model | TensorFlow Core"><meta name="description" content="Complete guide to the Sequential model."> <meta property="og:description" content="Complete guide to the Sequential model."><meta property="og:url" content="https://www.tensorflow.org/guide/keras/sequential_model"><meta property="og:image" content="https://www.tensorflow.org/static/images/tf_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": "The Sequential model" } </script><script type="application/ld+json"> { "@context": "https://schema.org", "@type": "BreadcrumbList", "itemListElement": [{ "@type": "ListItem", "position": 1, "name": "TensorFlow Core", "item": "https://www.tensorflow.org/tutorials" },{ "@type": "ListItem", "position": 2, "name": "The Sequential model", "item": "https://www.tensorflow.org/guide/keras/sequential_model" }] } </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="TensorFlow Core" 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/tutorials" 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="TensorFlow Core" > TensorFlow Core </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/tutorials" track-metadata-eventdetail="https://www.tensorflow.org/tutorials" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - tutorials" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Tutorials" track-name="tutorials" > Tutorials </a> </tab> <tab class="devsite-active"> <a href="https://www.tensorflow.org/guide" track-metadata-eventdetail="https://www.tensorflow.org/guide" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - guide" track-metadata-module="primary nav" aria-label="Guide, selected" data-category="Site-Wide Custom Events" data-label="Tab: Guide" track-name="guide" > Guide </a> </tab> <tab > <a href="https://www.tensorflow.org/guide/migrate" track-metadata-eventdetail="https://www.tensorflow.org/guide/migrate" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - migrate to tf2" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: Migrate to TF2" track-name="migrate to tf2" > Migrate to TF2 </a> </tab> <tab > <a href="https://github.com/tensorflow/docs/tree/master/site/en/r1" track-metadata-eventdetail="https://github.com/tensorflow/docs/tree/master/site/en/r1" class="devsite-tabs-content gc-analytics-event " track-type="nav" track-metadata-position="nav - tf 1 ↗" track-metadata-module="primary nav" data-category="Site-Wide Custom Events" data-label="Tab: TF 1 ↗" track-name="tf 1 ↗" > TF 1 ↗ </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="/tutorials" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " 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 > Tutorials </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="/guide" class="devsite-nav-title gc-analytics-event devsite-nav-has-children devsite-nav-active" 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 menu="_book"> Guide </span> <span class="devsite-nav-icon material-icons" data-icon="forward" menu="_book"> </span> </a> </li> <li class="devsite-nav-item"> <a href="/guide/migrate" class="devsite-nav-title gc-analytics-event devsite-nav-has-children " data-category="Site-Wide Custom Events" data-label="Tab: Migrate to TF2" track-name="migrate to tf2" data-category="Site-Wide Custom Events" data-label="Responsive Tab: Migrate to TF2" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Migrate to TF2 </span> <span class="devsite-nav-icon material-icons" data-icon="forward" > </span> </a> </li> <li class="devsite-nav-item"> <a href="https://github.com/tensorflow/docs/tree/master/site/en/r1" class="devsite-nav-title gc-analytics-event " data-category="Site-Wide Custom Events" data-label="Tab: TF 1 ↗" track-name="tf 1 ↗" data-category="Site-Wide Custom Events" data-label="Responsive Tab: TF 1 ↗" track-type="globalNav" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > TF 1 ↗ </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="/guide" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide" ><span class="devsite-nav-text" tooltip>TensorFlow guide</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>TensorFlow basics</span> </div></li> <li class="devsite-nav-item"><a href="/guide/basics" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/basics" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/basics" ><span class="devsite-nav-text" tooltip>Overview</span></a></li> <li class="devsite-nav-item"><a href="/guide/tensor" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/tensor" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/tensor" ><span class="devsite-nav-text" tooltip>Tensors</span></a></li> <li class="devsite-nav-item"><a href="/guide/variable" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/variable" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/variable" ><span class="devsite-nav-text" tooltip>Variables</span></a></li> <li class="devsite-nav-item"><a href="/guide/autodiff" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/autodiff" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/autodiff" ><span class="devsite-nav-text" tooltip>Automatic differentiation</span></a></li> <li class="devsite-nav-item"><a href="/guide/intro_to_graphs" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/intro_to_graphs" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/intro_to_graphs" ><span class="devsite-nav-text" tooltip>Graphs and functions</span></a></li> <li class="devsite-nav-item"><a href="/guide/intro_to_modules" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/intro_to_modules" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/intro_to_modules" ><span class="devsite-nav-text" tooltip>Modules, layers, and models</span></a></li> <li class="devsite-nav-item"><a href="/guide/basic_training_loops" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/basic_training_loops" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/basic_training_loops" ><span class="devsite-nav-text" tooltip>Training loops</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>Keras</span> </div></li> <li class="devsite-nav-item"><a href="/guide/keras" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras" ><span class="devsite-nav-text" tooltip>Overview</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/sequential_model" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/sequential_model" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/sequential_model" ><span class="devsite-nav-text" tooltip>The Sequential model</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/functional_api" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/functional_api" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/functional_api" ><span class="devsite-nav-text" tooltip>The Functional API</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/training_with_built_in_methods" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/training_with_built_in_methods" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/training_with_built_in_methods" ><span class="devsite-nav-text" tooltip>Training & evaluation with the built-in methods</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/making_new_layers_and_models_via_subclassing" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/making_new_layers_and_models_via_subclassing" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/making_new_layers_and_models_via_subclassing" ><span class="devsite-nav-text" tooltip>Making new layers and models via subclassing</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/serialization_and_saving" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/serialization_and_saving" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/serialization_and_saving" ><span class="devsite-nav-text" tooltip>Serialization and saving</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/customizing_saving_and_serialization" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/customizing_saving_and_serialization" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/customizing_saving_and_serialization" ><span class="devsite-nav-text" tooltip>Customizing Saving</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/preprocessing_layers" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/preprocessing_layers" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/preprocessing_layers" ><span class="devsite-nav-text" tooltip>Working with preprocessing layers</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/customizing_what_happens_in_fit" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/customizing_what_happens_in_fit" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/customizing_what_happens_in_fit" ><span class="devsite-nav-text" tooltip>Customizing what happens in fit()</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/writing_a_training_loop_from_scratch" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/writing_a_training_loop_from_scratch" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/writing_a_training_loop_from_scratch" ><span class="devsite-nav-text" tooltip>Writing a training loop from scratch</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/working_with_rnns" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/working_with_rnns" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/working_with_rnns" ><span class="devsite-nav-text" tooltip>Working with RNNs</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/understanding_masking_and_padding" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/understanding_masking_and_padding" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/understanding_masking_and_padding" ><span class="devsite-nav-text" tooltip>Understanding masking & padding</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/writing_your_own_callbacks" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/writing_your_own_callbacks" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/writing_your_own_callbacks" ><span class="devsite-nav-text" tooltip>Writing your own callbacks</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/transfer_learning" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/transfer_learning" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/transfer_learning" ><span class="devsite-nav-text" tooltip>Transfer learning & fine-tuning</span></a></li> <li class="devsite-nav-item"><a href="/guide/keras/distributed_training" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/keras/distributed_training" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/keras/distributed_training" ><span class="devsite-nav-text" tooltip>Multi-GPU and distributed training</span></a></li> <li class="devsite-nav-item devsite-nav-heading devsite-nav-new"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Build with Core</span><span class="devsite-nav-icon material-icons" data-icon="new" data-title="New!" aria-hidden="true"></span> </div></li> <li class="devsite-nav-item"><a href="/guide/core" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core" ><span class="devsite-nav-text" tooltip>Overview</span></a></li> <li class="devsite-nav-item"><a href="/guide/core/quickstart_core" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core/quickstart_core" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core/quickstart_core" ><span class="devsite-nav-text" tooltip>Quickstart for Core</span></a></li> <li class="devsite-nav-item"><a href="/guide/core/logistic_regression_core" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core/logistic_regression_core" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core/logistic_regression_core" ><span class="devsite-nav-text" tooltip>Logistic regression</span></a></li> <li class="devsite-nav-item"><a href="/guide/core/mlp_core" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core/mlp_core" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core/mlp_core" ><span class="devsite-nav-text" tooltip>Multilayer perceptrons</span></a></li> <li class="devsite-nav-item"><a href="/guide/core/matrix_core" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core/matrix_core" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core/matrix_core" ><span class="devsite-nav-text" tooltip>Matrix approximation</span></a></li> <li class="devsite-nav-item"><a href="/guide/core/optimizers_core" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core/optimizers_core" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core/optimizers_core" ><span class="devsite-nav-text" tooltip>Custom optimizers</span></a></li> <li class="devsite-nav-item devsite-nav-experimental"><a href="/guide/core/distribution" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/core/distribution" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/core/distribution" ><span class="devsite-nav-text" tooltip>DTensor with Core APIs</span><span class="devsite-nav-icon material-icons" data-icon="experimental" data-title="Experimental!" aria-hidden="true"></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>TensorFlow in depth</span> </div></li> <li class="devsite-nav-item"><a href="/guide/tensor_slicing" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/tensor_slicing" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/tensor_slicing" ><span class="devsite-nav-text" tooltip>Tensor slicing</span></a></li> <li class="devsite-nav-item"><a href="/guide/advanced_autodiff" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/advanced_autodiff" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/advanced_autodiff" ><span class="devsite-nav-text" tooltip>Advanced autodiff</span></a></li> <li class="devsite-nav-item"><a href="/guide/ragged_tensor" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/ragged_tensor" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/ragged_tensor" ><span class="devsite-nav-text" tooltip>Ragged tensor</span></a></li> <li class="devsite-nav-item"><a href="/guide/sparse_tensor" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/sparse_tensor" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/sparse_tensor" ><span class="devsite-nav-text" tooltip>Sparse tensor</span></a></li> <li class="devsite-nav-item"><a href="/guide/random_numbers" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/random_numbers" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/random_numbers" ><span class="devsite-nav-text" tooltip>Random number generation</span></a></li> <li class="devsite-nav-item devsite-nav-experimental"><a href="/guide/tf_numpy" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/tf_numpy" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/tf_numpy" ><span class="devsite-nav-text" tooltip>NumPy API</span><span class="devsite-nav-icon material-icons" data-icon="experimental" data-title="Experimental!" aria-hidden="true"></span></a></li> <li class="devsite-nav-item devsite-nav-nightly"><a href="/guide/tf_numpy_type_promotion" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/tf_numpy_type_promotion" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/tf_numpy_type_promotion" ><span class="devsite-nav-text" tooltip>NumPy API Type Promotion</span><span class="devsite-nav-icon material-icons" data-icon="nightly" data-title="Nightly build only" aria-hidden="true"></span></a></li> <li class="devsite-nav-item devsite-nav-experimental"><a href="/guide/dtensor_overview" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/dtensor_overview" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/dtensor_overview" ><span class="devsite-nav-text" tooltip>DTensor concepts</span><span class="devsite-nav-icon material-icons" data-icon="experimental" data-title="Experimental!" aria-hidden="true"></span></a></li> <li class="devsite-nav-item"><a href="/guide/effective_tf2" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/effective_tf2" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/effective_tf2" ><span class="devsite-nav-text" tooltip>Thinking in TensorFlow 2</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>Customization</span> </div></li> <li class="devsite-nav-item"><a href="/guide/create_op" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/create_op" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/create_op" ><span class="devsite-nav-text" tooltip>Create an op</span></a></li> <li class="devsite-nav-item devsite-nav-experimental"><a href="/guide/extension_type" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/extension_type" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/extension_type" ><span class="devsite-nav-text" tooltip>Extension types</span><span class="devsite-nav-icon material-icons" data-icon="experimental" data-title="Experimental!" aria-hidden="true"></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 input pipelines</span> </div></li> <li class="devsite-nav-item"><a href="/guide/data" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/data" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/data" ><span class="devsite-nav-text" tooltip>tf.data</span></a></li> <li class="devsite-nav-item"><a href="/guide/data_performance" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/data_performance" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/data_performance" ><span class="devsite-nav-text" tooltip>Optimize pipeline performance</span></a></li> <li class="devsite-nav-item"><a href="/guide/data_performance_analysis" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/data_performance_analysis" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/data_performance_analysis" ><span class="devsite-nav-text" tooltip>Analyze pipeline performance</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>Import and export</span> </div></li> <li class="devsite-nav-item"><a href="/guide/checkpoint" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/checkpoint" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/checkpoint" ><span class="devsite-nav-text" tooltip>Checkpoint</span></a></li> <li class="devsite-nav-item"><a href="/guide/saved_model" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/saved_model" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/saved_model" ><span class="devsite-nav-text" tooltip>SavedModel</span></a></li> <li class="devsite-nav-item devsite-nav-new"><a href="/guide/jax2tf" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/jax2tf" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/jax2tf" ><span class="devsite-nav-text" tooltip>Import a JAX model using JAX2TF</span><span class="devsite-nav-icon material-icons" data-icon="new" data-title="New!" aria-hidden="true"></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>Accelerators</span> </div></li> <li class="devsite-nav-item"><a href="/guide/distributed_training" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/distributed_training" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/distributed_training" ><span class="devsite-nav-text" tooltip>Distributed training</span></a></li> <li class="devsite-nav-item"><a href="/guide/gpu" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/gpu" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/gpu" ><span class="devsite-nav-text" tooltip>GPU</span></a></li> <li class="devsite-nav-item"><a href="/guide/tpu" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/tpu" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/tpu" ><span class="devsite-nav-text" tooltip>TPU</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>Performance</span> </div></li> <li class="devsite-nav-item"><a href="/guide/function" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/function" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/function" ><span class="devsite-nav-text" tooltip>Better performance with tf.function</span></a></li> <li class="devsite-nav-item"><a href="/guide/profiler" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/profiler" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/profiler" ><span class="devsite-nav-text" tooltip>Profile TensorFlow performance</span></a></li> <li class="devsite-nav-item"><a href="/guide/gpu_performance_analysis" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/gpu_performance_analysis" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/gpu_performance_analysis" ><span class="devsite-nav-text" tooltip>Optimize GPU Performance</span></a></li> <li class="devsite-nav-item"><a href="/guide/graph_optimization" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/graph_optimization" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/graph_optimization" ><span class="devsite-nav-text" tooltip>Graph optimization</span></a></li> <li class="devsite-nav-item"><a href="/guide/mixed_precision" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/mixed_precision" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/mixed_precision" ><span class="devsite-nav-text" tooltip>Mixed precision</span></a></li> <li class="devsite-nav-item devsite-nav-heading devsite-nav-new"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Model Garden</span><span class="devsite-nav-icon material-icons" data-icon="new" data-title="New!" aria-hidden="true"></span> </div></li> <li class="devsite-nav-item"><a href="/tfmodels" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels" ><span class="devsite-nav-text" tooltip>Overview</span></a></li> <li class="devsite-nav-item"><a href="/tfmodels/orbit" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels/orbit" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels/orbit" ><span class="devsite-nav-text" tooltip>Training with Orbit</span></a></li> <li class="devsite-nav-item devsite-nav-external"><a href="/tfmodels/nlp" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels/nlp" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels/nlp" ><span class="devsite-nav-text" tooltip>TFModels - NLP</span><span class="devsite-nav-icon material-icons" data-icon="external" data-title="External" aria-hidden="true"></span></a></li> <li class="devsite-nav-item"><a href="/tfmodels/vision/image_classification" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels/vision/image_classification" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels/vision/image_classification" ><span class="devsite-nav-text" tooltip>Example: Image classification</span></a></li> <li class="devsite-nav-item"><a href="/tfmodels/vision/object_detection" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels/vision/object_detection" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels/vision/object_detection" ><span class="devsite-nav-text" tooltip>Example: Object Detection</span></a></li> <li class="devsite-nav-item"><a href="/tfmodels/vision/semantic_segmentation" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels/vision/semantic_segmentation" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels/vision/semantic_segmentation" ><span class="devsite-nav-text" tooltip>Example: Semantic Segmentation</span></a></li> <li class="devsite-nav-item"><a href="/tfmodels/vision/instance_segmentation" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /tfmodels/vision/instance_segmentation" track-type="bookNav" track-name="click" track-metadata-eventdetail="/tfmodels/vision/instance_segmentation" ><span class="devsite-nav-text" tooltip>Example: Instance Segmentation</span></a></li> <li class="devsite-nav-item devsite-nav-heading devsite-nav-deprecated"><div class="devsite-nav-title devsite-nav-title-no-path"> <span class="devsite-nav-text" tooltip>Estimators</span><span class="devsite-nav-icon material-icons" data-icon="deprecated" data-title="Deprecated" aria-hidden="true"></span> </div></li> <li class="devsite-nav-item"><a href="/guide/estimator" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/estimator" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/estimator" ><span class="devsite-nav-text" tooltip>Estimator overview</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>Appendix</span> </div></li> <li class="devsite-nav-item"><a href="/guide/versions" class="devsite-nav-title gc-analytics-event" data-category="Site-Wide Custom Events" data-label="Book nav link, pathname: /guide/versions" track-type="bookNav" track-name="click" track-metadata-eventdetail="/guide/versions" ><span class="devsite-nav-text" tooltip>Version compatibility</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 & datasets" track-type="navMenu" track-metadata-eventDetail="globalMenu" track-metadata-position="nav"> <span class="devsite-nav-text" tooltip > Models & 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/tutorials" 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="TensorFlow Core" > TensorFlow Core </a> </li> <li class="devsite-breadcrumb-item "> <div class="devsite-breadcrumb-guillemet material-icons" aria-hidden="true"></div> <a href="https://www.tensorflow.org/guide" 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="" > Guide </a> </li> </ul> <devsite-thumb-rating position="header"> </devsite-thumb-rating> </div> <h1 class="devsite-page-title" tabindex="-1"> The Sequential model </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></p> <!-- DO NOT EDIT! Automatically generated file. --> <div itemscope itemtype="http://developers.google.com/ReferenceObject"> <meta itemprop="name" content="The Sequential model" /> <meta itemprop="path" content="Guide & Tutorials" /> <meta itemprop="property" content="tf.ones"/> </div> <p><strong>Author:</strong> <a href="https://twitter.com/fchollet">fchollet</a><br></p> <table class="tfo-notebook-buttons" align="left"> <td> <a target="_blank" href="https://www.tensorflow.org/guide/keras/sequential_model"><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/keras-team/keras-io/blob/master/guides/ipynb/sequential_model.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/keras-team/keras-io/blob/master/guides/sequential_model.py"><img src="https://www.tensorflow.org/images/GitHub-Mark-32px.png">View source on GitHub</a> </td> <td> <a href="https://keras.io/guides/sequential_model"><img src="https://www.tensorflow.org/images/keras32px.png">View on keras.io</a> </td> </table> <h2 id="setup" data-text="Setup" tabindex="-1">Setup</h2> <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">tensorflow</span> <span class="devsite-syntax-k">as</span> <span class="devsite-syntax-nn">tf</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-nn">keras</span> <span class="devsite-syntax-kn">from</span> <span class="devsite-syntax-nn">keras</span> <span class="devsite-syntax-kn">import</span> <span class="devsite-syntax-n">layers</span> </code></pre></devsite-code> <h2 id="when_to_use_a_sequential_model" data-text="When to use a Sequential model" tabindex="-1">When to use a Sequential model</h2> <p>A <code translate="no" dir="ltr">Sequential</code> model is appropriate for <strong>a plain stack of layers</strong> where each layer has <strong>exactly one input tensor and one output tensor</strong>.</p> <p>Schematically, the following <code translate="no" dir="ltr">Sequential</code> model:</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"># Define Sequential model with 3 layers</span> <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-p">[</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">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-s2">"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-s2">"layer1"</span><span class="devsite-syntax-p">),</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">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"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-s2">"layer2"</span><span class="devsite-syntax-p">),</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">4</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"layer3"</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">]</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># Call model on a test input</span> <span class="devsite-syntax-n">x</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">ones</span><span class="devsite-syntax-p">((</span><span class="devsite-syntax-mi">3</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">y</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">x</span><span class="devsite-syntax-p">)</span> </code></pre></devsite-code> <p>is equivalent to this function:</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"># Create 3 layers</span> <span class="devsite-syntax-n">layer1</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">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-s2">"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-s2">"layer1"</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">layer2</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">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"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-s2">"layer2"</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">layer3</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">4</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"layer3"</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># Call layers on a test input</span> <span class="devsite-syntax-n">x</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">ones</span><span class="devsite-syntax-p">((</span><span class="devsite-syntax-mi">3</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">y</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">layer3</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">layer2</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">layer1</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">x</span><span class="devsite-syntax-p">)))</span> </code></pre></devsite-code> <p>A Sequential model is <strong>not appropriate</strong> when:</p> <ul> <li>Your model has multiple inputs or multiple outputs</li> <li>Any of your layers has multiple inputs or multiple outputs</li> <li>You need to do layer sharing</li> <li>You want non-linear topology (e.g. a residual connection, a multi-branch model)</li> </ul> <h2 id="creating_a_sequential_model" data-text="Creating a Sequential model" tabindex="-1">Creating a Sequential model</h2> <p>You can create a Sequential model by passing a list of layers to the Sequential constructor:</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-p">[</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">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-s2">"relu"</span><span class="devsite-syntax-p">),</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">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</span><span class="devsite-syntax-p">),</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">4</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">]</span> <span class="devsite-syntax-p">)</span> </code></pre></devsite-code> <p>Its layers are accessible via the <code translate="no" dir="ltr">layers</code> attribute:</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">layers</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> [<keras.src.layers.core.dense.Dense at 0x7fa3c8de0100>, <keras.src.layers.core.dense.Dense at 0x7fa3c8de09a0>, <keras.src.layers.core.dense.Dense at 0x7fa5181b5c10>] </pre></devsite-code> <p>You can also create a Sequential model incrementally via the <code translate="no" dir="ltr">add()</code> method:</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</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">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-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</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">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</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">4</span><span class="devsite-syntax-p">))</span> </code></pre></devsite-code> <p>Note that there's also a corresponding <code translate="no" dir="ltr">pop()</code> method to remove layers: a Sequential model behaves very much like a list of layers.</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">pop</span><span class="devsite-syntax-p">()</span> <span class="devsite-syntax-nb">print</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-c1"># 2</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> 2 </pre></devsite-code> <p>Also note that the Sequential constructor accepts a <code translate="no" dir="ltr">name</code> argument, just like any layer or model in Keras. This is useful to annotate TensorBoard graphs with semantically meaningful names.</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">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"my_sequential"</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">add</span><span class="devsite-syntax-p">(</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">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-s2">"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-s2">"layer1"</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">add</span><span class="devsite-syntax-p">(</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">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"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-s2">"layer2"</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">add</span><span class="devsite-syntax-p">(</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">4</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"layer3"</span><span class="devsite-syntax-p">))</span> </code></pre></devsite-code> <h2 id="specifying_the_input_shape_in_advance" data-text="Specifying the input shape in advance" tabindex="-1">Specifying the input shape in advance</h2> <p>Generally, all layers in Keras need to know the shape of their inputs in order to be able to create their weights. So when you create a layer like this, initially, it has no weights:</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">layer</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">3</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">layer</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">weights</span> <span class="devsite-syntax-c1"># Empty</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> [] </pre></devsite-code> <p>It creates its weights the first time it is called on an input, since the shape of the weights depends on the shape of the inputs:</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"># Call layer on a test input</span> <span class="devsite-syntax-n">x</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">ones</span><span class="devsite-syntax-p">((</span><span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">4</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-n">y</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">layer</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">x</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">layer</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">weights</span> <span class="devsite-syntax-c1"># Now it has weights, of shape (4, 3) and (3,)</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> [<tf.Variable 'dense_6/kernel:0' shape=(4, 3) dtype=float32, numpy= array([[ 0.1752373 , 0.47623062, 0.24374962], [-0.0298934 , 0.50255656, 0.78478384], [-0.58323103, -0.56861055, -0.7190975 ], [-0.3191281 , -0.23635858, -0.8841506 ]], dtype=float32)>, <tf.Variable 'dense_6/bias:0' shape=(3,) dtype=float32, numpy=array([0., 0., 0.], dtype=float32)>] </pre></devsite-code> <p>Naturally, this also applies to Sequential models. When you instantiate a Sequential model without an input shape, it isn't "built": it has no weights (and calling <code translate="no" dir="ltr">model.weights</code> results in an error stating just this). The weights are created when the model first sees some input 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-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-p">[</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">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-s2">"relu"</span><span class="devsite-syntax-p">),</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">3</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</span><span class="devsite-syntax-p">),</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">4</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">]</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># No weights at this stage!</span> <span class="devsite-syntax-c1"># At this point, you can't do this:</span> <span class="devsite-syntax-c1"># model.weights</span> <span class="devsite-syntax-c1"># You also can't do this:</span> <span class="devsite-syntax-c1"># model.summary()</span> <span class="devsite-syntax-c1"># Call the model on a test input</span> <span class="devsite-syntax-n">x</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">ones</span><span class="devsite-syntax-p">((</span><span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">4</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-n">y</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">x</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-nb">print</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-s2">"Number of weights after calling the model:"</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">weights</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-c1"># 6</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Number of weights after calling the model: 6 </pre></devsite-code> <p>Once a model is "built", you can call its <code translate="no" dir="ltr">summary()</code> method to display its contents:</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">summary</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: "sequential_3" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_7 (Dense) (1, 2) 10 dense_8 (Dense) (1, 3) 9 dense_9 (Dense) (1, 4) 16 ================================================================= Total params: 35 (140.00 Byte) Trainable params: 35 (140.00 Byte) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________ </pre></devsite-code> <p>However, it can be very useful when building a Sequential model incrementally to be able to display the summary of the model so far, including the current output shape. In this case, you should start your model by passing an <code translate="no" dir="ltr">Input</code> object to your model, so that it knows its input shape from the start:</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</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">Input</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">4</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">add</span><span class="devsite-syntax-p">(</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">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-s2">"relu"</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> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Model: "sequential_4" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_10 (Dense) (None, 2) 10 ================================================================= Total params: 10 (40.00 Byte) Trainable params: 10 (40.00 Byte) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________ </pre></devsite-code> <p>Note that the <code translate="no" dir="ltr">Input</code> object is not displayed as part of <code translate="no" dir="ltr">model.layers</code>, since it isn't a layer:</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">layers</span> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> [<keras.src.layers.core.dense.Dense at 0x7fa3bc0ba820>] </pre></devsite-code> <p>A simple alternative is to just pass an <code translate="no" dir="ltr">input_shape</code> argument to your first layer:</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</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">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-s2">"relu"</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">4</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> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Model: "sequential_5" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= dense_11 (Dense) (None, 2) 10 ================================================================= Total params: 10 (40.00 Byte) Trainable params: 10 (40.00 Byte) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________ </pre></devsite-code> <p>Models built with a predefined input shape like this always have weights (even before seeing any data) and always have a defined output shape.</p> <p>In general, it's a recommended best practice to always specify the input shape of a Sequential model in advance if you know what it is.</p> <h2 id="a_common_debugging_workflow_add_summary" data-text="A common debugging workflow: add() + summary()" tabindex="-1">A common debugging workflow: <code translate="no" dir="ltr">add()</code> + <code translate="no" dir="ltr">summary()</code></h2> <p>When building a new Sequential architecture, it's useful to incrementally stack layers with <code translate="no" dir="ltr">add()</code> and frequently print model summaries. For instance, this enables you to monitor how a stack of <code translate="no" dir="ltr">Conv2D</code> and <code translate="no" dir="ltr">MaxPooling2D</code> layers is downsampling image feature maps:</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</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">Input</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">250</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">3</span><span class="devsite-syntax-p">)))</span> <span class="devsite-syntax-c1"># 250x250 RGB images</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</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-mi">32</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">5</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-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">MaxPooling2D</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">3</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-c1"># Can you guess what the current output shape is at this point? Probably not.</span> <span class="devsite-syntax-c1"># Let's just print it:</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-c1"># The answer was: (40, 40, 32), so we can keep downsampling...</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">MaxPooling2D</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">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</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">add</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">MaxPooling2D</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">2</span><span class="devsite-syntax-p">))</span> <span class="devsite-syntax-c1"># And now?</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-c1"># Now that we have 4x4 feature maps, time to apply global max pooling.</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">GlobalMaxPooling2D</span><span class="devsite-syntax-p">())</span> <span class="devsite-syntax-c1"># Finally, we add a classification layer.</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">add</span><span class="devsite-syntax-p">(</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> </code></pre></devsite-code> <div></div><devsite-code><pre class="tfo-notebook-code-cell-output" translate="no" dir="ltr" is-upgraded> Model: "sequential_6" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d (Conv2D) (None, 123, 123, 32) 2432 conv2d_1 (Conv2D) (None, 121, 121, 32) 9248 max_pooling2d (MaxPooling2 (None, 40, 40, 32) 0 D) ================================================================= Total params: 11680 (45.62 KB) Trainable params: 11680 (45.62 KB) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________ Model: "sequential_6" _________________________________________________________________ Layer (type) Output Shape Param # ================================================================= conv2d (Conv2D) (None, 123, 123, 32) 2432 conv2d_1 (Conv2D) (None, 121, 121, 32) 9248 max_pooling2d (MaxPooling2 (None, 40, 40, 32) 0 D) conv2d_2 (Conv2D) (None, 38, 38, 32) 9248 conv2d_3 (Conv2D) (None, 36, 36, 32) 9248 max_pooling2d_1 (MaxPoolin (None, 12, 12, 32) 0 g2D) conv2d_4 (Conv2D) (None, 10, 10, 32) 9248 conv2d_5 (Conv2D) (None, 8, 8, 32) 9248 max_pooling2d_2 (MaxPoolin (None, 4, 4, 32) 0 g2D) ================================================================= Total params: 48672 (190.12 KB) Trainable params: 48672 (190.12 KB) Non-trainable params: 0 (0.00 Byte) _________________________________________________________________ </pre></devsite-code> <p>Very practical, right?</p> <h2 id="what_to_do_once_you_have_a_model" data-text="What to do once you have a model" tabindex="-1">What to do once you have a model</h2> <p>Once your model architecture is ready, you will want to:</p> <ul> <li>Train your model, evaluate it, and run inference. See our <a href="/guides/training_with_built_in_methods">guide to training & evaluation with the built-in loops</a></li> <li>Save your model to disk and restore it. See our <a href="/guide/keras/serialization_and_saving">guide to serialization & saving</a>.</li> <li>Speed up model training by leveraging multiple GPUs. See our <a href="/guide/keras/distributed_training">guide to multi-GPU and distributed training</a>.</li> </ul> <h2 id="feature_extraction_with_a_sequential_model" data-text="Feature extraction with a Sequential model" tabindex="-1">Feature extraction with a Sequential model</h2> <p>Once a Sequential model has been built, it behaves like a <a href="/guide/keras/functional_api">Functional API model</a>. This means that every layer has an <code translate="no" dir="ltr">input</code> and <code translate="no" dir="ltr">output</code> attribute. These attributes can be used to do neat things, like quickly creating a model that extracts the outputs of all intermediate layers in a Sequential model:</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">initial_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-p">[</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Input</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">250</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</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">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-mi">32</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">5</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-s2">"relu"</span><span class="devsite-syntax-p">),</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</span><span class="devsite-syntax-p">),</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">]</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">feature_extractor</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">Model</span><span class="devsite-syntax-p">(</span> <span class="devsite-syntax-n">inputs</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">initial_model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">inputs</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">outputs</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">[</span><span class="devsite-syntax-n">layer</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">output</span> <span class="devsite-syntax-k">for</span> <span class="devsite-syntax-n">layer</span> <span class="devsite-syntax-ow">in</span> <span class="devsite-syntax-n">initial_model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">layers</span><span class="devsite-syntax-p">],</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># Call feature extractor on test input.</span> <span class="devsite-syntax-n">x</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">ones</span><span class="devsite-syntax-p">((</span><span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</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">features</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">feature_extractor</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">x</span><span class="devsite-syntax-p">)</span> </code></pre></devsite-code> <p>Here's a similar example that only extract features from one layer:</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">initial_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-p">[</span> <span class="devsite-syntax-n">keras</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Input</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">250</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</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">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-mi">32</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">5</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-s2">"relu"</span><span class="devsite-syntax-p">),</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"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-s2">"my_intermediate_layer"</span><span class="devsite-syntax-p">),</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-mi">32</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">activation</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"relu"</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">]</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-n">feature_extractor</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">Model</span><span class="devsite-syntax-p">(</span> <span class="devsite-syntax-n">inputs</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">initial_model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">inputs</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">outputs</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-n">initial_model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">get_layer</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">name</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s2">"my_intermediate_layer"</span><span class="devsite-syntax-p">)</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">output</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># Call feature extractor on test input.</span> <span class="devsite-syntax-n">x</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">ones</span><span class="devsite-syntax-p">((</span><span class="devsite-syntax-mi">1</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-mi">250</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">features</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-n">feature_extractor</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">x</span><span class="devsite-syntax-p">)</span> </code></pre></devsite-code> <h2 id="transfer_learning_with_a_sequential_model" data-text="Transfer learning with a Sequential model" tabindex="-1">Transfer learning with a Sequential model</h2> <p>Transfer learning consists of freezing the bottom layers in a model and only training the top layers. If you aren't familiar with it, make sure to read our <a href="/guide/keras/transfer_learning">guide to transfer learning</a>.</p> <p>Here are two common transfer learning blueprint involving Sequential models.</p> <p>First, let's say that you have a Sequential model, and you want to freeze all layers except the last one. In this case, you would simply iterate over <code translate="no" dir="ltr">model.layers</code> and set <code translate="no" dir="ltr">layer.trainable = False</code> on each layer, except the last one. Like this:</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">Input</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-n">shape</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-mi">784</span><span class="devsite-syntax-p">)),</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">32</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">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">32</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">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">32</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">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-p">])</span> <span class="devsite-syntax-c1"># Presumably you would want to first load pre-trained weights.</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">load_weights</span><span class="devsite-syntax-p">(</span><span class="devsite-syntax-o">...</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># Freeze all layers except the last one.</span> <span class="devsite-syntax-k">for</span> <span class="devsite-syntax-n">layer</span> <span class="devsite-syntax-ow">in</span> <span class="devsite-syntax-n">model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">layers</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">layer</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">trainable</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-kc">False</span> <span class="devsite-syntax-c1"># Recompile and train (this will only update the weights of the last layer).</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-o">...</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-o">...</span><span class="devsite-syntax-p">)</span> </code></pre></devsite-code> <p>Another common blueprint is to use a Sequential model to stack a pre-trained model and some freshly initialized classification layers. Like this:</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"># Load a convolutional base with pre-trained weights</span> <span class="devsite-syntax-n">base_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">applications</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">Xception</span><span class="devsite-syntax-p">(</span> <span class="devsite-syntax-n">weights</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s1">'imagenet'</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">include_top</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-kc">False</span><span class="devsite-syntax-p">,</span> <span class="devsite-syntax-n">pooling</span><span class="devsite-syntax-o">=</span><span class="devsite-syntax-s1">'avg'</span><span class="devsite-syntax-p">)</span> <span class="devsite-syntax-c1"># Freeze the base model</span> <span class="devsite-syntax-n">base_model</span><span class="devsite-syntax-o">.</span><span class="devsite-syntax-n">trainable</span> <span class="devsite-syntax-o">=</span> <span class="devsite-syntax-kc">False</span> <span class="devsite-syntax-c1"># Use a Sequential model to add a trainable classifier on top</span> <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">base_model</span><span class="devsite-syntax-p">,</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">1000</span><span class="devsite-syntax-p">),</span> <span class="devsite-syntax-p">])</span> <span class="devsite-syntax-c1"># Compile & train</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-o">...</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-o">...</span><span class="devsite-syntax-p">)</span> </code></pre></devsite-code> <p>If you do transfer learning, you will probably find yourself frequently using these two patterns.</p> <p>That's about all you need to know about Sequential models!</p> <p>To find out more about building models in Keras, see:</p> <ul> <li><a href="/guide/keras/functional_api">Guide to the Functional API</a></li> <li><a href="/guides/making_new_layers_and_models_via_subclassing">Guide to making new Layers & Models via subclassing</a></li> </ul> </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 2023-07-24 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 2023-07-24 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>[{"dimensions": {"dimension4": "TensorFlow Core", "dimension1": "Signed out", "dimension3": false, "dimension12": false, "dimension6": "en", "dimension5": "en"}, "gaid": "UA-69864048-1", "metrics": {"ratings_count": "metric2", "ratings_value": "metric1"}, "purpose": 0}]</script> <script type="application/json" tag-management>{"at": "True", "ga4": [], "ga4p": [], "gtm": [{"id": "GTM-MXSL34P", "purpose": 0}], "parameters": {"internalUser": "False", "language": {"machineTranslated": "False", "requested": "en", "served": "en"}, "pageType": "article", "projectName": "TensorFlow Core", "signedIn": "False", "tenant": "tensorflow", "recommendations": {"sourcePage": "", "sourceType": 0, "sourceRank": 0, "sourceIdenticalDescriptions": 0, "sourceTitleWords": 0, "sourceDescriptionWords": 0, "experiment": ""}, "experiment": {"ids": ""}}}</script> </devsite-analytics> <devsite-badger></devsite-badger> <script nonce="wQNpVrjRsPLOvs3+VZRJQu25xJp2mt"> (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,116,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,["Search__enable_dynamic_content_confidential_banner","Experiments__reqs_query_experiments","Profiles__enable_dashboard_curated_recommendations","Profiles__require_profile_eligibility_for_signin","Cloud__enable_cloud_shell_fte_user_flow","Profiles__enable_profile_collections","DevPro__enable_developer_subscriptions","MiscFeatureFlags__enable_view_transitions","Profiles__enable_release_notes_notifications","Cloud__enable_cloud_dlp_service","Profiles__enable_complete_playlist_endpoint","Search__enable_page_map","Cloud__enable_cloudx_experiment_ids","Cloud__enable_llm_concierge_chat","Search__enable_ai_eligibility_checks","EngEduTelemetry__enable_engedu_telemetry","Profiles__enable_developer_profiles_callout","Cloud__enable_cloud_shell","CloudShell__cloud_shell_button","Profiles__enable_public_developer_profiles","Cloud__enable_legacy_calculator_redirect","TpcFeatures__enable_required_headers","TpcFeatures__enable_mirror_tenant_redirects","MiscFeatureFlags__enable_firebase_utm","Analytics__enable_clearcut_logging","Cloud__enable_cloudx_ping","MiscFeatureFlags__developers_footer_image","Profiles__enable_recognition_badges","Concierge__enable_pushui","Profiles__enable_completecodelab_endpoint","MiscFeatureFlags__emergency_css","Profiles__enable_awarding_url","MiscFeatureFlags__developers_footer_dark_image","Cloud__enable_cloud_facet_chat","Cloud__enable_free_trial_server_call","Search__enable_suggestions_from_borg","MiscFeatureFlags__enable_explain_this_code","SignIn__enable_refresh_access_tokens","CloudShell__cloud_code_overflow_menu","BookNav__enable_tenant_cache_key","Profiles__enable_page_saving","DevPro__enable_cloud_innovators_plus","MiscFeatureFlags__enable_variable_operator","MiscFeatureFlags__enable_project_variables"],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],[[4,3],[5,4],[3,2],[12,8],[1,1],[6,5]],[[1,1],[2,2]]],null,4]]') </script> <devsite-a11y-announce></devsite-a11y-announce> </body> </html>