-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module standardization #32
Merged
Merged
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9fe7cae
add publish gh actions
Rob1in 4e1648c
Merge remote-tracking branch 'upstream/main' into gh_actions
Rob1in 7078d66
change exit
Rob1in 19edc32
Merge remote-tracking branch 'upstream/main' into gh_actions
Rob1in a8c8e43
...
Rob1in 54ecb77
add linting and testing
Rob1in fdbf115
fix requirements
Rob1in c14f64d
fix requirements
Rob1in c61d2a4
add testing files and fix requirements
Rob1in c82cdb1
update chirac
Rob1in e49504e
publish
Rob1in 8463865
add test workflow
Rob1in 828786c
update README
Rob1in d04e4ad
fix distance
Rob1in 4a0569c
fix distance2
Rob1in b630049
remove some linting disabled
Rob1in File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Empty file.
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 |
---|---|---|
|
@@ -5,5 +5,4 @@ src/__pycache__ | |
src/data | ||
.vscode | ||
venv | ||
benchmark/ | ||
test_* | ||
benchm |
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,2 +1,8 @@ | ||
module.tar.gz: | ||
tar czf $@ --exclude='.DS_Store' *.sh .env src/*.py src/models/*.py src/models/checkpoints/*.pt src/models/checkpoints/*.onnx requirements.txt | ||
|
||
test: | ||
python3 -m pytest tests/* | ||
|
||
lint: | ||
python3 -m pylint src --disable=W0719,C0114,W0201,W1203,E1101,W1203,E0611,R0902,R0913,E0611,E0001,R0914,R0903 | ||
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
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
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,9 +1,24 @@ | ||
viam-sdk>=0.21 | ||
onnx2torch | ||
|
||
numpy | ||
torch | ||
|
||
torch; sys_platform == 'darwin' | ||
torch==2.2.2+cpu; sys_platform == 'linux' | ||
-f https://download.pytorch.org/whl/cpu/torch_stable.html | ||
|
||
torchvision == 0.18; sys_platform == 'darwin' | ||
torchvision==0.17.2+cpu;sys_platform == 'linux' | ||
-f https://download.pytorch.org/whl/cpu/torch_stable.html | ||
|
||
pyinstaller | ||
torchvision | ||
|
||
facenet-pytorch | ||
opencv-python | ||
pillow | ||
|
||
|
||
##for testing | ||
pytest | ||
pytest-asyncio | ||
pylint |
Empty file.
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,20 +1,51 @@ | ||
from torch.nn import CosineSimilarity | ||
import torch.nn.functional as F | ||
from torch import Tensor | ||
import numpy as np | ||
import torch.nn.functional as F | ||
from torch.nn import CosineSimilarity | ||
|
||
|
||
def euclidean_distance(t1, t2): | ||
""" | ||
Computes the Euclidean distance between two tensors using the L1 norm. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Euclidean usually means the L2 norm, not L1 -- the L1 norm is colloquially called the "manhattan" or "taxicab" norm |
||
|
||
Args: | ||
t1 (torch.Tensor): The first tensor. | ||
t2 (torch.Tensor): The second tensor. | ||
|
||
Returns: | ||
float: The Euclidean distance between the two tensors. | ||
""" | ||
return F.pairwise_distance(t1, t2, p=1).item() # pylint: disable=not-callable | ||
|
||
def euclidean_distance(t1,t2): | ||
return F.pairwise_distance(t1,t2, p=1).item() | ||
|
||
def euclidean_l2_distance(t1, t2): | ||
if isinstance(t1, np.ndarray) and isinstance(t2, np.ndarray): | ||
euclidean_distance = t2 - t1 | ||
euclidean_distance = np.sum(np.multiply(euclidean_distance, euclidean_distance)) | ||
euclidean_distance = np.sqrt(euclidean_distance) | ||
return euclidean_distance | ||
else: | ||
return F.pairwise_distance(t1,t2).item() | ||
""" | ||
Computes the Euclidean distance between two tensors or numpy arrays using the L2 norm. | ||
|
||
Args: | ||
t1 (torch.Tensor or numpy.ndarray): The first tensor or numpy array. | ||
t2 (torch.Tensor or numpy.ndarray): The second tensor or numpy array. | ||
|
||
Returns: | ||
float: The Euclidean distance between the two inputs. | ||
""" | ||
if isinstance(t1, np.ndarray) and isinstance(t2, np.ndarray): | ||
euc_distance = t2 - t1 | ||
euc_distance = np.sum(np.multiply(euc_distance, euc_distance)) | ||
euc_distance = np.sqrt(euc_distance) | ||
return euc_distance | ||
return F.pairwise_distance(t1, t2).item() # pylint: disable=not-callable | ||
|
||
|
||
def cosine_distance(t1, t2): | ||
""" | ||
Computes the cosine distance between two tensors. | ||
|
||
Args: | ||
t1 (torch.Tensor): The first tensor. | ||
t2 (torch.Tensor): The second tensor. | ||
|
||
Returns: | ||
float: The cosine distance between the two tensors. | ||
""" | ||
cos_sim = CosineSimilarity(dim=0, eps=1e-6) | ||
return 1-cos_sim(t1, t2).item() | ||
return 1 - cos_sim(t1, t2).item() |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C0114: Missing module docstring
W0201: Attribute defined outside init
W1203: Use % formatting in logging functions and pass the % parameters as arguments
E1101: Instance of 'x' has no 'y' member
E0611: No name 'x' in module 'y'
E0001: Syntax error
R0801: Similar lines in 'x' files
Remove these from the disable string, and if you do need to disable them, put the ignore right next to the code where you need it