Skip to content

Instantly share code, notes, and snippets.

View AyaanZaveri's full-sized avatar
🚀

Ayaan AyaanZaveri

🚀
  • Toronto, Ontario
  • 20:48 (UTC -04:00)
View GitHub Profile
@AyaanZaveri
AyaanZaveri / flask.py
Last active October 13, 2021 14:14
Flask Boilerplate
from flask import Flask, render_template, session
from flask import request
app = Flask(__name__)
app.secret_key = "abc"
@app.route('/', methods=['GET','POST'])
def process():
name = request.form.get('name','')
survived sex age n_siblings_spouses parch fare class deck embark_town alone
0 male 35.0 0 0 8.05 Third unknown Southampton y
0 male 54.0 0 0 51.8625 First E Southampton y
1 female 58.0 0 0 26.55 First C Southampton y
1 female 55.0 0 0 16.0 Second unknown Southampton y
1 male 34.0 0 0 13.0 Second D Southampton y
1 female 15.0 0 0 8.0292 Third unknown Queenstown y
0 female 8.0 3 1 21.075 Third unknown Southampton n
0 male 21.0 0 0 8.05 Third unknown Southampton y
0 female 18.0 2 0 18.0 Third unknown Southampton n
survived sex age n_siblings_spouses parch fare class deck embark_town alone
0 male 22.0 1 0 7.25 Third unknown Southampton n
1 female 38.0 1 0 71.2833 First C Cherbourg n
1 female 26.0 0 0 7.925 Third unknown Southampton y
1 female 35.0 1 0 53.1 First C Southampton n
0 male 28.0 0 0 8.4583 Third unknown Queenstown y
0 male 2.0 3 1 21.075 Third unknown Southampton n
1 female 27.0 0 2 11.1333 Third unknown Southampton n
1 female 14.0 1 0 30.0708 Second unknown Cherbourg n
1 female 4.0 1 1 16.7 Third G Southampton n
label_id_offset = 0
image_np_with_detections = image_np.copy()
# Use keypoints if available in detections
keypoints, keypoint_scores = None, None
if 'detection_keypoints' in result:
keypoints = result['detection_keypoints'][0]
keypoint_scores = result['detection_keypoint_scores'][0]
viz_utils.visualize_boxes_and_labels_on_image_array(
#Detection
results = hub_model(image_np)
result = {key:value.numpy() for key,value in results.items()}
#Download The Image
!wget -O myfile.jpg.tmp "https://images.unsplash.com/photo-1595801185745-c35f30d63934?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=2250&q=80" && mv myfile.jpg{.tmp,} && mv /content/myfile.jpg "/content/"
#Set Image Path
image_path = "/content/myfile.jpg"
image_np = load_image_into_numpy_array(image_path)
#Show Image
plt.figure(figsize=(24,32))
plt.imshow(image_np[0])
print('Loading Model...')
hub_model = hub.load(model_handle)
print('Model Loaded!')
#@title Model Selection { display-mode: "form", run: "auto" }
model_display_name = 'EfficientDet D4 1024x1024' # @param ['CenterNet HourGlass104 512x512','CenterNet HourGlass104 Keypoints 512x512','CenterNet HourGlass104 1024x1024','CenterNet HourGlass104 Keypoints 1024x1024','CenterNet Resnet50 V1 FPN 512x512','CenterNet Resnet50 V1 FPN Keypoints 512x512','CenterNet Resnet101 V1 FPN 512x512','CenterNet Resnet50 V2 512x512','CenterNet Resnet50 V2 Keypoints 512x512','EfficientDet D0 512x512','EfficientDet D1 640x640','EfficientDet D2 768x768','EfficientDet D3 896x896','EfficientDet D4 1024x1024','EfficientDet D5 1280x1280','EfficientDet D6 1280x1280','EfficientDet D7 1536x1536','SSD MobileNet v2 320x320','SSD MobileNet V1 FPN 640x640','SSD MobileNet V2 FPNLite 320x320','SSD MobileNet V2 FPNLite 640x640','SSD ResNet50 V1 FPN 640x640 (RetinaNet50)','SSD ResNet50 V1 FPN 1024x1024 (RetinaNet50)','SSD ResNet101 V1 FPN 640x640 (RetinaNet101)','SSD ResNet101 V1 FPN 1024x1024 (RetinaNet101)','SSD ResNet152 V1 FPN 640x
#Use Proxima Nova Font
!mv "/content/models/research/object_detection/Proxima Nova Bold.ttf" /usr/share/fonts/truetype
#Install Packages
%%bash
sudo apt install -y protobuf-compiler
cd models/research/
protoc object_detection/protos/*.proto --python_out=.
cp object_detection/packages/tf2/setup.py .
python -m pip install .
#Clone The Files For The Model
!git clone --depth 1 https://github.com/AyaanZaveri/models