【发布时间】:2021-08-03 08:26:23
【问题描述】:
我想知道如何将以下代码(Tensorflow)转换为 Pytorch。 我想使用 DataLoader 但我不能。是否可以使用 DataLoader 进行转换?或者你能告诉我任何其他的转换方式吗?
非常感谢:)
from tensorflow.keras.preprocessing import image as image_utils
from tensorflow.keras.applications.vgg16 import preprocess_input
def load_and_process_image(image_path):
# Print image's original shape, for reference
print('Original image shape: ', mpimg.imread(image_path).shape)
# Load in the image with a target size of 224, 224
image = image_utils.load_img(image_path, target_size=(224, 224))
# Convert the image from a PIL format to a numpy array
image = image_utils.img_to_array(image)
# Add a dimension for number of images, in our case 1
image = image.reshape(1,224,224,3)
# Preprocess image to align with original ImageNet dataset
image = preprocess_input(image)
# Print image's shape after processing
print('Processed image shape: ', image.shape)
return image
【问题讨论】:
标签: python tensorflow pytorch