-
Notifications
You must be signed in to change notification settings - Fork 3
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
code clean up on backend ec2, push up to end of SP23 #51
Open
emerisly
wants to merge
7
commits into
main
Choose a base branch
from
code-clean-up
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d3c95ec
code clean up, push up to end of SP23
xforeverjlx 9c0b906
Merge branch 'main' into code-clean-up
emerisly 4cf4d6c
Delete ml-model/yolov5/tests3.py
emerisly 7f931b3
Delete ml-model/model/image_to_latex.py
emerisly f2a216c
Delete ml-model/model/latex_to_tree.py
emerisly 4ec6250
Delete ml-model/yolov5/main.py
emerisly 33c9553
delete dataset folder
emerisly 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
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,22 @@ | ||
from rapid_latex_ocr import LatexOCR | ||
|
||
image_resizer_path = 'models/image_resizer.onnx' | ||
encoder_path = 'models/encoder.onnx' | ||
decoder_path = 'models/decoder.onnx' | ||
tokenizer_json = 'models/tokenizer.json' | ||
model = LatexOCR(image_resizer_path=image_resizer_path, | ||
encoder_path=encoder_path, | ||
decoder_path=decoder_path, | ||
tokenizer_json=tokenizer_json) | ||
|
||
img_path = "tests/test_files/6.png" | ||
with open(img_path, "rb") as f: | ||
data = f. read() | ||
|
||
result, elapse = model(data) | ||
|
||
print(result) | ||
# {\frac{x^{2}}{a^{2}}}-{\frac{y^{2}}{b^{2}}}=1 | ||
|
||
print(elapse) | ||
# 0.4131628000000003 |
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,93 @@ | ||
import sympy as sp | ||
from sympy.parsing.latex import parse_latex | ||
from zss import Node, distance | ||
import networkx as nx | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
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. Delete this file as well |
||
def zss_to_nx(node, graph=None, parent=None): | ||
if graph is None: | ||
graph = nx.DiGraph() | ||
graph.add_node(id(node), label=node.label) | ||
if parent is not None: | ||
graph.add_edge(id(parent), id(node)) | ||
for child in node.children: | ||
zss_to_nx(child, graph, node) | ||
return graph | ||
|
||
|
||
# Define some complex LaTeX expressions | ||
# expr1 represents our query | ||
latex_expr1 = r"\nabla J(\theta) = \frac{1}{m} \sum_{i=1}^m (h_\theta(x^{(i)}) - y^{(i)}) x^{(i)}" | ||
# expr represents our OCR'd expression from the file | ||
latex_expr2 = r"\nabla J(\Theta) = \frac{1}{m} \sum_{i=1}^m (h_\theta(z^{(i)}) - y^{(i)}) z^{(i)}" | ||
|
||
# Convert LaTeX to SymPy | ||
sympy_expr1 = parse_latex(latex_expr1) | ||
sympy_expr2 = parse_latex(latex_expr2) | ||
|
||
|
||
def sympy_to_zss(expr): | ||
if isinstance(expr, sp.Symbol) or isinstance(expr, sp.Number): | ||
return Node(str(expr)) | ||
else: | ||
node = Node(str(expr.func)) | ||
for arg in expr.args: | ||
child_node = sympy_to_zss(arg) | ||
node.addkid(child_node) | ||
return node | ||
|
||
|
||
# Convert the SymPy expression to a ZSS tree | ||
zss_tree1 = sympy_to_zss(sympy_expr1) | ||
zss_tree2 = sympy_to_zss(sympy_expr2) | ||
# print(zss_tree1) | ||
# print(zss_tree2) | ||
|
||
# Assuming zss_tree1 and zss_tree2 are your ZSS trees | ||
nx_tree1 = zss_to_nx(zss_tree1) | ||
nx_tree2 = zss_to_nx(zss_tree2) | ||
|
||
|
||
def hierarchy_pos(G, root=None, width=1., vert_gap=0.2, vert_loc=0, xcenter=0.5): | ||
pos = _hierarchy_pos(G, root, width, vert_gap, vert_loc, xcenter) | ||
return pos | ||
|
||
|
||
def _hierarchy_pos(G, root, width=1., vert_gap=0.2, vert_loc=0, xcenter=0.5, pos=None, parent=None, parsed=[]): | ||
if pos is None: | ||
pos = {root: (xcenter, vert_loc)} | ||
else: | ||
pos[root] = (xcenter, vert_loc) | ||
children = list(G.neighbors(root)) | ||
if not isinstance(G, nx.DiGraph) and parent is not None: | ||
children.remove(parent) | ||
if len(children) != 0: | ||
dx = width / len(children) | ||
nextx = xcenter - width/2 - dx/2 | ||
for child in children: | ||
nextx += dx | ||
pos = _hierarchy_pos(G, child, width=dx, vert_gap=vert_gap, | ||
vert_loc=vert_loc-vert_gap, xcenter=nextx, | ||
pos=pos, parent=root, parsed=parsed) | ||
return pos | ||
|
||
|
||
def draw_tree(tree): | ||
pos = hierarchy_pos(tree, root=list(tree.nodes()) | ||
[0]) # Specify the root node | ||
labels = nx.get_node_attributes(tree, 'label') | ||
nx.draw(tree, pos, labels=labels, with_labels=True, | ||
node_size=3000, node_color='lightblue', font_size=10) | ||
plt.show() | ||
|
||
|
||
# Draw the trees | ||
# draw_tree(nx_tree1) | ||
# draw_tree(nx_tree2) | ||
|
||
# Compare ZSS trees | ||
# make update non-zero to see difference in more updated tree vs. not | ||
distance = distance(zss_tree1, zss_tree2, get_children=Node.get_children, | ||
insert_cost=lambda node: 10, remove_cost=lambda node: 10, update_cost=lambda a, b: 1) | ||
print(distance) # Output the tree edit distance |
Oops, something went wrong.
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.
Can you delete this files from the PR? Lots of people have made changes on these files and will screw it up