Close Menu
    Trending
    • 4 Reminders Every Mompreneur Needs This Mother’s Day
    • การวิเคราะห์ผลการศึกษาพื้นคอนกรีตดาดฟ้าที่มีความชื้นสูง | by MATLAB BKK | May, 2025
    • Web App Automation using custom trained YOLOv8 model and Playwright | by Shyamchandar | May, 2025
    • Warren Buffett Doesn’t Believe in 10,000 Hours of Practice
    • Simplify Trading: Build a Multi-Timeframe Dashboard in Pine Script (Without Chart-Hopping) | by Betashorts | May, 2025
    • Microsoft Prohibits Employees From Using DeepSeek AI App
    • Optimasi Model Machine Learning. Optimalkan model machine learning… | by Yasun Studio | May, 2025
    • Inside Emptio Home Decor’s Shopkeeping Success
    Finance StarGate
    • Home
    • Artificial Intelligence
    • AI Technology
    • Data Science
    • Machine Learning
    • Finance
    • Passive Income
    Finance StarGate
    Home»Machine Learning»Food Image Classifier. In this tutorial, I’ll show how to… | by Amruta | Mar, 2025
    Machine Learning

    Food Image Classifier. In this tutorial, I’ll show how to… | by Amruta | Mar, 2025

    FinanceStarGateBy FinanceStarGateMarch 21, 2025No Comments2 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Telegram Email
    Share
    Facebook Twitter LinkedIn Pinterest Email


    On this tutorial, I’ll present how you can construct a meals picture classifier, utilizing switch studying.. The objective is to take meals photos as enter, and routinely determine what dish it’s.. e.g. pizza, noodles, burger, sandwich and many others …

    Step 1: First, create a listing say ‘food-images’ or ‘food-samples’. On this listing, create a sub-folder for every class: {pizza, noodles, burger, soup, sandwich ..} and many others. Every sub-folder ought to comprise photos (jpg, png, jpeg) for that class.

    Step 2: Now, load this knowledge into python. For this, we use operate ‘image_dataset_from_directory’ from keras.utils.

    train_data, valid_data = keras.utils.image_dataset_from_directory(
    "food-images",
    labels = "inferred",
    class_names=('burger', 'cake', 'juice', 'noodles', 'pizza'),
    image_size=(224,224),
    batch_size=32,
    validation_split=0.2,
    subset="each",
    seed=1337)

    Step 3: Load pre-trained mannequin weights. Word, these fashions are already educated on very giant scale datasets, so even when our new picture pattern for meals photos is comparatively very small (say few 100 to 1000 photos per class), our classifier can nonetheless obtain first rate accuracy. That’s the great thing about switch studying, the place we make the most of mannequin educated on giant dataset (say to determine cats, canines, horse, airplane, automotive, bus from picture) and modify or customise it for a brand new activity.

    # load pre-trained mannequin
    from keras.purposes.resnet50 import ResNet50
    from keras.purposes.resnet50 import preprocess_input

    base_model = ResNet50(weights='imagenet', include_top=False)
    base_model.trainable = False

    Step 4: Now, we add some new layers on high of this base_model, and solely prepare these new layers on our meals picture dataset.

    # construct new mannequin on high of pre-trained mannequin

    from keras import layers

    num_classes = 5

    # add new layers to base_model
    mannequin = keras.Sequential([
    base_model,
    layers.GlobalAveragePooling2D(),
    layers.Dense(64, activation='relu'),
    layers.Dense(num_classes, activation='softmax')
    ])

    Step 5: Now, we simply compile our mannequin as ordinary, and prepare it on new meals picture dataset. Word, in step 3, we set base_model.trainable as False, so our pre-trained mannequin just isn’t be altered throughout coaching. Solely the brand new layers added on high are educated on customized dataset.

    mannequin.compile(optimizer='adam', loss='sparse_categorical_crossentropy')
    mannequin.match(train_data, validation_data=valid_data, epochs=3)

    Step 6: Let’s attempt our food-image classifier on few pattern take a look at photos.

    # attempt mannequin on new pattern picture
    from matplotlib import picture

    plt.determine(figsize=(7,7))

    for okay in vary(12):
    plt.subplot(3, 4, okay+1)
    test_img_file = str(okay+1) + ".jpg"
    test_img = picture.imread(test_img_file)
    plt.imshow(test_img)

    y = mannequin.predict(np.array([test_img]))
    label = class_labels[np.argmax(y[0])]
    plt.xlabel(label)
    plt.xticks([])
    plt.yticks([])

    meals picture classification

    Yumm, isn’t it? For extra yummy code examples, take a look at my git repo at : https://github.com/pamruta/Keras



    Source link

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous Article@HPCpodcast: Live from GTC 2025, Among the Crowds for the New AI Compute Landscape
    Next Article Google’s Data Science Agent: Can It Really Do Your Job?
    FinanceStarGate

    Related Posts

    Machine Learning

    การวิเคราะห์ผลการศึกษาพื้นคอนกรีตดาดฟ้าที่มีความชื้นสูง | by MATLAB BKK | May, 2025

    May 11, 2025
    Machine Learning

    Web App Automation using custom trained YOLOv8 model and Playwright | by Shyamchandar | May, 2025

    May 11, 2025
    Machine Learning

    Simplify Trading: Build a Multi-Timeframe Dashboard in Pine Script (Without Chart-Hopping) | by Betashorts | May, 2025

    May 11, 2025
    Add A Comment

    Comments are closed.

    Top Posts

    How To Survive The Most Dangerous Time After Buying A House

    April 14, 2025

    The Growing Demand for Web3 Professionals & How Certifications Can Help

    March 25, 2025

    Smart Hiring Tactics From a James Beard Award Nominee

    April 27, 2025

    Data-Driven March Madness Predictions | Towards Data Science

    March 26, 2025

    I Use the 6-Week Sprint Method For Better Product Development — and More. Here’s Why You Need It, Too.

    February 12, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    Most Popular

    We Need a Fourth Law of Robotics in the Age of AI

    May 7, 2025

    Now’s Your Chance to Get a MacBook Air for Just $200

    May 1, 2025

    Your Job Search Doesn’t Have to Be a Full-Time Job

    April 5, 2025
    Our Picks

    Exploring IMDB Movies Dataset: Key Insights and Marketing Research Implications | by Pourushporwal | Feb, 2025

    February 17, 2025

    The Timeless Appeal of Watches. | by Sifra Sifra | Mar, 2025

    March 9, 2025

    AI Agent Developer: A Journey Through Code, Creativity, and Curiosity | by Talha Nazar | Feb, 2025

    February 19, 2025
    Categories
    • AI Technology
    • Artificial Intelligence
    • Data Science
    • Finance
    • Machine Learning
    • Passive Income
    • Privacy Policy
    • Disclaimer
    • Terms and Conditions
    • About us
    • Contact us
    Copyright © 2025 Financestargate.com All Rights Reserved.

    Type above and press Enter to search. Press Esc to cancel.