Skip to content

Instantly share code, notes, and snippets.

View ozgurshn's full-sized avatar

Ozgur Sahin ozgurshn

View GitHub Profile
@ozgurshn
ozgurshn / ObjProtocolInSwift.swift
Last active June 19, 2016 12:00
Ensuring Objective-C class implemented Swift optional protocol method
@objc protocol VideoRangeSliderDelegate
{
func videoRange (videoRange:VideoRangeSlider, didChangeLeftPosition:CGFloat, rightPosition:CGFloat)
optional func videoRange(videoRange:VideoRangeSlider, didGestureStateEndedLeftPosition:CGFloat, rightPosition:CGFloat)
}
// Usage ensuring call if method is implemented
delegate?.videoRange?(self, didGestureStateEndedLeftPosition: self.leftPosition, rightPosition: self.rightPosition)
@ozgurshn
ozgurshn / IBInspectableGradient.swift
Last active February 27, 2017 21:58
Live gradient rendering on XCode Storyboard with IBInspectable
import UIKit
@IBDesignable
class CustomView: UIView {
@IBInspectable var gradient:Bool = false {
didSet {
if gradient
{
let topColor = UIColor(red: 3/256, green: 51/256, blue: 75/256, alpha: 1.0)
@ozgurshn
ozgurshn / RoundedView.swift
Created February 27, 2017 22:00
Set corderRadius on XCode StoryBoard
import UIKit
@IBDesignable
class CustomView: UIView {
@IBInspectable var cornerRadius: CGFloat = 0 {
didSet {
layer.cornerRadius = cornerRadius
layer.masksToBounds = cornerRadius > 0
}
@ozgurshn
ozgurshn / RoundedandGradient.swift
Created February 27, 2017 23:24
IBInspectable for Rounded and Gradient UIView
import UIKit
@IBDesignable
class CustomView: UIView {
var fromColor: UIColor?
var toColor: UIColor?
var gradientLayer: CAGradientLayer?
@ozgurshn
ozgurshn / DrawRoutesonMapKit.swift
Last active June 18, 2017 14:13
Draw route between two core location point
func drawRoutes(sourceLocation:CLLocationCoordinate2D , destinationLocation:CLLocationCoordinate2D)
{
let sourcePlacemark = MKPlacemark(coordinate: sourceLocation, addressDictionary: nil)
let destinationPlacemark = MKPlacemark(coordinate: destinationLocation, addressDictionary: nil)
let sourceMapItem = MKMapItem(placemark: sourcePlacemark)
let destinationMapItem = MKMapItem(placemark: destinationPlacemark)
@ozgurshn
ozgurshn / ProtocolWithDelegateOutlet.swift
Last active June 18, 2017 14:13
Protocol with Delegate Outlet to use directly in Storyboard
@objc protocol LocationSelectorDelegate: class {
func showMap(tag: Int)
}
@IBDesignable
class LocationSelectorView: UIView {
@IBOutlet weak var delegate: LocationSelectorDelegate?
@ozgurshn
ozgurshn / resnetModelGetModel.py
Last active June 21, 2018 22:39
Resnet50 model fine-tuned
def get_model():
input_tensor = Input(shape=(224, 224, 3)) # this assumes K.image_data_format() == 'channels_last'
# create the base pre-trained model
base_model = ResNet50(input_tensor=input_tensor,weights='imagenet',include_top=False)
for layer in base_model.layers:
layer.trainable=False
def compile_model(compiledModel):
compiledModel.compile(loss=keras.losses.categorical_crossentropy,
optimizer=Adadelta(),
metrics=['accuracy'])
def modelFitGenerator(fitModel):
num_train_samples = sum([len(files) for r, d, files in os.walk(train_data_dir)])
num_valid_samples = sum([len(files) for r, d, files in os.walk(validation_data_dir)])
num_train_steps = math.floor(num_train_samples/batch_size)
num_valid_steps = math.floor(num_valid_samples/batch_size)
train_datagen = ImageDataGenerator(
rotation_range=90,
def saveCoreMLModel(kerasModel):
coreml_model = coremltools.converters.keras.convert(kerasModel,
input_names=['input'],
output_names=['probs'],
image_input_names='input',
predicted_feature_name='predictedMoney',
class_labels = 'drive/Resnet/labels.txt')
coreml_model.save('resnet50custom.mlmodel')
print('CoreML model saved')