Visualize your Dataset in a 10x10 matrix using Python Packages.
- vidyakamath1004
- Feb 22, 2023
- 1 min read
import the following packages in any environment of your choice. I use a virtual environment in the anaconda Spyder IDE.
import xml.etree.ElementTree as ET
import glob
import matplotlib.pyplot as pltInitialize the following variables .
path= os.path.abspath("YOUR_DATASET_PATH")
row=10
col=10
c=0
rand= [ 500, 600, ... , ... ]
{100 (10x10) RANDOM VALUES THAT ARE WITHIN THE NUMBER OF IMAGES IN YOUR DATSET} The dataset folder in my case contains all the images in .jpg format, along with the annotations in .xml format.
Extract all the image paths and store in a variable.
img_paths= glob.glob(f"{path}/*jpg)
imgs=[image_path.split('/')[-1] for image_path in img_paths
imgs=sorted(imgs) Now you can extract the paths from the imgs and display the images in a matrix form using matplotlib.
f, ax =plt.subplots(row, col, squeeze=True)
for i in range (row):
for j in range (col):
ax[i, j].imshow(plt.imread(imgs[rand[c]]))
ax[i, j].grid(False)
ax[i, j].axis("off")
c=c+1You are good to go.. If you are using Spyder IDE, check for a plot under the ''Plots' tab (next to 'Help' tab) available on top right corner.




Comments