Skip to content

Instantly share code, notes, and snippets.

View roywei's full-sized avatar
🎯
Focusing

Lai Wei roywei

🎯
Focusing
View GitHub Profile
@roywei
roywei / export_repo_issues_to_csv.py
Last active February 27, 2018 19:12 — forked from unbracketed/export_repo_issues_to_csv.py
Export Issues from Github repo to CSV (API v3)
"""
Exports Issues from a specified repository to a CSV file
Uses basic authentication (Github username + password) to retrieve Issues
from a repository that username has access to. Supports Github API v3.
"""
import csv
import requests
import random
GITHUB_USER = ''
@roywei
roywei / ImageClassifierExample.scala
Created June 12, 2018 22:13
Image Classifier Example for MXNet Scala Inference API
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
@roywei
roywei / ImageClassifierExample.scala
Created June 12, 2018 22:18
Code Snippet for Image Classifier Example
def runInferenceOnSingleImage(modelPathPrefix: String, inputImagePath: String,
context: Array[Context]):
IndexedSeq[IndexedSeq[(String, Float)]] = {
val dType = DType.Float32
val inputShape = Shape(1, 3, 32, 32)
val inputDescriptor = IndexedSeq(DataDesc("/input_11", inputShape, dType, "NCHW"))
// Create object of ImageClassifier class
val imgClassifier: ImageClassifier = new
@roywei
roywei / estimator_example.py
Last active May 3, 2019 21:04
Gluon Estimator Example
"""Gluon Estimator example on MNIST dataset with simple CNN"""
import sys
import os
import time
import mxnet as mx
from mxnet import gluon, nd, autograd
from mxnet import metric
from mxnet.gluon import nn, data
from mxnet.gluon.contrib.estimator import Estimator
Epoch 1.4.1 Duration(ms) 1.5.0 Duration(ms)
0 230.757866 236.492851
1 222.984238 210.10698
2 201.988141 216.398906
3 180.265748 193.985564
4 186.75808 184.309184
5 175.55141 189.248856
6 176.789087 181.657551
7 175.327701 178.745348
8 170.667204 177.222914
python build_covid_dataset.py --covid covid-chestxray-dataset --output dataset/covid
python sample_kaggle_dataset.py --kaggle chest_xray --output dataset/normal
python train_covid19.py --dataset dataset
./gradlew run -Dai.djl.repository.zoo.location=models/saved_model
[main] INFO com.examples.PneumoniaDetection - Diagnose: [
class: "Pneumonia", probability: 0.99310
class: "Normal", probability: 0.00689
]
repositories {
jcenter()
}
dependencies {
implementation "ai.djl:api:0.5.0"
implementation "ai.djl.tensorflow:tensorflow-api:0.5.0"
implementation "ai.djl.tensorflow:tensorflow-engine:0.5.0"
runtimeOnly "ai.djl.tensorflow:tensorflow-native-auto:2.1.0"
runtimeOnly "org.slf4j:slf4j-simple:1.7.29"
testImplementation "junit:junit:4.12"
Criteria<BufferedImage, Classifications> criteria =
Criteria.builder()
.setTypes(BufferedImage.class, Classifications.class)
.optTranslator(new MyTranslator())
.build();
try (ZooModel<BufferedImage, Classifications> model = ModelZoo.loadModel(criteria)) {
try (Predictor<BufferedImage, Classifications> predictor = model.newPredictor()) {
Classifications result = predictor.predict(image);
logger.info("Diagnose:" + result.toString());
}