Shuffle images in directories with Jupyter-notebook.
shuffleimage.ipynb
#Code to shuffle and save images in a folder
import os
from random import shuffle
from glob import glob
from shutil import copy
data_dir_path = "Paste the absolute path of the directory containing the image here" #Folder path containing the image you want to shuffle
base_path = os.path.join(data_dir_path ,"*.png ")
#Create a directory to save shuffled images
make_dir_path = data_dir_path +"_shuffle" #Destination directory path
os.makedirs(make_dir_path, exist_ok=True)
#Shuffle the images in the folder and save them in the destination directory
files = sorted(glob(base_path))
shuffle(files)
n = 1 #File name start number
#Save to the directory where the images were created with serial numbers
for file in files:
copy(file,'{}/{}.jpg'.format(make_dir_path,str(n).zfill(5)))
n += 1
print("Destination directory%Create r"%os.path.basename(make_dir_path))
print("Number of shuffled images: %d Save completed\n"%(int(len(files))+1))
Get file name / folder name / extension from path string in Python, combine | note.nkmk.me python relative path How to get the location of the parent directory-Beginner introductory sample [Python] Copy, move, delete folders and files (shutil module) | Hibiki Programming Notes [Python] Python counting the number of files in the current directory
Since this is my first post, I plan to rewrite it ^^