import os
import keras
from keras.preprocessing import image
from keras.applications.imagenet_utils import decode_predictions, preprocess_input
from keras.models import Model
model = keras.applications.VGG16(weights='imagenet', include_top=True)
feat_extractor = Model(inputs=model.input, outputs=model.get_layer("fc2").output)
import numpy as np
import matplotlib.pyplot as plt
def load_image(path):
img = image.load_img(path, target_size=model.input_shape[1:3])
x = image.img_to_array(img)
x = np.expand_dims(x, axis=0)
x = preprocess_input(x)
return img, x
images_path = 'D:/code/python/data/101_ObjectCategories'
image_extensions = ['.jpg', '.png', '.jpeg'] # case-insensitive (upper/lower doesn't matter)
max_num_images = 10000
import random
images = [os.path.join(dp, f) for dp, dn, filenames
使用t-SNE可视化的代码记录
最新推荐文章于 2022-09-24 22:25:54 发布