| import torch | |
| # Load old model weights | |
| old_weights = torch.load('/Users/snoamr/Documents/superCap/huggingface_model_card/FuseCap/pytorch_model.bin', map_location=torch.device('cpu')) | |
| # Prepare a dictionary to hold the new weights | |
| new_weights = {} | |
| # Loop over the items in old_weights | |
| for name, weight in old_weights.items(): | |
| # Replace the old model's layer names with the new model's layer names | |
| new_name = name.replace('vision_model.encoder.layers', 'visual_encoder.blocks') | |
| # Add the modified name and associated weight to new_weights | |
| new_weights[new_name] = weight | |
| # Save the new weights | |
| torch.save(new_weights, '/Users/snoamr/Documents/superCap/huggingface_model_card/FuseCap/pytorch_model_new.bin') | |