Skip to content

Commit

Permalink
0.539
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhky committed Aug 23, 2024
1 parent 7d0b19f commit a2cf6d4
Show file tree
Hide file tree
Showing 20 changed files with 1,625 additions and 329 deletions.
2 changes: 1 addition & 1 deletion _proc/bounding_boxes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[2;36m[08/17/24 12:55:25]\u001b[0m\u001b[2;36m \u001b[0m\u001b[2;31mWARNING \u001b[0m Unable to load torch and dependent libraries from torch-snippets. \u001b]8;id=121523;file:///Users/yeshwanth/Code/Personal/torch_snippets/torch_snippets/loader.py:108\u001b\\\u001b[2mloader.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=164102;file:///Users/yeshwanth/Code/Personal/torch_snippets/torch_snippets/loader.py:108#<module>:108\u001b\\\u001b[2m<module>:108\u001b[0m\u001b]8;;\u001b\\\n",
"\u001b[2;36m[08/23/24 18:12:57]\u001b[0m\u001b[2;36m \u001b[0m\u001b[2;31mWARNING \u001b[0m Unable to load torch and dependent libraries from torch-snippets. \u001b]8;id=185334;file:///Users/yeshwanth/Code/Personal/torch_snippets/torch_snippets/loader.py:108\u001b\\\u001b[2mloader.py\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=169396;file:///Users/yeshwanth/Code/Personal/torch_snippets/torch_snippets/loader.py:108#<module>:108\u001b\\\u001b[2m<module>:108\u001b[0m\u001b]8;;\u001b\\\n",
"\u001b[2;36m \u001b[0m Functionalities might be limited. pip install lovely-tensors in case there are torch related errors \u001b[2m \u001b[0m\n"
]
}
Expand Down
2 changes: 1 addition & 1 deletion _proc/decorators.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
"OUTPUTS:\n",
"int: 21\n",
"══════════════════════════════════════════════════════════════════\n",
"\u001b[2;36m[08/17/24 12:55:28]\u001b[0m\u001b[2;36m \u001b[0m\u001b[2;33mINFO \u001b[0m foo took \u001b[1;36m1.01\u001b[0m seconds to execute \u001b]8;id=866065;file://<ipython-input-1-6ac2073623b5>:47\u001b\\\u001b[2m<ipython-input-1-6ac2073623b5>\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=883885;file://<ipython-input-1-6ac2073623b5>:47#wrapper:47\u001b\\\u001b[2mwrapper:47\u001b[0m\u001b]8;;\u001b\\\n"
"\u001b[2;36m[08/23/24 18:13:00]\u001b[0m\u001b[2;36m \u001b[0m\u001b[2;33mINFO \u001b[0m foo took \u001b[1;36m1.00\u001b[0m seconds to execute \u001b]8;id=60504;file://<ipython-input-1-6ac2073623b5>:47\u001b\\\u001b[2m<ipython-input-1-6ac2073623b5>\u001b[0m\u001b]8;;\u001b\\\u001b[2m:\u001b[0m\u001b]8;id=369021;file://<ipython-input-1-6ac2073623b5>:47#wrapper:47\u001b\\\u001b[2mwrapper:47\u001b[0m\u001b]8;;\u001b\\\n"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions _proc/jupyter_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -219,15 +219,15 @@
"### display_dfs_side_by_side\n",
"\n",
"> display_dfs_side_by_side (*args, titles=<itertools.cycle object at\n",
"> 0x137427a00>, max_rows=50)"
"> 0x13fd9b3c0>, max_rows=50)"
],
"text/plain": [
"---\n",
"\n",
"### display_dfs_side_by_side\n",
"\n",
"> display_dfs_side_by_side (*args, titles=<itertools.cycle object at\n",
"> 0x137427a00>, max_rows=50)"
"> 0x13fd9b3c0>, max_rows=50)"
]
},
"execution_count": 6,
Expand Down
476 changes: 431 additions & 45 deletions _proc/misc.ipynb

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
# Changelog
#### 0.539
✨ set `AD_SHOW_TAB_STOPS` env variable to anything to print with tab-stops (only recommended to see on REPL. Default is good for storing files)
`crop_from_bb` has `padding` (px,py,pX,pY)
🐞 minor bugfix in `AD`
🎉 `AD` has a `fetch2` which preserves json structure while fetching all the leafs of the same name
🎉 `AD` has a `flatten` which flattens all nested jsons into flat dictionary with '.' combined key names
🎉 `AD` has a `flatten_and_make_dataframe` which creates one column for each nesting
`tryy` will store all its errors and can be accessed by calling `<func>.error_summary()`
🎉 torch snippets as a new cli function called `ts`, thanks to the wonderful `Typer`. Try
`ts time`
`ts zen-of python`
`ts zen-of c++`
`ts --help`

#### 0.538.1
✨ slightly better error printing in `tryy`

Expand Down
521 changes: 467 additions & 54 deletions nbs/misc.ipynb

Large diffs are not rendered by default.

683 changes: 472 additions & 211 deletions scripts.ipynb

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ author = Yeshwanth Reddy
author_email = 1992chinna@gmail.com
copyright = sizhky
branch = master
version = 0.538.1
version = 0.539
min_python = 3.7
audience = Developers
language = English
custom_sidebar = False
license = apache2
status = 2
requirements = fastcore matplotlib Pillow altair dill ipython loguru numpy pandas tqdm rich PyYAML catalogue confection pydantic typing srsly typing_extensions wasabi jsonlines imgaug>=0.4.0 xmltodict fuzzywuzzy scikit-learn nltk python-Levenshtein pre-commit pymupdf nbconvert nbformat icecream mergedeep
requirements = fastcore matplotlib Pillow altair dill ipython loguru numpy pandas tqdm rich PyYAML catalogue confection pydantic typing srsly typing_extensions wasabi jsonlines imgaug>=0.4.0 xmltodict fuzzywuzzy scikit-learn nltk python-Levenshtein pre-commit pymupdf nbconvert nbformat icecream mergedeep typer
nbs_path = nbs
doc_path = docs
doc_host = https://%(user)s.github.io
doc_baseurl = /%(lib_name)s/
git_url = https://github.com/%(user)s/%(lib_name)s/tree/%(branch)s/
lib_path = %(lib_name)s
title = %(lib_name)s
console_scripts = ts=torch_snippets.cli:cli
3 changes: 2 additions & 1 deletion torch_snippets.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: torch_snippets
Version: 0.538.1
Version: 0.539
Summary: One line functions for common tasks
Home-page: https://github.com/sizhky/torch_snippets/tree/master/
Author: Yeshwanth Reddy
Expand Down Expand Up @@ -49,6 +49,7 @@ Requires-Dist: nbconvert
Requires-Dist: nbformat
Requires-Dist: icecream
Requires-Dist: mergedeep
Requires-Dist: typer

# Utilities for simple needs

Expand Down
4 changes: 4 additions & 0 deletions torch_snippets.egg-info/SOURCES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ torch_snippets/adapters.py
torch_snippets/bb_utils.py
torch_snippets/bokeh_loader.py
torch_snippets/charts.py
torch_snippets/cli.py
torch_snippets/dates.py
torch_snippets/decorators.py
torch_snippets/fastcores.py
Expand All @@ -29,15 +30,18 @@ torch_snippets/misc.py
torch_snippets/paths.py
torch_snippets/pdf_loader.py
torch_snippets/registry.py
torch_snippets/s3_loader.py
torch_snippets/scp.py
torch_snippets/sklegos.py
torch_snippets/text_utils.py
torch_snippets/tmp.py
torch_snippets/torch_loader.py
torch_snippets/video.py
torch_snippets/zen.py
torch_snippets.egg-info/PKG-INFO
torch_snippets.egg-info/SOURCES.txt
torch_snippets.egg-info/dependency_links.txt
torch_snippets.egg-info/entry_points.txt
torch_snippets.egg-info/not-zip-safe
torch_snippets.egg-info/requires.txt
torch_snippets.egg-info/top_level.txt
Expand Down
2 changes: 2 additions & 0 deletions torch_snippets.egg-info/entry_points.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[console_scripts]
ts = torch_snippets.cli:cli
1 change: 1 addition & 0 deletions torch_snippets.egg-info/requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ nbconvert
nbformat
icecream
mergedeep
typer
5 changes: 4 additions & 1 deletion torch_snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.538.1"
__version__ = "0.539"
from .loader import *
from .paths import *
from .markup import *
Expand All @@ -22,3 +22,6 @@
from .torch_loader import *
except Exception as e:
...

from .s3_loader import *
from .zen import *
16 changes: 15 additions & 1 deletion torch_snippets/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
'torch_snippets.charts.spider': ('charts.html#spider', 'torch_snippets/charts.py'),
'torch_snippets.charts.upsetaltair_top_level_configuration': ( 'charts.html#upsetaltair_top_level_configuration',
'torch_snippets/charts.py')},
'torch_snippets.cli': {},
'torch_snippets.dates': {},
'torch_snippets.decorators': { 'torch_snippets.decorators.check_kwargs_not_none': ( 'decorators.html#check_kwargs_not_none',
'torch_snippets/decorators.py'),
Expand Down Expand Up @@ -269,17 +270,26 @@
'torch_snippets.markup2.AttrDict.drop': ('markups.html#attrdict.drop', 'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.fetch': ( 'markups.html#attrdict.fetch',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.fetch2': ( 'markups.html#attrdict.fetch2',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.find_address': ( 'markups.html#attrdict.find_address',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.flatten': ( 'markups.html#attrdict.flatten',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.flatten_and_make_dataframe': ( 'markups.html#attrdict.flatten_and_make_dataframe',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.get': ('markups.html#attrdict.get', 'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.items': ( 'markups.html#attrdict.items',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.keys': ('markups.html#attrdict.keys', 'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.map': ('markups.html#attrdict.map', 'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.merge_addersses': ( 'markups.html#attrdict.merge_addersses',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.pretty': ( 'markups.html#attrdict.pretty',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.print_summary': ( 'markups.html#attrdict.print_summary',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.set': ('markups.html#attrdict.set', 'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.slice': ( 'markups.html#attrdict.slice',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.AttrDict.summary': ( 'markups.html#attrdict.summary',
Expand All @@ -301,6 +311,8 @@
'torch_snippets.markup2.hash_pandas_dataframe': ( 'markups.html#hash_pandas_dataframe',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.hash_tensor': ('markups.html#hash_tensor', 'torch_snippets/markup2.py'),
'torch_snippets.markup2.is_attrdict_like': ( 'markups.html#is_attrdict_like',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.isnamedtupleinstance': ( 'markups.html#isnamedtupleinstance',
'torch_snippets/markup2.py'),
'torch_snippets.markup2.pretty_json': ('markups.html#pretty_json', 'torch_snippets/markup2.py'),
Expand Down Expand Up @@ -389,6 +401,7 @@
'torch_snippets.registry.parse_string': ( 'registry.html#parse_string',
'torch_snippets/registry.py'),
'torch_snippets.registry.tryeval': ('registry.html#tryeval', 'torch_snippets/registry.py')},
'torch_snippets.s3_loader': {},
'torch_snippets.scp': {},
'torch_snippets.sklegos': { 'torch_snippets.sklegos.Cat2Num': ('sklegos.html#cat2num', 'torch_snippets/sklegos.py'),
'torch_snippets.sklegos.Cat2Num.__init__': ( 'sklegos.html#cat2num.__init__',
Expand Down Expand Up @@ -512,4 +525,5 @@
'torch_snippets/trainer/config.py')},
'torch_snippets.trainer.hooks': {},
'torch_snippets.trainer.neural_graph': {},
'torch_snippets.video': {}}}
'torch_snippets.video': {},
'torch_snippets.zen': {}}}
21 changes: 21 additions & 0 deletions torch_snippets/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from typer import Typer
from .loader import show as _show

cli = Typer()


@cli.command()
def time():
"""print the time now, in %Y-%m-%d %H:%M:%S format"""
import time

print(time.strftime("%Y-%m-%d %H:%M:%S"))


# Other cool utils


@cli.command()
def show(path):
"""print the object"""
_show(path)
9 changes: 7 additions & 2 deletions torch_snippets/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,18 @@ def readPIL(fname, mode="RGB"):
return Image.open(str(fname)).convert(mode.upper())


def crop_from_bb(im, bb):
def crop_from_bb(im, bb, padding=None):
if isinstance(bb, list):
return [crop_from_bb(im, _bb) for _bb in bb]
return [crop_from_bb(im, _bb, padding=padding) for _bb in bb]
x, y, X, Y = bb
px, py, pX, pY = padding
if max(x, y, X, Y) < 1.5:
h, w = im.shape[:2]
x, y, X, Y = BB(bb).absolute((h, w))
y = max(0, y - py)
Y = min(h, Y + pY)
x = max(0, x - px)
X = min(w, X + pX)
return im.copy()[y:Y, x:X]


Expand Down
Loading

0 comments on commit a2cf6d4

Please sign in to comment.