|
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() |