@xiao You need to know the old number of classes, then you can do this:
# Create the model and change the dimension of the output
model = torchvision.models.resnet152()
num_ftrs = model.fc.in_features
model.fc = nn.Linear(num_ftrs, old_num_classes)
# Load the pre-trained model, which has old_num_classes
model.load_state_dict(torch.load('state_dict.pth'))
# Now change the model to new_num_classes
model.fc = nn.Linear(num_ftrs, new_num_classes)
# Done