This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
| { | |
| "extends": "expo-module-scripts/tsconfig.plugin", | |
| "compilerOptions": { | |
| "outDir": "build", | |
| "rootDir": "src" | |
| }, | |
| "include": ["./src"], | |
| "exclude": ["**/__mocks__/*", "**/__tests__/*"] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ExpoModulesCore | |
| public class Yolov8ClassifyModule: Module { | |
| public func definition() -> ModuleDefinition { | |
| Name("Yolov8Classify") | |
| View(Yolov8ClassifyView.self) { | |
| Events("onResult") | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import ExpoModulesCore | |
| import Vision | |
| import WebKit | |
| import UIKit | |
| import AVFoundation | |
| enum Yolov8ClassifyViewError: Error { | |
| case mlModelNotFound | |
| case mlModelLoadingFailed(Error) | |
| case videoDeviceInputCreationFailed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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__': |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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(), | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// 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>>, | |
| } |
NewerOlder