Upload 9 files
Browse files- .gitignore +6 -0
- README.md +5 -5
- app.py +57 -0
- car_bike.jpg +0 -0
- chair.jpg +0 -0
- classlabel.txt +12 -0
- human.jpg +0 -0
- requirements.txt +22 -0
.gitignore
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flagged/
|
| 2 |
+
*.pt
|
| 3 |
+
*.png
|
| 4 |
+
*.mp4
|
| 5 |
+
*.mkv
|
| 6 |
+
gradio_cached_examples/
|
README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Low Light Image Recognition
|
| 3 |
+
emoji: 🐢
|
| 4 |
+
colorFrom: purple
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.40.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import cv2
|
| 3 |
+
import requests
|
| 4 |
+
import gdown
|
| 5 |
+
import tensorflow as tf
|
| 6 |
+
from tensorflow import keras
|
| 7 |
+
#from custom_model import ImageClassifier
|
| 8 |
+
import numpy as np
|
| 9 |
+
#from tensorflow.keras import models
|
| 10 |
+
#from keras.layers import Dense, Activation, Flatten,Dropout, Conv2D, BatchNormalization, MaxPooling2D
|
| 11 |
+
|
| 12 |
+
from keras.models import load_model
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
path = [['car_bike.jpg'], ['human.jpg'], ['chair.jpg']]
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
url = 'https://drive.google.com/file/d/1PCb6MTqelw7Tk0iCxo5Ef70zYwEpsI4Y/view?usp=sharing'
|
| 22 |
+
output_path = 'classlabel.txt'
|
| 23 |
+
gdown.download(url, output_path, quiet=False,fuzzy=True)
|
| 24 |
+
|
| 25 |
+
with open(output_path,'r') as file:
|
| 26 |
+
LABELS = [x.strip() for x in file.readlines()]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
num_classes = 12
|
| 30 |
+
IMG_SIZE = 124
|
| 31 |
+
|
| 32 |
+
def _normalize_img(img):
|
| 33 |
+
img = tf.cast(img, tf.float32)/255. # All images will be rescaled by 1./255
|
| 34 |
+
img = tf.image.resize(img, (IMG_SIZE, IMG_SIZE), method= 'bilinear')
|
| 35 |
+
return (img)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
model = load_model("model.h5")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def predict_fn(img):
|
| 43 |
+
img = img.convert('RGB')
|
| 44 |
+
img_data = _normalize_img(img)
|
| 45 |
+
x = np.array(img_data)
|
| 46 |
+
x = np.expand_dims(x, axis=0)
|
| 47 |
+
temp = model.predict(x)
|
| 48 |
+
|
| 49 |
+
idx = np.argsort(np.squeeze(temp))[::-1]
|
| 50 |
+
top3_value = np.asarray([temp[0][i] for i in idx[0:3]])
|
| 51 |
+
top3_idx = idx[0:3]
|
| 52 |
+
|
| 53 |
+
return {LABELS[i]:str(v) for i,v in zip(top3_idx,top3_value)}
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
gr.Interface(predict_fn, gr.inputs.Image(type='pil'), outputs='label', examples=path,).launch()
|
car_bike.jpg
ADDED
|
chair.jpg
ADDED
|
classlabel.txt
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Bicycle
|
| 2 |
+
Boat
|
| 3 |
+
Bottle
|
| 4 |
+
Bus
|
| 5 |
+
Car
|
| 6 |
+
Cat
|
| 7 |
+
Chair
|
| 8 |
+
Cup
|
| 9 |
+
Dog
|
| 10 |
+
Motorbike
|
| 11 |
+
People
|
| 12 |
+
Table
|
human.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Base ----------------------------------------
|
| 2 |
+
matplotlib>=3.2.2
|
| 3 |
+
numpy>=1.21.6
|
| 4 |
+
opencv-python>=4.6.0
|
| 5 |
+
Pillow>=7.1.2
|
| 6 |
+
PyYAML>=5.3.1
|
| 7 |
+
requests>=2.23.0
|
| 8 |
+
scipy>=1.4.1
|
| 9 |
+
gradio>=3.36.1
|
| 10 |
+
tensorflow==2.12.0
|
| 11 |
+
tensorflow-datasets==4.9.2
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Plotting ------------------------------------
|
| 15 |
+
pandas>=1.1.4
|
| 16 |
+
seaborn>=0.11.0
|
| 17 |
+
gdown
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
# Extras --------------------------------------
|
| 21 |
+
psutil # system utilization
|
| 22 |
+
thop>=0.1.1 # FLOPs computation
|