File size: 835 Bytes
5066aaa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import tensorflow as tf
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from tensorflow import keras

import requests
import PIL
import io
import matplotlib.pyplot as plt

def download_image(url):
    resp = requests.get(url)
    resp.raise_for_status()
    return PIL.Image.open(io.BytesIO(resp.content))

from keras_cv_attention_models import convnext

mm = convnext.ConvNeXtBase()

downloaded_image = download_image(
    "https://www.popsci.com/uploads/2021/09/21/Tortoise-on-ground-surrounded-by-plants.jpg?auto=webp"
    )

downloaded_image_np = np.array(downloaded_image)

img = downloaded_image_np
imm = keras.applications.imagenet_utils.preprocess_input(img, mode='torch')
image_input = tf.expand_dims(tf.image.resize(imm, mm.input_shape[1:3]), 0)

pred = mm(image_input)
pred_np = pred.numpy()