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 sys | |
import coremltools | |
from coremltools.models.neural_network.quantization_utils import * | |
def quantize(file, bits, functions): | |
""" | |
Processes a file to quantize it for each bit-per-weight | |
and function listed. | |
file : Core ML file to process (example : mymodel.mlmodel) | |
bits : Array of bit per weight (example : [16,8,6,4,2,1]) |
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 sys | |
from onnx import onnx_pb | |
from onnx_coreml import convert | |
model_in = sys.argv[1] | |
model_out = sys.argv[2] | |
model_file = open(model_in, 'rb') | |
model_proto = onnx_pb.ModelProto() | |
model_proto.ParseFromString(model_file.read()) |
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
func process(input: UIImage, completion: @escaping FilteringCompletion) { | |
// Initialize the NST model | |
let model = StarryNight() | |
// Next steps are pretty heavy, better process them on a background thread | |
DispatchQueue.global().async { | |
// 1 - Transform our UIImage to a PixelBuffer of appropriate size | |
guard let cvBufferInput = input.pixelBuffer(width: 720, height: 720) else { |
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
python ./neural_style/neural_style.py eval \ | |
--content-image ~/Documents/data/images/original.jpg \ | |
--output-image ~/Documents/data/images/stylized-test.jpg \ | |
--model ~/Documents/checkpoints/checkpoint_5000.pth \ | |
--cuda 0 \ | |
--export_onnx ~/Documents/models/pytorch_model.onnx \ | |
&& \ | |
python ./onnx_to_coreml.py \ | |
~/Documents/models/pytorch_model.onnx \ | |
~/Documents/models/final_model.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
python neural_style/neural_style.py eval \ | |
--model ~/Documents/checkpoint_5000.pth \ | |
--content-image ~/Documents/images/original.jpg \ | |
--output-image ~/Documents/images/stylized-test.jpg \ | |
--cuda 0 |
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
python neural_style/neural_style.py train \ | |
--dataset ~/Documents/dataset \ | |
--style-image ~/Documents/images/styles/starry_night.jpg \ | |
--style-size 512 \ | |
--batch-size 2 \ | |
--style-weight 1e10 \ | |
--content-weight 1e5 \ | |
--checkpoint-model-dir ~/Documents/checkpoints \ | |
--save-model-dir ~/Documents/models \ | |
--log-interval 10 \ |
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
API.request(.Colors("Sunny")) { response in | |
if (response.result.error) != nil { | |
// ERROR HANDLING | |
} else { | |
// PARSING... | |
} | |
} |
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
public static func request( | |
endpoint: API.Endpoints, | |
completionHandler: Response<AnyObject, NSError> -> Void) | |
-> Request { | |
let request = Manager.sharedInstance.request( | |
endpoint.method, | |
endpoint.path, | |
parameters: endpoint.parameters, | |
encoding: .URL, | |
headers: nil |
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
public var method: Alamofire.Method { | |
switch self { | |
case .Colors: | |
return Alamofire.Method.GET | |
case .AddColor: | |
return Alamofire.Method.POST | |
} | |
} | |
public var path: 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
public enum Endpoints { | |
case Colors(String) | |
case AddColor(Color) | |
} |
NewerOlder