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
var md5: String { | |
let str = self.cString(using: .utf8) | |
let strLen = CUnsignedInt(self.lengthOfBytes(using: .utf8)) | |
let digestLen = Int(CC_MD5_DIGEST_LENGTH) | |
let result = UnsafeMutablePointer<CUnsignedChar>.allocate(capacity: digestLen) | |
CC_MD5(str!, strLen, result) | |
let hash = NSMutableString() | |
for i in 0..<digestLen { | |
hash.appendFormat("%02x", result[i]) | |
} |
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 Foundation | |
struct MarvelURL { | |
private let ts = Int(Date().timeIntervalSinceReferenceDate) | |
private let privateKey = Bundle.main.object(forInfoDictionaryKey: "MarvelPrivateKey")! | |
private let publicKey = "3e2e1997fd3ada9d85d651c8627d1052" | |
let urlString: String | |
func authorized() -> URL { |
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 let classifier = Resnet50() | |
func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) { | |
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) | |
let rescaled = rescaledImageRectangle(createUIImage(from: imageBuffer), dimension: inputImageScale) | |
let rescaledBuffer = createCVPixelBuffer(from: rescaled) | |
guard let prediction = try? classifier.prediction(image: rescaledBuffer!) else { return } | |
DispatchQueue.main.async { | |
self.predictionLabel.text = prediction.classLabel |
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
pip install -U coremltools | |
pip install jupyter | |
jupyter-notebook |
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
pip install ipykernel | |
python -m ipykernel install --user --name=your-enviroment-name |
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 | |
age_net = coremltools.converters.caffe.convert(('models/age_net.caffemodel', 'models/deploy_age.prototxt'), | |
image_input_names='data', | |
class_labels='models/age_labels.txt') | |
gender_net = coremltools.converters.caffe.convert(('models/gender_net.caffemodel', 'models/deploy_gender.prototxt'), | |
image_input_names='data', | |
class_labels='models/gender_labels.txt') | |
age_net.save('AgeNet.mlmodel') | |
gender_net.save('GenderNet.mlmodel') |
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
input: "data" | |
input_dim: 1 | |
input_dim: 3 | |
input_dim: 227 | |
input_dim: 227 |
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
(0, 2) | |
(4, 6) | |
(8, 12) | |
(15, 20) | |
(25, 32) | |
(38, 43) | |
(48, 53) | |
(60, 100) |
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
let image = UIImage(buffer: givenBuffer)!.rescaled(width: desiredWidth, height: desiredHeight) | |
let buffer = image.buffer | |
let model = GenderNet() | |
let prediction = try! model.prediction(data: buffer) | |
let probabilites = prediction.prob // ['Male': 66.22, 'Female': 22.3212341] | |
let output = prediction.classLabel // 'Male |
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 LiveCameraViewController: LiveCameraDelegate { | |
private let ageModel = try! VNCoreMLModel(for: AgeNet().model) | |
private let genderModel = try! VNCoreMLModel(for: GenderNet().model) | |
func createAgeRequest() -> VNCoreMLRequest { | |
return VNCoreMLRequest(model: ageModel, completionHandler: onClassification) | |
} | |
func createGenderRequest() -> VNCoreMLRequest { |
OlderNewer