showlab / Image2Paragraph

[A toolbox for fun.] Transform Image into Unique Paragraph with ChatGPT, BLIP2, OFA, GRIT, Segment Anything, ControlNet.
Apache License 2.0
789 stars 53 forks source link

Input type and weight type should be the same #12

Closed QinghongLin closed 1 year ago

QinghongLin commented 1 year ago

I follow the instruction and run python main.py but meet such an error:

image
QinghongLin commented 1 year ago

just replace the blip2_model.py line 12-line 30 to this. then can work.


    def initialize_model(self):
        if self.device == 'cpu':
            self.data_type = torch.float32
        else:
            self.data_type = torch.float16
        # processor = Blip2Processor.from_pretrained("Salesforce/blip2-opt-2.7b")
        # model = Blip2ForConditionalGeneration.from_pretrained(
        #     "Salesforce/blip2-opt-2.7b", torch_dtype=self.data_type
        # )
        # for gpu with small memory
        processor = BlipProcessor.from_pretrained("Salesforce/blip-image-captioning-base")
        model = BlipForConditionalGeneration.from_pretrained("Salesforce/blip-image-captioning-base")
        model.to(self.device)
        if self.device != 'cpu':
            model.half()
        return processor, model