MICCAI21_MMQ icon indicating copy to clipboard operation
MICCAI21_MMQ copied to clipboard

could you give the code for extract ae and maml featrue, we want to extract feature on own dataset

Open tangxiaochu123230 opened this issue 2 years ago • 8 comments

tangxiaochu123230 avatar Aug 11 '22 09:08 tangxiaochu123230

Hi! I regret not being able to provide feature extraction code because our proposal does not use any feature as input. We simply resized all the images to the suitable size (84x84 for maml and 128x128 for ae) and saved them as one file. If you want to work with your dataset, please resize them and use the pre-trained models we provided to extract the features you want.

xuanbinh-nguyen96 avatar Aug 12 '22 06:08 xuanbinh-nguyen96

do not you subtract mean and divide std. I cannot preduce your result

tangxiaochu123230 avatar Aug 12 '22 07:08 tangxiaochu123230

simply you open the image with the PIL library, resize and convert to the torch tensor, then divide them directly by 255.

xuanbinh-nguyen96 avatar Aug 12 '22 08:08 xuanbinh-nguyen96

from PIL import Image
img_size = [128, 128]
transform = transforms.Compose([lambda x: Image.open(x).convert('L'),
                                         transforms.Resize(img_size),
                                         transforms.ToTensor(),
                                lambda x: x/255.])

xuanbinh-nguyen96 avatar Aug 12 '22 08:08 xuanbinh-nguyen96

thanks you very much [code.]

微信图片_20220812165234 687189170287429743

on rad datset,we get very different feature

tangxiaochu123230 avatar Aug 12 '22 08:08 tangxiaochu123230

if i do not use lambda x: x/255..it may be more closer

tangxiaochu123230 avatar Aug 12 '22 09:08 tangxiaochu123230

I double checked and noticed there is a bit of a mistake here. Very sorry for this. For our proposed dataset - PathVQA:

  • for maml (size 84x84), run:
    • Step 1 (resize all image by PIL with LANCZOS), run:
import os

from PIL import Image

path_to_images = 'pathVQA/images'

all_images = []

# Resize images
for r, d, f in os.walk(path_to_images):
    for file in f:
        if '.jpg' in file:
            all_images.append(os.path.join(r, file))

for i, image_file in enumerate(all_images):
    im = Image.open(image_file)
    im = im.resize((84, 84), resample=Image.LANCZOS)
    im.save(image_file)
    if i % 500 == 0:
        print(i)

Step 2, using the bellow "transform" on the images processed in step 1.

img_size = [84, 84]
transform = transforms.Compose([lambda x: Image.open(x).convert('RGB'),
                                         transforms.Resize(img_size),
                                         transforms.ToTensor(),
                                         transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
                                         ])
  • for ae (size 128x128), run:
    • Step 1 (resize all image by PIL with LANCZOS), run:
import os

from PIL import Image

path_to_images = 'pathVQA/images'

all_images = []

# Resize images
for r, d, f in os.walk(path_to_images):
    for file in f:
        if '.jpg' in file:
            all_images.append(os.path.join(r, file))

for i, image_file in enumerate(all_images):
    im = Image.open(image_file)
    im = im.resize((128, 128), resample=Image.LANCZOS)
    im.save(image_file)
    if i % 500 == 0:
        print(i)

Step 2, using the bellow "transform" on the images processed in step 1.

img_size = [128, 128]
transform = transforms.Compose([lambda x: Image.open(x).convert('L'),
                                         transforms.Resize(img_size),
                                         transforms.ToTensor(),
                                         transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
                                         ])

For RAD dataset, we use dataset from https://github.com/aioz-ai/MICCAI19-MedVQA

xuanbinh-nguyen96 avatar Aug 12 '22 10:08 xuanbinh-nguyen96

great,thank you very much for you patience. I want to implemet vqa, if I can skip MMQ Progress and finetune VQA Progress based on model train on RAD dataset

tangxiaochu123230 avatar Aug 12 '22 11:08 tangxiaochu123230