Skip to content

Instantly share code, notes, and snippets.

View RahulBhalley's full-sized avatar
🦅

RahulBhalley

🦅
View GitHub Profile
@rorodriguez116
rorodriguez116 / photoCaptureProcessor.swift
Created October 23, 2020 20:58
PhotoCaptureProcessor implemented AVCapturePhotoCaptureDelegate
import Photos
class PhotoCaptureProcessor: NSObject {
lazy var context = CIContext()
private(set) var requestedPhotoSettings: AVCapturePhotoSettings
private let willCapturePhotoAnimation: () -> Void
@JacopoMangiavacchi
JacopoMangiavacchi / MLCompute.swift
Last active January 15, 2021 07:14
MLCompute Playground
import Foundation
import MLCompute
import PlaygroundSupport
let page = PlaygroundPage.current
page.needsIndefiniteExecution = true
let tensor1 = MLCTensor(descriptor: MLCTensorDescriptor(shape: [6, 1], dataType: .float32)!)
let tensor2 = MLCTensor(descriptor: MLCTensorDescriptor(shape: [6, 1], dataType: .float32)!)
let tensor3 = MLCTensor(descriptor: MLCTensorDescriptor(shape: [6, 1], dataType: .float32)!)
@cweinberger
cweinberger / 1-MySQLDataConvertibleEnum.swift
Last active April 13, 2020 15:54
Auto-conform your enums types that you want to store in MySQL to `MySQLDataConvertible` and `ReflectionDecodable`. Avoids a lot of boilerplate!
/* NOTE: check out 3-MySQLDataConvertibleEnum_Better_Version.swift. */
import Fluent
import FluentMySQL
import Vapor
protocol MySQLDataConvertibleEnum: MySQLDataConvertible, ReflectionDecodable, CaseIterable { }
extension MySQLDataConvertibleEnum where Self: RawRepresentable, Self.RawValue == String {
func convertToMySQLData() -> MySQLData {
func downloadMovieLensDatasetIfNotPresent() -> String{
let localURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
let dataFolder = DatasetUtilities.downloadResource(
filename: "ml-25m",
fileExtension: "zip",
remoteRoot: URL(string: "http://files.grouplens.org/datasets/movielens/")!,
localStorageDirectory: localURL.appendingPathComponent("data/", isDirectory: true)
)
return try! String(contentsOf: dataFolder.appendingPathComponent("ratings.csv"), encoding: .utf8)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@kongzii
kongzii / model.swift
Last active January 30, 2020 07:40
Example of saving trained weights of model in the Swift For Tensorflow
import Foundation
import Python
import TensorFlow
public struct MyModel : Layer {
public var conv1d: Conv1D<Float>
public var dense1: Dense<Float>
public var dropout: Dropout<Float>
public var denseOut: Dense<Float>
@hollance
hollance / CoreML+Combine.swift
Created November 12, 2019 16:28
Using Core ML with Combine
import CoreML
import Combine
extension Publisher where Self.Output: MLFeatureProvider {
/**
Operator that lets you run a Core ML model as part of a Combine chain.
It accepts an MLFeatureProvider object as input, and, if all goes well,
returns another MLFeatureProvider with the model outputs.
@dan-zheng
dan-zheng / README.md
Last active January 4, 2020 19:47
Retroactive derivative registration in Swift (https://bugs.swift.org/browse/TF-866)

Retroactive derivative registration: register derivatives for functions in other modules.

Previously:

  • If module A defines func foo, then its derivatives must be in the same module.

With retroactive derivative registration:

  • If module A defines func foo;
  • And if module B imports module A and defines @differentiating(foo) func derivativeFoo:
  • Then module C can import modules A and B and differentiate func foo (e.g. via differentiation APIs).
@rxwei
rxwei / upstreaming-swift-autodiff.md
Last active January 28, 2020 11:06
Upstreaming Swift AutoDiff

Upstreaming Swift AutoDiff

Author: Richard Wei (rxwei@google.com) on behalf of the Swift for TensorFlow team

Last updated: October 2, 2019

Overview

The differentiable programming feature (AutoDiff) has been incubated in the 'tensorflow' branch of apple/swift since December 2017 and released as part of the Swift for TensorFlow toolchains. The Differentiable Programming Mega-Proposal, which serves as a manifesto, received general positive feedback from the community, but there is a long way between receiving conceptual approval and obtaining Swift Evolution approval of such a large feature. We would like to merge the pieces into the 'master' branch under a gate to further development and bake the feature on master, just like Apple develops its major features

@cyrilzakka
cyrilzakka / ContentView.swift
Created July 26, 2019 21:03
Simple Image Viewer using SwiftUI
//
// ContentView.swift
// Scribe
//
// Created by Cyril Zakka on 7/21/19.
// Copyright © 2019 Cyril Zakka. All rights reserved.
//
import SwiftUI
struct ContentView: View {