-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
json_path = "./data/COCO/captions_val2014.json"
json_labels = json.load(open(json_path,'r'))
annotations = json_labels["annotations"]
images = json_labels["images"]
images_path = "./data/COCO/image/"
image_dict = dict()
for image in images:
image_dict[image["file_name"]] = image["id"]
with open("./data/COCO/coco_test.txt") as image_names_data:
image_names = image_names_data.readlines()
image_features = []
for image_info in image_names:
image_file = image_info.split('\n')[0]
image_id = image_dict[image_file]
image_path = images_path + image_file
ori_image = Image.open(image_path)
image = preprocess(ori_image).unsqueeze(0).to(device)
image_feature = clip_model.encode_image(image)
image_features.append(image_feature)
image_features = torch.cat(image_features)
torch.save(image_features, "./feature/COCO/image_features.pkl")
因为不懂这个coco_test.txt文件,这段代码没有看明白,如果是读取图片的话,应该只需要拼接file_name与image_folder_name吧。
Metadata
Metadata
Assignees
Labels
No labels