Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehova committed Apr 2, 2022
1 parent 2d0aed1 commit 3fa4771
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 4 deletions.
28 changes: 28 additions & 0 deletions tech/tensorflow/machine-learning.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,31 @@
* TensorFlow Lite: Google's ML framework that focuses on mobile native and IoT devices. **Note:** TensorflowJS can also run on these platforms but TensorFlow Lite is optimized for them.
* ONNX: The Open Neural Network Exchange is an open-source AI ecosystem of tech companies and research orgs. ONNX establishes open standards for representing ML algorithms in a way agnostic to the library it was written in.

## Selecting a Model
* Understand the problem by asking the client questions:
* What type of app does the customer need
* is it a web app? does it need to run on the client-side or the server-side?
* how important is privacy, speed, accuracy?
* Populate the list of models that can be used to solve the problem
* Use Inference speed (lower the better), file size of the model, RAM in MB to compare models
* calc inference speed:
```
async function calculateInferenceSpeed() {
// Record timestamp before model execution
const timeStart = performance.now();
// Execute model
let results = await useSomeModel();
// Record timestamp after model execution
const timeEnd = performance.now();
// Calculate time taken for model execution
const timeTaken = timeEnd - timeStart;
console.log(`Time taken ${timeTaken} ms.`);
// Convert ms to FPS
console.log(`Frames per sec: ${1000 / timeTaken}`);
}
```
* file size: check model's documentation or pull up the model and look at file size on chrome dev tools
* models are json or bin files. add up all the json/bin files that re pulled down and you have your model size
* Use memory tab in chrome dev tools
* load the model, go to memory tab, click create snapshot => view total ram in the statistics drop down option
22 changes: 22 additions & 0 deletions tech/tensorflow/template/hello-world/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Hello World - TensorFlow.js</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Import the webpage's stylesheet -->
<link rel="stylesheet" href="/style.css">
</head>
<body>
<h1>TensorFlow.js Hello World</h1>

<p id="status">Awaiting TF.js load</p>

<!-- Import TensorFlow.js library -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js" type="text/javascript"></script>

<!-- Import the page's JavaScript to do some stuff -->
<script src="/script.js" defer></script>
</body>
</html>
20 changes: 20 additions & 0 deletions tech/tensorflow/template/hello-world/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/

const status = document.getElementById('status');
status.innerText = 'Loaded TensorFlow.js - version: ' + tf.version.tfjs;

29 changes: 29 additions & 0 deletions tech/tensorflow/template/hello-world/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @license
* Copyright 2018 Google LLC. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* =============================================================================
*/

/* CSS files add styling rules to your content */

body {
font-family: helvetica, arial, sans-serif;
margin: 2em;
}

h1 {
font-style: italic;
color: #FF6F00;
}

75 changes: 75 additions & 0 deletions tech/tensorflow/tensor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Tensor

## What
* Primary data structure in tensorflow models
* Similar to arrays that can have multiple dimensions. **ONLY contain numerical data**
* ML models take tensors as inputs and output tensors
* Tensor is a class
* Need to explicitly dispose tensors when they are no longer needed
* tf.dispose() => to destroy a specific tensor
* tf.tidy() => dispose any tensor(s) created in the same function
* Terminology:
* DataType (DType) => either integer or floating point
* Shape => Number of elements present along each axis of the tensor (a cube would have a shape of [3,3,3] if it had 3 elements on each axis)
* Rank => # of "Axis" in the tensor. 6 Axis is max number tensorflow handles
* Size => total elements in the tensor
* Example:
* 0 Dimensions:
```
// js 0 dimension
let value = 6;

// tf 0 dimension
let tensor = tf.scalar(6);
```
* 1 Dimensional: example as a x,y,x coordinates on a 3 dimensional plane
```
// js 1 dimension
let value = [1,2,3];
// tf 1 dimension.
let tensor = tf.tensor1d([1,2,3]);
```
* 2 Dimensional: example grayscale image
```
// js 2 dimension
let values = [
[1,2,3],
[4,5,6],
[7,8,9]
]
// tf 2 dimensional
let tensor = tf.tensor2d([
[1,2,3],
[4,5,6],
[7,8,9]
]);
```
* 3 Dimensiona: exmaple rgb image where each pixel would need a rgb array value
* 4 Dimensional: example video where the rgb images above now have a time component associated with it
## Code
```
/**
* Line below creates a 2D tensor.
* Printing its values at this stage would give you:
* Rank: 2, shape: [2,3], values: [[1, 2, 3], [4, 5, 6]]
**/
let tensor = tf.tensor2d([[1, 2, 3], [4, 5 ,6]]);

// Create a Tensor holding a single scalar value:
let scalar = tf.scalar(2);

// Multiply all values in tensor by the scalar value 2.
let newTensor = tensor.mul(scalar);

// Values of newTensor would be: [[2, 4, 6], [8, 10 ,12]]
newTensor.print();

// You can even change the shape of the Tensor.
// This would convert the 2D tensor to a 1D version with
// 6 elements instead of a 2D 2 by 3 shape.
let reshaped = tensor.reshape([6]);
```
18 changes: 14 additions & 4 deletions tech/tensorflow/tensorflow.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# Tensorflow

