Open opeleasap opened 9 months ago
this is the code
import os import numpy as np import matplotlib.pyplot as plt from tensorflow.keras.preprocessing.image import ImageDataGenerator, load_img, img_to_array
input_folder = r'C:\Users\Admini\Desktop\Image Classification\Input_folder' # Change this to the path of your dataset output_folder = r'C:\Users\Admini\Desktop\Image Classification\Output1' # Change this to the desired output path
datagen = ImageDataGenerator( rotation_range=40, width_shift_range=0.2, height_shift_range=0.2, shear_range=0.2, zoom_range=0.2, horizontal_flip=True, fill_mode='nearest' )
for subfolder in os.listdir(input_folder): subfolder_path = os.path.join(input_folder, subfolder)
# Create output folder for the current subfolder
output_subfolder = os.path.join(output_folder, subfolder)
os.makedirs(output_subfolder, exist_ok=True)
# Loop through images in the current subfolder
for image_file in os.listdir(subfolder_path):
image_path = os.path.join(subfolder_path, image_file)
# Load the image
img = load_img(image_path, target_size=(224, 224))
img_array = img_to_array(img)
img_array = np.expand_dims(img_array, axis=0)
# Generate augmented images
augmented_images = datagen.flow(img_array, batch_size=1)
# Save augmented images to the output folder
for i in range(5): # Save 5 augmented images for each original image
augmented_img = next(augmented_images)[0]
output_file = os.path.join(output_subfolder, f"augmented_{i}_{image_file}")
plt.imsave(output_file, augmented_img.astype(np.uint8))
print("Augmentation and image generation completed.")
there's an error after running the code. The error says that i sholud downgrade the version of the protobuf in order to runthe codes but yet still same error. TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: