pytorch dataset:mimix-cxr transformers image-to-text
---
tags:
- image-to-text
datasets:
- mimix-cxr
---

Code available on [this GitHub repo](https://github.com/flych3r/xrrg).

```bash
$ pip install git+https://github.com/flych3r/xrrg.git
```
```python
>>> import torch
>>> from imageio import imread
>>> from transformers import AutoFeatureExtractor, AutoTokenizer
>>> from vxr import XrayReportGeneration

>>> image = imread('https://huggingface.co/spaces/flych3r/xrrg-demo/resolve/main/xray-1.jpg')
>>> tokenizer = AutoTokenizer.from_pretrained('flych3r/xrrg')
>>> feature_extractor = AutoFeatureExtractor.from_pretrained('flych3r/xrrg')
>>> model = XrayReportGeneration.from_pretrained('flych3r/xrrg')

>>> with torch.no_grad():
>>>     inputs = feature_extractor(image, return_tensors="pt")
>>>     pixel_values = inputs.pixel_values
>>>     outputs = model.generate(pixel_values, max_length=100, num_beams=3, early_stopping=True)

>>> text = tokenizer.decode(outputs[0], skip_special_tokens=True)
>>> print(text)
"PA and lateral views of the chest provided. There is no focal consolidation, effusion, or pneumothorax. 
The cardiomediastinal silhouette is normal. Imaged osseous structures are intact. No free air below the right hemidiaphragm is seen."

```