This repository has been archived by the owner on Nov 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #363 from flojoy-ai/update-node-docs-234
[WIP] TORCHSCRIPT_CLASSIFIER node for any user-provided .torchscript AI model - nodes PR:234
- Loading branch information
Showing
45 changed files
with
2,812 additions
and
577 deletions.
There are no files selected for viewing
22 changes: 17 additions & 5 deletions
22
docs/nodes/AI_ML/CLASSIFICATION/ONE_HOT_ENCODING/a1-[autogen]/docstring.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
The ONE_HOT_ENCODING node creates a one hot encoding from a dataframe containing categorical features. | ||
|
||
The ONE_HOT_ENCODING node creates a one hot encoding from a dataframe and columns dataframe containing categorical features. | ||
Inputs | ||
------ | ||
data : DataFrame | ||
The input dataframe containing the categorical features. | ||
|
||
Returns | ||
------- | ||
DataFrame | ||
The one hot encoding of the input features. | ||
Parameters | ||
---------- | ||
feature_col: DataFrame, optional | ||
A dataframe whose columns are used to create the one hot encoding. | ||
For example, if 'data' has columns ['a', 'b', 'c'] and 'feature_col' has columns ['a', 'b'], | ||
then the one hot encoding will be created only for columns ['a', 'b'] against 'data'. | ||
Defaults to None, meaning that all columns of categorizable objects are encoded. | ||
|
||
Returns | ||
------- | ||
DataFrame | ||
The one hot encoding of the input features. |
59 changes: 59 additions & 0 deletions
59
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/TORCHSCRIPT_CLASSIFIER.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
[//]: # (Custom component imports) | ||
|
||
import DocString from '@site/src/components/DocString'; | ||
import PythonCode from '@site/src/components/PythonCode'; | ||
import AppDisplay from '@site/src/components/AppDisplay'; | ||
import SectionBreak from '@site/src/components/SectionBreak'; | ||
import AppendixSection from '@site/src/components/AppendixSection'; | ||
|
||
[//]: # (Docstring) | ||
|
||
import DocstringSource from '!!raw-loader!./a1-[autogen]/docstring.txt'; | ||
import PythonSource from '!!raw-loader!./a1-[autogen]/python_code.txt'; | ||
|
||
<DocString>{DocstringSource}</DocString> | ||
<PythonCode GLink='AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/TORCHSCRIPT_CLASSIFIER.py'>{PythonSource}</PythonCode> | ||
|
||
<SectionBreak /> | ||
|
||
|
||
|
||
[//]: # (Examples) | ||
|
||
## Examples | ||
|
||
import Example1 from './examples/EX1/example.md'; | ||
import App1 from '!!raw-loader!./examples/EX1/app.json'; | ||
import appImg from './examples/EX1/app.jpeg' | ||
import outputImg from './examples/EX1/output.jpeg' | ||
|
||
|
||
|
||
<AppDisplay | ||
nodeLabel='TORCHSCRIPT_CLASSIFIER' | ||
appImg={appImg} | ||
outputImg={outputImg} | ||
> | ||
{App1} | ||
</AppDisplay> | ||
|
||
<Example1 /> | ||
|
||
<SectionBreak /> | ||
|
||
|
||
|
||
[//]: # (Appendix) | ||
|
||
import Notes from './appendix/notes.md'; | ||
import Hardware from './appendix/hardware.md'; | ||
import Media from './appendix/media.md'; | ||
|
||
## Appendix | ||
|
||
<AppendixSection index={0} folderPath='nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/appendix/'><Notes /></AppendixSection> | ||
<AppendixSection index={1} folderPath='nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/appendix/'><Hardware /></AppendixSection> | ||
<AppendixSection index={2} folderPath='nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/appendix/'><Media /></AppendixSection> | ||
|
||
|
19 changes: 19 additions & 0 deletions
19
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/a1-[autogen]/docstring.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
Execute a torchscript classifier against an input image. | ||
|
||
Inputs | ||
---------- | ||
input_image : Image | ||
The image to classify. | ||
class_names : DataFrame | ||
A dataframe containing the class names. | ||
|
||
Parameters | ||
---------- | ||
model_path : str | ||
The path to the torchscript model. | ||
|
||
Returns | ||
---------- | ||
DataFrame | ||
A dataframe containing the class name and confidence score. |
51 changes: 51 additions & 0 deletions
51
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/a1-[autogen]/python_code.txt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from flojoy import flojoy, run_in_venv, Image, DataFrame | ||
|
||
|
||
@flojoy | ||
@run_in_venv( | ||
pip_dependencies=[ | ||
"torch==2.0.1", | ||
"torchvision==0.15.2", | ||
"numpy", | ||
"Pillow", | ||
] | ||
) | ||
def TORCHSCRIPT_CLASSIFIER( | ||
input_image: Image, class_names: DataFrame, model_path: str | ||
) -> DataFrame: | ||
|
||
|
||
import torch | ||
import torchvision | ||
import pandas as pd | ||
import numpy as np | ||
import PIL.Image | ||
|
||
# Load model | ||
model = torch.jit.load(model_path) | ||
channels = [input_image.r, input_image.g, input_image.b] | ||
mode = "RGB" | ||
|
||
if input_image.a is not None: | ||
channels.append(input_image.a) | ||
mode += "A" | ||
|
||
input_image_pil = PIL.Image.fromarray( | ||
np.stack(channels).transpose(1, 2, 0), mode=mode | ||
).convert("RGB") | ||
input_tensor = torchvision.transforms.functional.to_tensor( | ||
input_image_pil | ||
).unsqueeze(0) | ||
|
||
# Run model | ||
with torch.inference_mode(): | ||
output = model(input_tensor) | ||
|
||
# Get class name and confidence score | ||
_, pred = torch.max(output, 1) | ||
class_name = class_names.m.iloc[pred.item()].item() | ||
confidence = torch.nn.functional.softmax(output, dim=1)[0][pred.item()].item() | ||
|
||
return DataFrame( | ||
df=pd.DataFrame({"class_name": [class_name], "confidence": [confidence]}) | ||
) |
1 change: 1 addition & 0 deletions
1
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/appendix/hardware.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This node does not require any peripheral hardware to operate. Please see INSTRUMENTS for nodes that interact with the physical world through connected hardware. |
1 change: 1 addition & 0 deletions
1
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/appendix/media.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No supporting screenshots, photos, or videos have been added to the media.md file for this node. |
1 change: 1 addition & 0 deletions
1
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/appendix/notes.md
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No theory or technical notes have been contributed for this node yet. |
Binary file added
BIN
+715 KB
docs/nodes/AI_ML/CLASSIFICATION/TORCHSCRIPT_CLASSIFIER/examples/EX1/app.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.