Skip to content

Instantly share code, notes, and snippets.

guard let pose = poseResult.decodePose() else { return }
let leftArmParts: [PosePart] = [.leftWrist, .leftElbow, .leftShoulder]
let rightArmParts: [PosePart] = [.rightWrist, .rightElbow, .rightShoulder]
var foundLeftArm: [Keypoint] = []
var foundRightArm: [Keypoint] = []
for keypoint in pose.keypoints {
if leftArmParts.contains(keypoint.part) {
@jamesonthecrow
jamesonthecrow / fritz_style_transfer_template.sh
Last active May 12, 2020 06:26
Train a Fritz Style Transfer model with a custom style image in 20 minutes. Create Core ML and TensorFlow Mobile versions for use in your app. More information at https://fritz.ai.
# A script to train an artistic style transfer model from a custom style image.
# A Google Colab going through the same steps can be found here:
# https://colab.research.google.com/drive/1nDkxLKBgZGFscGoF0tfyPMGqW03xITl0#scrollTo=V33xVH-CWUCs
# Note that this script will download and unzip 1GB of photos for training.
# Make sure you have the appropriate permissions to use any images.
# CHANGE ME BEFORE RUNNING
STYLE_IMAGE_URL='STYLE_IMAGE_URL'
# Install requirements
import Fritz
class PoseEstimationViewController: UIViewController {
private let poseModel = FritzVisionPoseModel()
// We can also set of sensitivity parameters for our model.
// The poseThreshold is a number between 0 and 1. Higher numbers mean
// the model must be more confident about its estimate, thus reducing false
// positives.
internal var poseThreshold: Double = 0.3
import ai.fritz.vision.FritzVision;
import ai.fritz.poseestimationmodel.PoseEstimationOnDeviceModel;
import ai.fritz.vision.poseestimation.FritzVisionPosePredictor;
import ai.fritz.core.FritzOnDeviceModel;
// ...
public class CameraActivity extends Activity implements ImageReader.OnImageAvailableListener {
private FritzVisionPosePredictor posePredictor;
private FritzVisionPoseResult poseResult;
@jamesonthecrow
jamesonthecrow / trainSubredditSuggester.swift
Created November 11, 2018 03:37
Train a text classification model with CreateML to suggest subreddits based on a proposed title.
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
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 July 26, 2019 14:47
Pet Segmentation iOS View Controller with Fritz (www.fritz.ai)
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 July 26, 2019 14:42
Pet Segmentation on Android with Fritz (www.fritz.ai)
// 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 / fritz_cli_tutorial.py
Created July 6, 2019 14:02
Mobile machine learning with Fritz. https://fritz.ai
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 July 6, 2019 14:01
Mobile machine learning made easy with the Fritz CLI. https://fritz.ai
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