This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder