Skip to content

Instantly share code, notes, and snippets.

View aymericdelab's full-sized avatar
🎯
Focusing

raschel aymericdelab

🎯
Focusing
View GitHub Profile
import cv2
import os
dim1,dim2 = 28,28
founders=['Jeff Bezos','Larry Page','Bill Gates']
for founder in founders:
#prefix=r'.\data\google\{}'.format(founder)
from azure.cognitiveservices.search.imagesearch import ImageSearchAPI
from msrest.authentication import CognitiveServicesCredentials
from PIL import Image
import requests
from io import BytesIO
import os
# create an Azure account
# and get your API key from here:
# https://azure.microsoft.com/en-us/services/cognitive-services/bing-image-search-api/
from google_images_download import google_images_download
downloader=google_images_download.googleimagesdownload()
## if we want to retrieve more than 100 images from google drive we need to download chromedriver
cd_path='C:\Program Files\chromedriver_win32\chromedriver.exe'
output_dir=r'./data/google/'
founders=['Jeff Bezos','Larry Page','Bill Gates']
@aymericdelab
aymericdelab / from_image_to_json.py
Created October 16, 2019 19:35
transfrom image into a json file to send to GCP deployed model
import cv2
import json
import numpy as np
def from_image_to_json(image_directory):
image=cv2.imread(image_directory)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
faces = faceCascade.detectMultiScale(
import cv2
import requests
key1, Key2 = service.get_keys()
def get_founder(image_directory):
image=cv2.imread(image_directory)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + "haarcascade_frontalface_default.xml")
@aymericdelab
aymericdelab / azure_deployment.py
Created October 16, 2019 17:03
deployment on azure using a ACI
## deploy the model to the ACI (azure container instances)
from azureml.core.webservice import AciWebservice
from azureml.core.model import InferenceConfig
from azureml.core.webservice import Webservice
from azureml.core.model import Model
inference_config = InferenceConfig(runtime= "python", ## runtime for the image, either python or spark-py
entry_script="score.py",
conda_file="myenv.yml") ##dependencies
@aymericdelab
aymericdelab / score.py
Created October 15, 2019 16:48
entry point script for the deployment in azure ml
import numpy as np
from tensorflow.contrib import predictor
from azureml.core.model import Model
import json
def init():
global loaded_model
saved_model_location=Model.get_model_path('founder-classifier-test')
## create the myenv.yml to install the necessary packages on the Docker image
from azureml.core.runconfig import CondaDependencies
cd = CondaDependencies.create()
cd.add_conda_package('tensorflow')
cd.save_to_file(base_directory='./', conda_file_path='myenv.yml')
print(cd.serialize_to_string())
@aymericdelab
aymericdelab / register_model.py
Created October 15, 2019 16:41
register model in azure to deploy it
from azureml.core.model import Model
model_dir='./outputs/founder-classifier/outputs/model/1570442423'
# Tip: When model_path is set to a directory, you can use the child_paths parameter to include
# only some of the files from the directory
model = Model.register(model_path = model_dir,
model_name = "founder-classifier",
description = "classification of founders using CNN",
workspace = ws)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.