## What?
JS and Python library to develop models, train them, and use them to run ML and AI on many platforms. It is written in C++

## Common Terms
* Deep Learning results feed better Machine Learning Models. Better Machine Learning Models feed better AI.
* AI - Science of making things smart
Expand All @@ -27,7 +24,8 @@ JS and Python library to develop models, train them, and use them to run ML and
* This works by feeding the Kerans Model the Layers API. The Core/OPS API then translates the Keras Model to a TensorFlow SavedModel.

## What is it
TensorflowJS - Javascript library that contains Google's machine learning library
* JS and Python library to develop models, train them, and use them to run ML and AI on many platforms. It is written in C++
* TensorflowJS - Javascript library that contains Google's machine learning library
* Python vs Javascript
* Running Tensorflow in NodeJS allows you to leverage CUDA and AVX acceleration to perform a LOT faster than Python.
* NodeJS supports integrating with Python Keras and Tensorflow SavedModels created in Python.
Expand All @@ -44,6 +42,18 @@ TensorflowJS - Javascript library that contains Google's machine learning librar
* Interactivity - can directly interact with the library using the browser platform
* Reach & Scale - Running on a browser is basically omnipresent.

## Setup
**Note:** If using typescript, then set "skipLibCheck: true" in tsconfig.json file.
**Note:** NPM is shipped with ES Modules and ES2017 syntax
* JS
* npm install @tensorflow/tfjs
* Node:
* npm install @tensorflow/tfjs-node
* Linux with CUDA support (NVIDIA GPU)
* npm install @tensorflow/tfjs-node-gpu
* Script tag
* <script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>

## Structurte
Models --> Layers API --> Core/OPS API
* Layers API - high level api
Expand Down
14 changes: 14 additions & 0 deletions tech/twistlock/twistlock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Twistlock

## Background
When using containers, there are three primary challenges that need to be solved to ensure that your deployment is secure:
1) Access Control - Ensuring that each container follows least-access privelage
2) Inter-Container Communication - Ensuring that communication between containers is secure (authenticated)
3) App within Container - Ensuring that code within your container doesnt violate key security, that exceptions are handled properly, or contain malicious code

Twistlock is a full suite of tools to address those challenges.

On VA Notify, Twistlock is used to address challenge #3; container scanning.

## How
Twistlock is integrated into our CI/CD pipeline. When a developer commits their code to the notify repository, Github triggers a pre-commit hook that launches Twistlock in a github VM environment. Twistlock then does a scan of the user's commit and the resultant container. If no issues are found and the container score is above a specified threshold, then the code is committed and Github kicks off any post commit actions. If there ARE issues found, then the commit is rejected and the dev is notified that an error was found.
12 changes: 12 additions & 0 deletions tech/typescript/typescript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Typescript

## Common Commands:
* Setup a typescript project using [GTS](https://github.com/google/gts)
* creates a code formatter, linter, and code fixer for typescript projects.
* npx gts init
* command to compile: npm run compile
* command to lin
* Compile to JS
* npx tsc index.ts
* Activate watch command
* npx tsc -w

0 comments on commit 3fa4771

Please sign in to comment.