-
Notifications
You must be signed in to change notification settings - Fork 0
/
sfaaaaaa.txt
40 lines (40 loc) · 1.91 KB
/
sfaaaaaa.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def preprocess_and_save_images(image_list, save_dir):
for image_path in image_list:
try:
img = Image.open(image_path)
# Apply your preprocessing steps
img_vertical_flipped = vertical_flip(img)
img_horizontal_flipped = horizontal_flip(img)
img_clipped = clip_image(img, 200, 200)
img_normalized = normalize_image(img)
# Save the preprocessed images
base_name = os.path.basename(image_path).split('.')[0]
img_vertical_flipped.save(os.path.join(save_dir, f"{base_name}_vertical_flipped.png"))
img_horizontal_flipped.save(os.path.join(save_dir, f"{base_name}_horizontal_flipped.png"))
img_clipped.save(os.path.join(save_dir, f"{base_name}_clipped.png"))
# If you want to save the normalized image, you'll need to convert it back to a PIL Image
img_normalized_pil = Image.fromarray((img_normalized * 255).astype('uint8'))
img_normalized_pil.save(os.path.join(save_dir, f"{base_name}_normalized.png"))
except Exception as e:
print(f'Error processing image {image_path}. Error: {e}')
# Get all image paths from each category
all_category0_images = [os.path.join(category0_dir, fname) for fname in os.listdir(category0_dir)]
all_category1_images = [os.path.join(category1_dir, fname) for fname in os.listdir(category1_dir)]
# Preprocess and save images for each category
preprocess_and_save_images(all_category0_images, category0_dir)
preprocess_and_save_images(all_category1_images, category1_dir)
# Split the data into training, validation, and test sets
category0_train, category0_val, category0_test = split_data(category0_dir)
category1_train, category1_val, category1_test = split_data(category1_dir)
File "/tmp/ipykernel_94/3807105616.py", line 7
img_vertical_flipped = vertical_flip(img)
^
SyntaxError: invalid syntax