# How to check if image exists at image url?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-check-if-image-exists-at-image-url%2F20690%3E%5C
**Category:** 🤗Transformers\
**Created:** [July 21, 2022, 3:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-check-if-image-exists-at-image-url%2F20690 "2022-07-21T15:54:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheNoob3131](https://avatars.discourse-cdn.com/v4/letter/t/7feea3/32.png) [@TheNoob3131](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FTheNoob3131)%5C
**Post date:** [July 21, 2022, 3:54pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-check-if-image-exists-at-image-url%2F20690%2F1 "2022-07-21T15:54:53Z")

</div>

So every time I try to train my model (google/vit-base-patch16-224-in21k) on my dataset for image classification, it always gives a FileNotFound error (see below).

 ![image](https://us1.discourse-cdn.com/hellohellohello/original/2X/a/a8e900a1bf6b8b25b359bee93923448c8947e528.png)

Is there a way to go through the entire ‘Photos’ column and delete/identify whichever rows have an image url that doesn’t exist? Is there a python/huggingface function for that?

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [July 22, 2022, 7:54am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-check-if-image-exists-at-image-url%2F20690%2F2 "2022-07-22T07:54:07Z")

</div>

You can simply skip it as follows:

```auto
def to_pillow(examples):
    urls = examples['Photo']
    images = []
    for url in urls:
      try:
          image = Image.open(requests.get(url, stream=True).raw)
          images.append(image)
      except:
          pass
    
    examples['image'] = images
    
    return examples

dataset = load_dataset("TheNoob3131/mosquito-data")
dataset = dataset.map(to_pillow, batched=True)

```
