Skip to content

Instantly share code, notes, and snippets.

View jeanmidevacc's full-sized avatar

Jean-Michel Daignan jeanmidevacc

View GitHub Profile
import tensorflow as tf
import tensorflow_hub as hub
# colelct the feature extractor of mobile net
feature_extractor_url = "https://tfhub.dev/google/tf2-preview/mobilenet_v2/feature_vector/2" #@param {type:"string"}
feature_extractor_layer = hub.KerasLayer(feature_extractor_url,
input_shape=(IMG_HEIGHT, IMG_WIDTH,3))
feature_extractor_layer.trainable = False
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.Conv2D(
32, (3, 3), padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D((2, 2)),
tf.keras.layers.Dropout(rate=0.5),
tf.keras.layers.Conv2D(
64, (3, 3), padding='same', activation='relu'),
import tensorflow as tf
model = tf.keras.models.Sequential([
tf.keras.layers.Flatten(input_shape=(IMG_HEIGHT, IMG_WIDTH, 3)),
tf.keras.layers.Dense(300, activation="relu"),
tf.keras.layers.Dense(100, activation="relu"),
tf.keras.layers.Dense(len(CLASS_NAMES), activation="softmax")
])
model.compile(optimizer='adam',
import tensorflow as tf
model = tf.keras.models.Sequential([
tf.keras.layers.Conv2D(16, 3, padding='same', activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH ,3)),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Conv2D(32, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Conv2D(64, 3, padding='same', activation='relu'),
tf.keras.layers.MaxPooling2D(),
tf.keras.layers.Flatten(),
"""
Based on https://www.tensorflow.org/tutorials/images/cnn
"""
import pathlib
import tensorflow as tf
# Definition of the constant
BATCH_SIZE = 30
EPOCHS = 5
informations = []
for i,run in enumerate(runs):
if run.successful:
# collect some details on the fisrt and last step of the flow
step_start = Step(f"{flowname}/{run.id}/start")
step_end = run.end_task
# Collect the number of cards picked for the features computation
nbr_cardsselected = step_start.task.data.limittopcards
@jeanmidevacc
jeanmidevacc / decoratorexample_flow.py
Created January 22, 2020 23:27
A Flow design to explained the potential of metaflow decorator.
"""
pipeline.py
Script to test the different decorator on the metaflow framework
"""
import random
from metaflow import FlowSpec, step, Parameter, conda, conda_base
@conda_base(disabled = False ,python="3.7.4", libraries={"pandas" : "0.25.2"})
class ExampleFlow(FlowSpec):
from PIL import Image
def build_mlimage(path, config_resize = (100,50), is_bw = True):
# Access the image
img = Image.open(path)
# Resizing and conversion in black and white (if necessary)
if is_bw:
newimg = img.resize(config_resize, Image.ANTIALIAS).convert('L')
else:
from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score, explained_variance_score
import mlflow
import mlflow.sklearn
import numpy as np
# Launch the experiment on mlflow
experiment_name = "electricityconsumption-forecast"
import boto3
import json
# Name of the app that you defined during the deployment on sagemaker
app_name = "xxxxx"
# AWS region of the deployment of the app on sagemaker
region = "xxxxx"
# Function to collect data from the endpoint on sagemaker
def query_endpoint(input_json):