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 coremltools | |
# Scrape the 100 newest posts from each subreddit | |
max_posts = 100 | |
posts = [] | |
for subreddit in subreddits: | |
posts.extend(get_n_posts(max_posts, subreddit, sort='new')) | |
# Apply the same preprocessing to the data | |
new_df = pandas.DataFrame(posts, columns=['subreddit', 'title']) |
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
// Drag your subredditClassifier.mlmodel to the Xcode project navigator. | |
// Use the model with the following code. | |
import NaturalLanguage | |
let subredditPredictor = try NLModel(mlModel: subredditClassifier().model) | |
subredditPredictor.predictedLabel(for: "TIL you can use Core ML to suggest subreddits to users.") |
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
@classmethod | |
def build( | |
cls, | |
image_size, | |
alpha=1.0, | |
input_tensor=None, | |
checkpoint_file=None): | |
"""Build a Transfer Network Model using keras' functional API. | |
Args: | |
image_size - the size of the input and output image (H, W) |
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
@classmethod | |
def build( | |
cls, | |
image_size, | |
alpha=1.0, | |
input_tensor=None, | |
checkpoint_file=None): | |
"""Build a Small Transfer Network Model using keras' functional API. | |
This architecture removes some blocks of layers and reduces the size | |
of convolutions to save on computation. |
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
private var machineIdentifier: String { | |
// Returns a machine identifier string. E.g. iPhone10,3 or iPhone7,1 | |
// A full list of machine identifiers can be found here: | |
// https://gist.github.com/adamawolf/3048717 | |
if let simulatorModelIdentifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { return simulatorModelIdentifier } | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
return withUnsafeMutablePointer(to: &systemInfo.machine) { | |
ptr in String(cString: UnsafeRawPointer(ptr).assumingMemoryBound(to: CChar.self)) | |
} |
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 | |
// Fetch all of the models matching the tag | |
// we chose based on the machine identifier | |
let tagManager = ModelTagManager(tags: [tag]) | |
// Loop through all of the models returned and download each model. | |
// In this case, we should only have a single model for each tag. | |
var allModels: [FritzMLModel] = [] | |
tagManager.fetchManagedModelsForTags { managedModels, error in |
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 { | |
var cameraView: UIImageView! | |
var maskView: UIImageView! | |
override func viewDidLoad() { | |
// ... | |
cameraView = UIImageView(frame: view.bounds) | |
cameraView.contentMode = .scaleAspectFill |
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 MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
val onDeviceModel = new ObjectDetectionOnDeviceModel(); | |
val objectPredictor = FritzVision.ObjectDetection.getPredictor(onDeviceModel); | |
var fritzVisionImage: FritzVisionImage | |
cameraView.addFrameProcessor { frame -> | |
if (yuvDataLength == 0) { | |
//Run this only once | |
initializeData() |
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 MainActivity : AppCompatActivity() { | |
private lateinit var renderScript: RenderScript | |
private lateinit var yuvToRGB: ScriptIntrinsicYuvToRGB | |
private var yuvDataLength: Int = 0 | |
private lateinit var allocationIn: Allocation | |
private lateinit var allocationOut: Allocation | |
private lateinit var bitmapOut: Bitmap | |
//Rest of the code |
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 MainActivity : AppCompatActivity() { | |
private lateinit var renderScript: RenderScript | |
private lateinit var yuvToRGB: ScriptIntrinsicYuvToRGB | |
private var yuvDataLength: Int = 0 | |
private lateinit var allocationIn: Allocation | |
private lateinit var allocationOut: Allocation | |
private lateinit var bitmapOut: Bitmap | |
private val itemMap by lazy { |