3d0f9bc8d6
This reverts commit d0a6d2db31
.
26 lines
703 B
Python
26 lines
703 B
Python
import tensorflow as tf
|
|
import os
|
|
import numpy as np
|
|
|
|
|
|
def load_and_preprocess_image(file_path, target_size):
|
|
img = tf.io.read_file(file_path)
|
|
img = tf.image.decode_png(img, channels=1)
|
|
img = tf.image.resize(img, target_size)
|
|
img = img / 255.0
|
|
return img
|
|
|
|
|
|
def generatePicList(category):
|
|
path = f"./Tpics/{category}"
|
|
dircs = os.listdir(path)
|
|
result = []
|
|
for img in dircs:
|
|
image = f"{path}/" + img
|
|
target_size = (128, 128)
|
|
image_tensor = load_and_preprocess_image(image, target_size)
|
|
image_tensor = np.array(image_tensor)
|
|
image_tensor = np.expand_dims(image_tensor, axis=0)
|
|
result.append(image_tensor)
|
|
return result
|