Skip to content

Instantly share code, notes, and snippets.

View pranjalsatija's full-sized avatar

Pranjal Satija pranjalsatija

View GitHub Profile
import os
import turicreate as tc
import xml.etree.cElementTree as XMLParser
# Takes the XML for a bounding box and returns a Dictionary containing the center X and Y coordinates of the box,
# along with its width and height.
def get_bounding_box(xml):
box = xml.find('bndbox')
x_min, x_max = float(box.find('xmin').text), float(box.find('xmax').text)
import os
import turicreate as tc
path = '../' # The path to the root of your project directory.
sf_path = os.path.join(path, 'data.sframe') # The path to load the SFrame from. See `gen_sframe.py` for more.
data = tc.SFrame(sf_path) # The training data for our model.
# This takes the first 50 rows from the SFrame we just loaded from disk and drops the rest of it. We do this so the
# visualization doesn't take too long to load and run.
data = data.head(50)
import os
import turicreate as tc
path = '../' # The path to the root of your project directory.
coreml_path = os.path.join(path, 'pascal.mlmodel') # The path to export the Core ML model to.
model_path = os.path.join(path, 'pascal.model') # The path to export the .model file to.
sf_path = os.path.join(path, 'data.sframe') # The path to load the SFrame from. See gen_sframe.py for more.
result_sf_path = os.path.join(path, 'result_data.sframe') # The path to save the test data with predictions to.
data = tc.SFrame(sf_path) # The training data for our model.
import os
import turicreate as tc
path = '../' # The path to the root of your project directory.
model_path = os.path.join(path, 'pascal.model') # The path to the trained model. See train_model.py for more.
result_sf_path = os.path.join(path, 'result_data.sframe') # The path to the result data from training the model.
# Loads the result data from training the model, along with the model itself.
data = tc.SFrame(result_sf_path)
model = tc.load_model(model_path)
pranjal:app $ flutter run --verbose
[ +35 ms] executing: [/Users/pranjal/flutter/] git log -n 1 --pretty=format:%H
[ +41 ms] Exit code 0 from: git log -n 1 --pretty=format:%H
[ ] 7a4c33425ddd78c54aba07d86f3f9a4a0051769b
[ ] executing: [/Users/pranjal/flutter/] git describe --match v*.*.* --first-parent --long --tags
[ +18 ms] Exit code 0 from: git describe --match v*.*.* --first-parent --long --tags
[ ] v1.5.4-hotfix.2-0-g7a4c33425
[ +14 ms] executing: [/Users/pranjal/flutter/] git rev-parse --abbrev-ref --symbolic @{u}
[ +11 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[ ] origin/stable
@pranjalsatija
pranjalsatija / SwiftUI List.swift
Last active February 7, 2020 18:31
A simple example of constructing a list in SwiftUI.
List(data, id: \.self) {
Text($0)
}
@pranjalsatija
pranjalsatija / UITableViewCoordinator.swift
Created February 7, 2020 18:41
A simple example of conformance to UITableViewDataSource and UITableViewDelegate.
class UITableViewCoordinator: UITableViewDataSource, UITableViewDelegate {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "identifier") as! Cell
// configure it
return cell
}
@pranjalsatija
pranjalsatija / Static Example.swift
Created February 7, 2020 20:30
A simple example of using Static to populate a table view.
let dataSource = DataSource()
dataSource.sections = [
Section(rows: [
Row(text: "Hello")
])
]
dataSource.tableView = tableView
@pranjalsatija
pranjalsatija / UITableView Abstraction.swift
Last active February 8, 2020 00:20
A theoretical example of a "perfect" abstraction over UITableViewDataSource and UITableViewDelegate.
tableView.descriptor = UITableViewDescriptor(sections: [
UITableViewSection(
items: $data,
cellProvider: {(tableView, indexPath, element) in
let cell = Cell.dequeue(in: tableView)
cell.configure(with: element)
return cell
}
)
@pranjalsatija
pranjalsatija / UITableViewSection.swift
Last active February 8, 2020 00:22
A simple implementation for UITableViewSection.
class UITableViewSection: NSObject {
private(set) var items = [AnyHashable]()
private(set) var sectionIndex: Int!
private let itemsPublisher: AnyPublisher<[AnyHashable], Never>
private let cellProvider: (UITableView, IndexPath, AnyHashable) -> UITableViewCell
private var subscriptions = Set<AnyCancellable>()
convenience init<T: Hashable>(