Skip to content

Instantly share code, notes, and snippets.

View alexiscreuzot's full-sized avatar
🚀
Making new stuff

Alexis Creuzot alexiscreuzot

🚀
Making new stuff
View GitHub Profile
#!/bin/sh
# Some things taken from here
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
# Set the colours you can use
black='\033[0;30m'
white='\033[0;37m'
red='\033[0;31m'
green='\033[0;32m'
public enum Endpoints {
case Colors(String)
case AddColor(Color)
}
public var method: Alamofire.Method {
switch self {
case .Colors:
return Alamofire.Method.GET
case .AddColor:
return Alamofire.Method.POST
}
}
public var path: String {
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
API.request(.Colors("Sunny")) { response in
if (response.result.error) != nil {
// ERROR HANDLING
} else {
// PARSING...
}
}
@alexiscreuzot
alexiscreuzot / train.sh
Last active August 23, 2018 15:18
Building a Style Transfer app on iOS using CoreML
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 \
@alexiscreuzot
alexiscreuzot / stylize.sh
Created August 20, 2018 15:01
Building a Style Transfer app on iOS using CoreML (2)
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
@alexiscreuzot
alexiscreuzot / export_coreml.sh
Created August 20, 2018 15:02
Building a Style Transfer app on iOS using CoreML (2)
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
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 {
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())