How to classify the images in the dataset from roboflow

I want to use the dataset from roboflow for one of my projects. I downloaded the dataset but the files are not grouped based on the classes. How can I classify the images based on classes.

If your images are not grouped by class, you can label them in Roboflow. Here’s how you can do it:

  1. Add your images to Roboflow.
  2. Assign a user in your account to label them. This could be you or someone else in your team.
  3. Labeling single-label classification data can be quick if you only have a few classes of data. If you have a large dataset, consider labeling 50 to 100 images, then using Roboflow Train to enable model assisted labeling. Model assisted labeling can help speed up labeling time by automatically applying best estimate labels to your images.

Here’s an example of how you can download a dataset from Roboflow:

from roboflow import Roboflow

rf = Roboflow.login()

project = rf.workspace("popular-benchmarks").project("mit-indoor-scene-recognition")
dataset = project.version(5).download("folder")

After downloading, you can create a dictionary that maps all of the file names to the name of the folder they are in so that you know the label for each image:

import os

cwd = os.getcwd()

ROOT_DIR = os.path.join(cwd, "MIT-Indoor-Scene-Recognition-5/train")

labels = {}

for folder in os.listdir(ROOT_DIR):
    for file in os.listdir(os.path.join(ROOT_DIR, folder)):
        if file.endswith(".jpg"):
            full_name = os.path.join(ROOT_DIR, folder, file)
            labels[full_name] = folder

files = labels.keys()

This way, you can classify your images based on classes.

Sources:


Hi! I’m Roboflow’s AI powered bot. This is an automated response powered using AI with knowledge from our docs, blog, and forum. If this solves your issue, please mark it as the solution using the checkbox icon. If this doesn’t solve your issue, please follow up with what you’ve tried/why, and the community will continue to chime in as usual.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.