Skip to content

Instantly share code, notes, and snippets.

View malnakli's full-sized avatar

Mohammed malnakli

  • Riyadh, Saudi Arabia
View GitHub Profile
"use strict";
/**
* Module dependencies
*/
const admin = require("firebase-admin");
module.exports = {
init(config) {
import torch.nn as nn
import math
def conv2d_out_shape(width, height, Conv2d):
"""
return (C , W , H)
C: channels
W: Width
H: Height
import requests
import json
import sys
labels = ['T-shirt/top' ,'Trouser','Pullover','Dress','Coat','Sandal','Shirt','Sneaker','Bag', 'Ankle boot']
# setup the request
url = "http://localhost:8501"
full_url = f"{url}/v1/models/tf_serving_keras_mobilenetv2/versions/1:predict"
from urllib import request
from PIL import Image
image_url = "https://cdn.shopify.com/s/files/1/2029/4253/products/[email protected]"
image_path = f"tmp/{image_url.split('/')[-1]}"
# download image
with request.urlopen(url=image_url, timeout=10) as response:
data = response.read()
with open(image_path, 'wb') as f:
f.write(data)
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
import os
import tensorflow as tf
import keras
# Import the libraries needed for saving models
# Note that in some other tutorials these are framed as coming from tensorflow_serving_api which is no longer correct
from tensorflow.python.saved_model import builder as saved_model_builder
from tensorflow.python.saved_model import tag_constants, signature_constants, signature_def_utils_impl
# images will be the input key name
# scores will be the out key name
from sklearn.utils import shuffle
def load_data_generator(x, y, batch_size=64):
num_samples = x.shape[0]
while 1: # Loop forever so the generator never terminates
try:
shuffle(x)
for i in range(0, num_samples, batch_size):
x_data = [preprocess_image(im) for im in x[i:i+batch_size]]
y_data = y[i:i + batch_size]
from skimage.transform import resize
target_size = 96
def preprocess_image(x):
# Resize the image to have the shape of (96,96)
x = resize(x, (target_size, target_size),
mode='constant',
anti_aliasing=False)
from keras.applications.mobilenetv2 import MobileNetV2
from keras.layers import Dense, Input, Dropout
from keras.models import Model
def build_model( ):
input_tensor = Input(shape=(target_size, target_size, 3))
base_model = MobileNetV2(
include_top=False,
weights='imagenet',
input_tensor=input_tensor,
# Author: Robert Guthrie
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
from sklearn.metrics.pairwise import euclidean_distances
torch.manual_seed(1)