GithubHelp home page GithubHelp logo

Comments (2)

lesjie-wen avatar lesjie-wen commented on June 16, 2024 1

Thank you very much @amyeroberts, l change my code to resize images bigger than the target size and then crop to target size. And it works well.

from transformers.

amyeroberts avatar amyeroberts commented on June 16, 2024

Hi @lesjie-wen, thanks for opening this issue!

The CLIPImageProcessor defines a series of steps which will prepare raw images in the format expected by the CLIP model. It follows the preprocessing steps done for the original model.

The first resize will resize according to processor.size. You can modify the output size by passing size={"shortest_edge: x"} or size={"height": h, "width": w} when calling the image processor e.g. processor(images, size={"height": h, "width": w}).

The reason the image is (324, 324) when output, is because this is the crop size specified in the example provided:

image = self.processor.preprocess(image, return_tensors='pt', do_normalize=False, do_rescale=False, do_center_crop=True, crop_size={'height':324,'width':324})['pixel_values']

If you want a size that matches the target size you can either:

  • Change crop_size when calling the processor to match your needs i.e crop_size is the target size. This is the most common behaviour when processing images.
image = self.processor.preprocess(image, return_tensors='pt', do_normalize=False, do_rescale=False, do_center_crop=True, crop_size={'height': target_height, 'width': target_width})['pixel_values']
  • Call processor.resize on the output images
from transformers.image_processing_utils import BatchFeature

images = self.processor.preprocess(image, do_normalize=False, do_rescale=False, do_center_crop=True, crop_size={'height': target_height, 'width': target_width})['pixel_values']
images = [self.processor.resize(image, size={"height": target_height, "width": target_width}) for image in images]
images = BatchFeature({"pixel_values": images}, tensor_type="pt")

from transformers.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.