Skip to content

Instantly share code, notes, and snippets.

Jameson Toole jamesonthecrow

Block or report user

Report or block jamesonthecrow

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jamesonthecrow
jamesonthecrow / trainSubredditSuggester.swift
Created Nov 11, 2018
Train a text classification model with CreateML to suggest subreddits based on a proposed title.
View trainSubredditSuggester.swift
import CreateML
import Foundation
// Load our data into an MLDataTable object.
let dataFilename = "PATH/TO/data.json"
let data = try MLDataTable(contentsOf: URL(fileURLWithPath: dataFilename))
print(data.description)
/*
Columns:
label string
View PoseEstimationViewController.swift
extension PoseEstimationViewController: AVCaptureVideoDataOutputSampleBufferDelegate {
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
// FritzVisionImage objects offer convient ways to manipulate
// images used as input to machine learning models.
// You can resize, crop, and scale images to your needs.
let image = FritzVisionImage(sampleBuffer: sampleBuffer, connection: connection)
// Set options for our pose estimation model using the constants
// we initialized earlier in the ViewController.
@jamesonthecrow
jamesonthecrow / ViewController.swift
Last active Jul 26, 2019
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
View ViewController.swift
class ViewController: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
/// The rest of the view controller...
/// Scores output from model greater than this value will be set as 1.
/// Lowering this value will make the mask more intense for lower confidence values.
var clippingScoresAbove: Double { return 0.6 }
/// Values lower than this value will not appear in the mask.
var zeroingScoresBelow: Double { return 0.4 }
@jamesonthecrow
jamesonthecrow / PetSeg-CreatePredictor.java
Last active Jul 26, 2019
Pet Segmentation on Android with Fritz (www.fritz.ai)
View PetSeg-CreatePredictor.java
// Initialize the model included with the app
PetSegmentationOnDeviceModel onDeviceModel = new PetSegmentationOnDeviceModel();
FritzVisionSegmentPredictorOptions options = new FritzVisionSegmentPredictorOptions.Builder()
.targetConfidenceThreshold(.4f)
.build();
// Create the predictor with the Pet Segmentation model.
predictor = FritzVision.ImageSegmentation.getPredictor(onDeviceModel, options);
View fritz_cli_tutorial.py
keras.backend.clear_session()
# Retrain the model with our new configuration and callback
model = build_model()
model.compile(
keras.optimizers.Adam(lr=metadata['learning_rate']),
loss=keras.losses.sparse_categorical_crossentropy,
metrics=[keras.metrics.sparse_categorical_accuracy]
)
@jamesonthecrow
jamesonthecrow / fritz_cli_tutorial.py
Created Jul 6, 2019
Mobile machine learning made easy with the Fritz CLI. https://fritz.ai
View fritz_cli_tutorial.py
import fritz
import fritz.train
# Fritz needs to be configured first. Calling the fritz.Configure() method will
# read the credentials we setup for the CLI earlier.
fritz.configure()
# Create the callback
# Start by defining a training configuration and storing it as metadata
@jamesonthecrow
jamesonthecrow / fritz_cli_tutorial.py
Last active Jul 6, 2019
Mobile machine learning with the Fritz CLI. https://fritz.ai
View fritz_cli_tutorial.py
# Convert to mobile formats
import coremltools
import tensorflow as tf
import tempfile
def convert_to_coreml(model):
return coremltools.converters.keras.convert(
model,
input_names=['input'],
output_names=['digit']
View fritz_cli_tutorial.py
import keras
from keras.datasets import mnist
keras.backend.clear_session()
(x_train, y_train), (x_test, y_test) = mnist.load_data()
def build_model():
input = keras.layers.Input((28, 28, 1))
out = keras.layers.Conv2D(16, 3, strides=2, activation='relu')(input)
@jamesonthecrow
jamesonthecrow / ViewController.swift
Last active Jun 11, 2019
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
View ViewController.swift
import UIKit
import AVFoundation
import Fritz
class ViewController: UIViewController, UIImagePickerControllerDelegate,
UINavigationControllerDelegate {
@IBOutlet var imageView: UIImageView!
var maskView: UIImageView!
var backgroundView: UIImageView!
@jamesonthecrow
jamesonthecrow / PetSeg-RunPrediction.java
Last active Jun 10, 2019
Pet Segmentation on Android with Fritz (www.fritz.ai)
View PetSeg-RunPrediction.java
// Run the image through the model to identify pixels belonging to a pet.
FritzVisionSegmentResult segmentResult = predictor.predict(visionImage);
You can’t perform that action at this time.