{"id":3316,"date":"2024-03-13T06:45:25","date_gmt":"2024-03-13T06:45:25","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/"},"modified":"2025-07-30T14:27:36","modified_gmt":"2025-07-30T14:27:36","slug":"how-to-utilize-pre-trained-models-in-keras","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/","title":{"rendered":"Keras Pre-trained Models: A Guide"},"content":{"rendered":"<p>There are two ways to use pre-trained models in Keras: either by utilizing pre-trained models already provided in Keras (such as VGG16, ResNet50, InceptionV3, etc.) or by using models trained in other deep learning frameworks (like TensorFlow, PyTorch).<\/p>\n<ol>\n<li>Utilize the pre-trained models provided by Keras.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">from<\/span> keras.applications.vgg16 <span class=\"hljs-keyword\">import<\/span> VGG16\r\n<span class=\"hljs-keyword\">from<\/span> keras.applications.vgg16 <span class=\"hljs-keyword\">import<\/span> preprocess_input, decode_predictions\r\n<span class=\"hljs-keyword\">from<\/span> keras.preprocessing <span class=\"hljs-keyword\">import<\/span> image\r\n<span class=\"hljs-keyword\">import<\/span> numpy <span class=\"hljs-keyword\">as<\/span> np\r\n\r\n<span class=\"hljs-comment\"># \u52a0\u8f7d\u9884\u8bad\u7ec3\u7684VGG16\u6a21\u578b<\/span>\r\nmodel = VGG16(weights=<span class=\"hljs-string\">'imagenet'<\/span>)\r\n\r\n<span class=\"hljs-comment\"># \u52a0\u8f7d\u8981\u9884\u6d4b\u7684\u56fe\u7247\uff0c\u5e76\u8fdb\u884c\u9884\u5904\u7406<\/span>\r\nimg_path = <span class=\"hljs-string\">'path_to_your_image.jpg'<\/span>\r\nimg = image.load_img(img_path, target_size=(<span class=\"hljs-number\">224<\/span>, <span class=\"hljs-number\">224<\/span>))\r\nx = image.img_to_array(img)\r\nx = np.expand_dims(x, axis=<span class=\"hljs-number\">0<\/span>)\r\nx = preprocess_input(x)\r\n\r\n<span class=\"hljs-comment\"># \u9884\u6d4b\u56fe\u50cf\u7684\u7c7b\u522b<\/span>\r\npreds = model.predict(x)\r\npredictions = decode_predictions(preds, top=<span class=\"hljs-number\">3<\/span>)[<span class=\"hljs-number\">0<\/span>]\r\n<span class=\"hljs-keyword\">for<\/span> i, (imagenetID, label, score) <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-built_in\">enumerate<\/span>(predictions):\r\n    <span class=\"hljs-built_in\">print<\/span>(<span class=\"hljs-string\">\"{}. {}: {:.2f}%\"<\/span>.<span class=\"hljs-built_in\">format<\/span>(i + <span class=\"hljs-number\">1<\/span>, label, score * <span class=\"hljs-number\">100<\/span>))\r\n<\/code><\/pre>\n<ol>\n<li>Utilize models trained in other deep learning frameworks.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">import<\/span> tensorflow <span class=\"hljs-keyword\">as<\/span> tf\r\n<span class=\"hljs-keyword\">from<\/span> keras.applications.vgg16 <span class=\"hljs-keyword\">import<\/span> preprocess_input\r\n<span class=\"hljs-keyword\">from<\/span> keras.preprocessing <span class=\"hljs-keyword\">import<\/span> image\r\n<span class=\"hljs-keyword\">import<\/span> numpy <span class=\"hljs-keyword\">as<\/span> np\r\n\r\n<span class=\"hljs-comment\"># \u52a0\u8f7d\u5176\u4ed6\u6df1\u5ea6\u5b66\u4e60\u6846\u67b6\u4e2d\u8bad\u7ec3\u597d\u7684\u6a21\u578b<\/span>\r\nmodel = tf.keras.models.load_model(<span class=\"hljs-string\">'path_to_your_model.h5'<\/span>)\r\n\r\n<span class=\"hljs-comment\"># \u52a0\u8f7d\u8981\u9884\u6d4b\u7684\u56fe\u7247\uff0c\u5e76\u8fdb\u884c\u9884\u5904\u7406<\/span>\r\nimg_path = <span class=\"hljs-string\">'path_to_your_image.jpg'<\/span>\r\nimg = image.load_img(img_path, target_size=(<span class=\"hljs-number\">224<\/span>, <span class=\"hljs-number\">224<\/span>))\r\nx = image.img_to_array(img)\r\nx = np.expand_dims(x, axis=<span class=\"hljs-number\">0<\/span>)\r\nx = preprocess_input(x)\r\n\r\n<span class=\"hljs-comment\"># \u9884\u6d4b\u56fe\u50cf\u7684\u7c7b\u522b<\/span>\r\npreds = model.predict(x)\r\n<\/code><\/pre>\n<p>You can use pre-trained models in Keras for tasks such as image classification and object detection using the two methods mentioned above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are two ways to use pre-trained models in Keras: either by utilizing pre-trained models already provided in Keras (such as VGG16, ResNet50, InceptionV3, etc.) or by using models trained in other deep learning frameworks (like TensorFlow, PyTorch). Utilize the pre-trained models provided by Keras. from keras.applications.vgg16 import VGG16 from keras.applications.vgg16 import preprocess_input, decode_predictions from [&hellip;]<\/p>\n","protected":false},"author":11,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[960,1251,1218,1292,1291],"class_list":["post-3316","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-deep-learning","tag-keras","tag-pre-trained-models","tag-resnet50","tag-vgg16"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Keras Pre-trained Models: A Guide - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Learn how to use pre-trained models in Keras effectively. Explore VGG16, ResNet50, and more with practical examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Keras Pre-trained Models: A Guide\" \/>\n<meta property=\"og:description\" content=\"Learn how to use pre-trained models in Keras effectively. Explore VGG16, ResNet50, and more with practical examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-13T06:45:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-30T14:27:36+00:00\" \/>\n<meta name=\"author\" content=\"Olivia Parker\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Olivia Parker\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\"},\"author\":{\"name\":\"Olivia Parker\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3ff7b3da0e45ac5dbbef2502f3cea8d9\"},\"headline\":\"Keras Pre-trained Models: A Guide\",\"datePublished\":\"2024-03-13T06:45:25+00:00\",\"dateModified\":\"2025-07-30T14:27:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\"},\"wordCount\":80,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"Deep Learning\",\"Keras\",\"pre-trained models\",\"ResNet50\",\"VGG16\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\",\"name\":\"Keras Pre-trained Models: A Guide - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-13T06:45:25+00:00\",\"dateModified\":\"2025-07-30T14:27:36+00:00\",\"description\":\"Learn how to use pre-trained models in Keras effectively. Explore VGG16, ResNet50, and more with practical examples.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Keras Pre-trained Models: A Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3ff7b3da0e45ac5dbbef2502f3cea8d9\",\"name\":\"Olivia Parker\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/56c66f189ba32a6f9eb50f31a38fe774e2a725c213d4070835ccc51b8fbbc54b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/56c66f189ba32a6f9eb50f31a38fe774e2a725c213d4070835ccc51b8fbbc54b?s=96&d=mm&r=g\",\"caption\":\"Olivia Parker\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/oliviaparker\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Keras Pre-trained Models: A Guide - Blog - Silicon Cloud","description":"Learn how to use pre-trained models in Keras effectively. Explore VGG16, ResNet50, and more with practical examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/","og_locale":"en_US","og_type":"article","og_title":"Keras Pre-trained Models: A Guide","og_description":"Learn how to use pre-trained models in Keras effectively. Explore VGG16, ResNet50, and more with practical examples.","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-13T06:45:25+00:00","article_modified_time":"2025-07-30T14:27:36+00:00","author":"Olivia Parker","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Olivia Parker","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/"},"author":{"name":"Olivia Parker","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3ff7b3da0e45ac5dbbef2502f3cea8d9"},"headline":"Keras Pre-trained Models: A Guide","datePublished":"2024-03-13T06:45:25+00:00","dateModified":"2025-07-30T14:27:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/"},"wordCount":80,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["Deep Learning","Keras","pre-trained models","ResNet50","VGG16"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/","name":"Keras Pre-trained Models: A Guide - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-13T06:45:25+00:00","dateModified":"2025-07-30T14:27:36+00:00","description":"Learn how to use pre-trained models in Keras effectively. Explore VGG16, ResNet50, and more with practical examples.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-utilize-pre-trained-models-in-keras\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Keras Pre-trained Models: A Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/3ff7b3da0e45ac5dbbef2502f3cea8d9","name":"Olivia Parker","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/56c66f189ba32a6f9eb50f31a38fe774e2a725c213d4070835ccc51b8fbbc54b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/56c66f189ba32a6f9eb50f31a38fe774e2a725c213d4070835ccc51b8fbbc54b?s=96&d=mm&r=g","caption":"Olivia Parker"},"url":"https:\/\/www.silicloud.com\/blog\/author\/oliviaparker\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/3316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/11"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=3316"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/3316\/revisions"}],"predecessor-version":[{"id":147949,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/3316\/revisions\/147949"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=3316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=3316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=3316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}