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
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 / 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);
@jamesonthecrow
jamesonthecrow / PetSeg-createImage.java
Last active Jun 10, 2019
Pet Segmentation on Android with Fritz (www.fritz.ai)
View PetSeg-createImage.java
// Determine how to rotate the image from the camera used.
int imgRotation = FritzVisionOrientation.getImageRotationFromCamera(this, cameraId);
// Create a FritzVisionImage object from android.media.Image
FritzVisionImage visionImage = FritzVisionImage.fromMediaImage(image, imgRotation);
@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);
@jamesonthecrow
jamesonthecrow / ViewController.swift
Created May 15, 2019
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
View ViewController.swift
extension ViewController: AVCaptureVideoDataOutputSampleBufferDelegate {
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
let image = FritzVisionImage(buffer: sampleBuffer)
image.metadata = FritzVisionImageMetadata()
image.metadata?.orientation = FritzImageOrientation(from: connection)
guard let result = try? visionModel.predict(image) else { return }
let mask = result.buildSingleClassMask(
@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 / ViewController.swift
Created May 15, 2019
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
View ViewController.swift
// ...
import Fritz
class ViewController: UIViewController {
var cameraView: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
You can’t perform that action at this time.