Skip to content

Instantly share code, notes, and snippets.

View hietalajulius's full-sized avatar

Julius Hietala hietalajulius

View GitHub Profile
{
"extends": "expo-module-scripts/tsconfig.plugin",
"compilerOptions": {
"outDir": "build",
"rootDir": "src"
},
"include": ["./src"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
}
import { withInfoPlist, ConfigPlugin } from "expo/config-plugins";
const withCameraUsageDescription: ConfigPlugin<{
cameraUsageDescription?: string;
}> = (config, { cameraUsageDescription }) => {
config = withInfoPlist(config, (config) => {
config.modResults["NSCameraUsageDescription"] =
cameraUsageDescription ??
"The camera is used to stream video for classification.";
return config;
require 'json'
package = JSON.parse(File.read(File.join(__dir__, '..', 'package.json')))
Pod::Spec.new do |s|
s.name = 'Yolov8Classify'
s.version = package['version']
s.summary = package['description']
s.description = package['description']
s.license = package['license']
import ExpoModulesCore
public class Yolov8ClassifyModule: Module {
public func definition() -> ModuleDefinition {
Name("Yolov8Classify")
View(Yolov8ClassifyView.self) {
Events("onResult")
}
}
import ExpoModulesCore
import Vision
import WebKit
import UIKit
import AVFoundation
enum Yolov8ClassifyViewError: Error {
case mlModelNotFound
case mlModelLoadingFailed(Error)
case videoDeviceInputCreationFailed
@hietalajulius
hietalajulius / yolo_executorch_export.py
Created June 2, 2024 06:36
YOLO executorch export
from ultralytics import YOLO
import torch
def main():
model = YOLO("yolov8n.pt")
example_input = torch.ones((1, 3, 640, 640))
exported_program = torch.export.export(model, (example_input,))
print(exported_program)
if __name__ == '__main__':
/// Perform backward pass through the linear layer.
fn backward(&mut self, dL_dy: &Array2<f64>) -> Array2<f64> {
// Calculate the gradient of the loss with respect to W
let dL_dW = dL_dy.t().dot(
&self
.dy_dW
.as_ref()
.expect("Need to call forward() first.")
.view(),
);
/// Perform forward pass through the linear layer.
fn forward(&mut self, x: &Array2<f64>) -> Array2<f64> {
// Store the input gradient for later use in backward pass
self.dy_dW = Some(x.to_owned());
self.get_output(x)
}
/// Get the output of the linear layer.
fn get_output(&self, x: &Array2<f64>) -> Array2<f64> {
// Formula: (W * x^T + b)^T
(self.W.dot(&x.t()) + self.b.clone()).t().to_owned()
}
/// LinearLayer represents a linear layer in a neural network.
pub struct LinearLayer {
pub W: Array2<f64>,
pub b: Array2<f64>,
// Gradient of the loss
pub dL_dW: Option<Array2<f64>>,
pub dL_db: Option<Array2<f64>>,
// Gradient of the output
pub dy_dW: Option<Array2<f64>>,
}