# Ensemble Adversarial Inception ResNet v2

**Inception-ResNet-v2** is a convolutional neural architecture that builds on the Inception family of architectures but incorporates [residual connections](https://paperswithcode.com/method/residual-connection) (replacing the filter concatenation stage of the Inception architecture).

This particular model was trained for study of adversarial examples (adversarial training).

The weights from this model were ported from [Tensorflow/Models](https://github.com/tensorflow/models).

## How do I use this model on an image?
To load a pretrained model:

```python
import timm
model = timm.create_model('ens_adv_inception_resnet_v2', pretrained=True)
model.eval()
```

To load and preprocess the image:
```python 
import urllib
from PIL import Image
from timm.data import resolve_data_config
from timm.data.transforms_factory import create_transform

config = resolve_data_config({}, model=model)
transform = create_transform(**config)

url, filename = ("https://github.com/pytorch/hub/raw/master/images/dog.jpg", "dog.jpg")
urllib.request.urlretrieve(url, filename)
img = Image.open(filename).convert('RGB')
tensor = transform(img).unsqueeze(0) # transform and add batch dimension
```

To get the model predictions:
```python
import torch
with torch.no_grad():
    out = model(tensor)
probabilities = torch.nn.functional.softmax(out[0], dim=0)
print(probabilities.shape)
# prints: torch.Size([1000])
```

To get the top-5 predictions class names:
```python
# Get imagenet class mappings
url, filename = ("https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt", "imagenet_classes.txt")
urllib.request.urlretrieve(url, filename) 
with open("imagenet_classes.txt", "r") as f:
    categories = [s.strip() for s in f.readlines()]
The context provides a clear and direct answer to the question. It specifies that the convolutional neural architecture incorporating residual connections and used for adversarial training is the "Inception-ResNet-v2." The context explicitly mentions this architecture and its purpose, making the question unambiguously answerable.


This question is quite useful for machine learning developers working with NLP applications in the Hugging Face ecosystem. It touches on advanced concepts such as convolutional neural architectures, residual connections, and adversarial training, which are relevant for developing robust and effective models. Understanding these concepts can help developers improve model performance and stability, which is crucial in NLP tasks.


The question is asking for the name of a specific convolutional neural architecture that incorporates residual connections and is used for adversarial training. This question is context-independent because it provides enough information for someone familiar with neural network architectures to understand what is being asked. The mention of "residual connections" and "adversarial training" are specific enough to guide someone with the appropriate background to the correct answer without needing additional context.

