-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e283f47
commit 88bb805
Showing
8 changed files
with
212 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ lxml | |
cython | ||
tensorflowjs | ||
imutils | ||
opencv-contrib-python | ||
opencv-contrib-python | ||
termcolor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# import the necessary packages | ||
from tracemalloc import start | ||
from tensorflow.keras.preprocessing.image import img_to_array | ||
from tensorflow.keras.preprocessing.image import load_img | ||
from tensorflow.keras.models import load_model | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import mimetypes | ||
import argparse | ||
import imutils | ||
import cv2 | ||
import os | ||
|
||
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" | ||
|
||
# font | ||
font = cv2.FONT_HERSHEY_SIMPLEX | ||
# Blue color in BGR | ||
color = (0,0,255) | ||
# Line thickness of 2 px | ||
thickness = 3 | ||
# org | ||
org = (50, 50) | ||
# fontScale | ||
fontScale = 1 | ||
|
||
# construct the argument parser and parse the arguments | ||
ap = argparse.ArgumentParser() | ||
ap.add_argument("-i", "--input", required=True, | ||
help="path to input image/text file of image filenames") | ||
args = vars(ap.parse_args()) | ||
|
||
def get_key(my_dict, val): | ||
for key, value in my_dict.items(): | ||
if val == value: | ||
return key | ||
|
||
return "Key doesn't exist" | ||
|
||
# determine the input file type, but assume that we're working with | ||
# single input image | ||
filetype = mimetypes.guess_type(args["input"])[0] | ||
imagePaths = [args["input"]] | ||
# if the file type is a text file, then we need to process *multiple* | ||
# images | ||
if "text/plain" == filetype: | ||
# load the filenames in our testing file and initialize our list | ||
# of image paths | ||
filenames = open(args["input"]).read().strip().split("\n") | ||
imagePaths = [] | ||
# loop over the filenames | ||
for f in filenames: | ||
# construct the full path to the image filename and then | ||
# update our image paths list | ||
p = os.path.sep.join(["../data/processed/Obj_Det/images", f]) | ||
imagePaths.append(p) | ||
|
||
# load our trained bounding box regressor from disk | ||
print("[INFO] loading object detector...") | ||
model = load_model("./artifacts/border_box/detector.h5") | ||
print("[INFO] loaded object detector...") | ||
|
||
print("-"*50) | ||
|
||
print("[INFO] loading intensity estimator model...") | ||
in_model = load_model('./artifacts/in_estimator/in_estimator.h5') | ||
print("[INFO] loaded intensity estimator model...") | ||
|
||
# loop over the images that we'll be testing using our bounding box | ||
# regression model | ||
p = 1 | ||
for imagePath in imagePaths: | ||
# load the input image (in Keras format) from disk and preprocess | ||
# it, scaling the pixel intensities to the range [0, 1] | ||
image = load_img(imagePath, target_size=(224, 224)) | ||
image = img_to_array(image) / 255.0 | ||
image = np.expand_dims(image, axis=0) | ||
# make bounding box predictions on the input image | ||
preds = model.predict(image)[0] | ||
(startX, startY, endX, endY) = preds | ||
# load the input image (in OpenCV format), resize it such that it | ||
# fits on our screen, and grab its dimensions | ||
image = cv2.imread(imagePath) | ||
image = imutils.resize(image, width=600) | ||
(h, w) = image.shape[:2] | ||
# scale the predicted bounding box coordinates based on the image | ||
# dimensions | ||
startX = int(startX * w) | ||
startY = int(startY * h) | ||
endX = int(endX * w) | ||
endY = int(endY * h) | ||
|
||
#crop the roi | ||
roi = image[startY:endY,startX:endX] | ||
roi = cv2.resize(roi,(100,100)) | ||
roi = img_to_array(roi) / 255.0 | ||
roi = np.expand_dims(roi, axis=0) | ||
#pred intensity | ||
classes = {'EXTREME':0, 'NORMAL':1, 'SEVERE':2, 'SUPER':3, 'VERY':4} | ||
Y_pred = in_model.predict(roi) | ||
Y_pred_classes = np.argmax(Y_pred,axis = 1) | ||
|
||
# draw the predicted bounding box on the image | ||
cv2.rectangle(image, (startX, startY), (endX, endY),(0, 255, 0), 2) | ||
#print(imagePath) | ||
txt = str(get_key(classes, Y_pred_classes[0])) | ||
image2 = cv2.putText(image.copy(),txt, (startX-2,startY-4), font,fontScale, color, thickness, cv2.LINE_AA) | ||
|
||
print("The predicted class for the given image is: ", get_key(classes, Y_pred_classes[0])) | ||
while True: | ||
cv2.imshow("Detection",image) | ||
cv2.imshow("Prediction",image2) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
cv2.destroyAllWindows() | ||
# cv2.imwrite('./result2/'+str(p)+'.jpg',image) | ||
# p = p+1 | ||
# print("pred image saved") | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Hybrid Prediction - Cyclone Detection and Intensity Estimation" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[INFO] loading object detector...\n", | ||
"2022-03-29 11:59:21.081233: E tensorflow/stream_executor/cuda/cuda_driver.cc:271] failed call to cuInit: CUDA_ERROR_NO_DEVICE: no CUDA-capable device is detected\n", | ||
"2022-03-29 11:59:21.081325: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:169] retrieving CUDA diagnostic information for host: indra-pop-os\n", | ||
"2022-03-29 11:59:21.081351: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:176] hostname: indra-pop-os\n", | ||
"2022-03-29 11:59:21.081544: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:200] libcuda reported version is: 510.54.0\n", | ||
"2022-03-29 11:59:21.081621: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:204] kernel reported version is: 510.54.0\n", | ||
"2022-03-29 11:59:21.081646: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:310] kernel version seems to match DSO: 510.54.0\n", | ||
"2022-03-29 11:59:21.082183: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX2 FMA\n", | ||
"To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.\n", | ||
"[INFO] loaded object detector...\n", | ||
"--------------------------------------------------\n", | ||
"[INFO] loading intensity estimator model...\n", | ||
"[INFO] loaded intensity estimator model...\n", | ||
"The predicted class for the given image is: NORMAL\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"!python hybridPred.py --input ../data/processed/threshZero_data/NORMAL/3DIMG_01DEC2020_0430_L1B_STD_IR2.jpg" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"interpreter": { | ||
"hash": "92f8549edb95926e67d9af130c51c844e0526e8912c849c6708914c947287dc8" | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3.9.7 ('vortex3.9')", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.11" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters