Ahsen Khaliq commited on
Commit
5066aaa
1 Parent(s): 63fafe6

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tensorflow as tf
3
+ import numpy as np
4
+ import pandas as pd
5
+ import matplotlib.pyplot as plt
6
+ from tensorflow import keras
7
+
8
+ import requests
9
+ import PIL
10
+ import io
11
+ import matplotlib.pyplot as plt
12
+
13
+ def download_image(url):
14
+ resp = requests.get(url)
15
+ resp.raise_for_status()
16
+ return PIL.Image.open(io.BytesIO(resp.content))
17
+
18
+ from keras_cv_attention_models import convnext
19
+
20
+ mm = convnext.ConvNeXtBase()
21
+
22
+ downloaded_image = download_image(
23
+ "https://www.popsci.com/uploads/2021/09/21/Tortoise-on-ground-surrounded-by-plants.jpg?auto=webp"
24
+ )
25
+
26
+ downloaded_image_np = np.array(downloaded_image)
27
+
28
+ img = downloaded_image_np
29
+ imm = keras.applications.imagenet_utils.preprocess_input(img, mode='torch')
30
+ image_input = tf.expand_dims(tf.image.resize(imm, mm.input_shape[1:3]), 0)
31
+
32
+ pred = mm(image_input)
33
+ pred_np = pred.numpy()