google-colaboratoryobject-detectiondetectionpytorch-lightning

DeTr Saving and Exporting Custom Trained Model


files i downloaded after training the model :

  1. config.json
  2. model.safetensors
  3. logs > hparams/yaml ( empty file )
  4. logs > events.out.tfevents.1707970167.d4c7dd713d7a.235.0
  5. logs > checkpoint > output.ckpt

The following code was used to save :

MODEL_PATH = 'custom-model'
model.model.save_pretrained(MODEL_PATH)

The custom-model folder contains the file number 1&2 (config.json and model.safetensors)

when i try to load the model which was custom-trained by me in the same session of google colab it works fine , but when the same folder is copied to another colab notebook and tried to execute , it throws this error :

/data does not appear to have a file named preprocessor_config.json

this code is used to load the custom model

CHECKPOINT = 'models/data'

image_processor = DetrImageProcessor.from_pretrained(CHECKPOINT)
model = DetrForObjectDetection.from_pretrained(CHECKPOINT)

Solution

  • okay so the problem was in this line

    image_processor = DetrImageProcessor.from_pretrained(CHECKPOINT)
    

    replaced the CHECKPOINT with 'facebook/detr-resnet-50'

    complete code for loading the model

    CHECKPOINT = 'models/data'
    
    image_processor = DetrImageProcessor.from_pretrained('facebook/detr-resnet-50') 
    model = DetrForObjectDetection.from_pretrained(CHECKPOINT)
    

    and the models/data contains all the files ( 1-5 ) mentioned in the above question