transformers/configuration_utils.py: TypeError: Object of type ResNetConfig is not JSON serializable ( AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-detection"..))
Author: dokondr
Pull request: no

### System Info

When loading model:
AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-detection", revision="no_timm")

transformers/configuration_utils.py returns a TypeError: 
Object of type ResNetConfig is not JSON serializable

This error happens when I run in virtual environment (Win10):
torch==2.2.0
torchvision==0.17.0
transformers==4.31.0

**And also with latest versions of these libraries.**

Yet it does not happen in Conda default environment that was created long ago:
torch==2.2.0
torchvision==0.17.0
transformers==4.31.0.dev0

Today when I try:
pip install transformers==4.31.0.dev0

I get:
ERROR: No matching distribution found for transformers==4.31.0.dev0

So, it looks like 'transformers 4.31.0.dev0' no longer exist. 
How to solve then
TypeError:  Object of type ResNetConfig is not JSON serializable ?

### Detailed environment info where this error happens ###
- `transformers` version: 4.31.0
- Platform: Windows-10-10.0.19045-SP0
- Python version: 3.9.15
- Huggingface_hub version: 0.20.3
- Safetensors version: 0.4.2
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): 2.2.0+cpu (False)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>
 

### Who can help?

 @amyeroberts

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

import torch
from torchvision import transforms
from transformers import AutoModelForObjectDetection

model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-detection", revision="no_timm")

### Expected behavior

"microsoft/table-transformer-detection" model should load without errors

Comments:
Hi @dokondr, thanks for raising an issue! 

I'm unable to replicate this issue locally. Could you try installing with pip and using the most recent version of transformers? 

```
pip install -U transformers
```

> Hi @dokondr, thanks for raising an issue!
> 
> I'm unable to replicate this issue locally. Could you try installing with pip and using the most recent version of transformers?
> 
> ```
> pip install -U transformers
> ```

Hi amyeroberts!

It solved the problem, many thanks!



I was still getting the same error with, 

```python
# Load model directly
from transformers import AutoImageProcessor, AutoModelForObjectDetection

processor = AutoImageProcessor.from_pretrained("microsoft/table-transformer-structure-recognition-v1.1-all")
model = AutoModelForObjectDetection.from_pretrained("microsoft/table-transformer-structure-recognition-v1.1-all")
```
even after updating transformers to the latest version.


For now the dirty way, is to patch a custom json serialising method  - https://stackoverflow.com/a/38764817/4296772


```python
from transformers.models.resnet.configuration_resnet import ResNetConfig
from fastcore import patch_to
from json import JSONEncoder

def _default(self, obj):
    return getattr(obj.__class__, "__json__", _default.default)(obj)
_default.default = JSONEncoder().default
JSONEncoder.default = _default

@patch_to(ResNetConfig)
def __json__(self):
    return self.to_dict()
```

@sizhky Could you share your running environment: run `transformers-cli env` in the terminal and copy-paste the output? 

I'm unable to replicate with the shared snippet running on the development branch 

Sorry I have moved on to a different project. You can share more details here if the issue is still relevant