Skip to content

Commit

Permalink
0.538
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhky committed Aug 17, 2024
1 parent 55336f9 commit 3edebb3
Show file tree
Hide file tree
Showing 21 changed files with 931 additions and 533 deletions.
4 changes: 2 additions & 2 deletions _proc/bounding_boxes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[07/25/24 07:17:46] WARNING Unable to load torch and dependent libraries from torch-snippets. loader.py:<module>:108\n",
" Functionalities might be limited. pip install lovely-tensors in case there are torch related errors \n"
"\u001b[2;36m[08/17/24 12:32:44]\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=7281;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=181415;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",
"[07/25/24 07:17:48] INFO foo took 1.01 seconds to execute <ipython-input-1-6ac2073623b5>:wrapper:47\n"
"\u001b[2;36m[08/17/24 12:32:46]\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=974847;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=366818;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",
"> 0x138a37040>, max_rows=50)"
"> 0x12fc26800>, 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",
"> 0x138a37040>, max_rows=50)"
"> 0x12fc26800>, max_rows=50)"
]
},
"execution_count": 6,
Expand Down
511 changes: 292 additions & 219 deletions _proc/misc.ipynb

Large diffs are not rendered by default.

11 changes: 3 additions & 8 deletions _proc/paths.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1664,9 +1664,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "ts",
"display_name": "base",
"language": "python",
"name": "ts"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -1678,12 +1678,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
},
"vscode": {
"interpreter": {
"hash": "0a92af74ccf65e106ae96852a45a9b0a5e11a3c414a16fc8bb2d134868e55bfd"
}
"version": "3.12.4"
}
},
"nbformat": 4,
Expand Down
9 changes: 9 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
# Changelog
#### 0.538
🎉 `tryy` a new decorator to wrap try except with optional default return as well as print stack trace if need be
`Timer` can given time-remaning approximation based on both instantaneous or average speed
`logging_mode` functions can be used as both context managers and decorators
✨ better formatting for `now()`
`show` auto generates a title if possible
`show` function includes a `framecount` parameter to specify which frame of the stack it should search for the title. See its usage in `show_big_dataframe`
`yolo_2_df` and `df_2_yolo` functions in adapters

#### 0.537
`AD` let's you know if a collection is list, set or tuple
✨ NEW DEFAULT: use `info` column to show text else `text`
Expand Down
48 changes: 48 additions & 0 deletions nbs/adapters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,54 @@
" Warn(f'{e} @ {item[\"@name\"]}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# | export\n",
"# | hide\n",
"def df_2_yolo(df, h, w, class2id, class_column):\n",
" yolo_data = []\n",
" for index, row in df.iterrows():\n",
" cls = row[class_column]\n",
" if cls not in class2id:\n",
" continue\n",
" class_id = class2id[cls]\n",
" x_center = (row[\"x\"] + row[\"X\"]) / 2 / w\n",
" y_center = (row[\"y\"] + row[\"Y\"]) / 2 / h\n",
" width = (row[\"X\"] - row[\"x\"]) / w\n",
" height = (row[\"Y\"] - row[\"y\"]) / h\n",
" yolo_data.append(\n",
" f\"{class_id} {x_center:.6f} {y_center:.6f} {width:.6f} {height:.6f}\"\n",
" )\n",
" return yolo_data\n",
"\n",
"\n",
"def yolo_2_df(yolo, h, w, id2class, class_column):\n",
" data = []\n",
"\n",
" for line in yolo:\n",
" class_id, x_center, y_center, width, height = map(float, line.split())\n",
" class_name = id2class[int(class_id)]\n",
"\n",
" x_center *= w\n",
" y_center *= h\n",
" width *= w\n",
" height *= h\n",
"\n",
" x_min = int(x_center - (width / 2))\n",
" y_min = int(y_center - (height / 2))\n",
" x_max = int(x_center + (width / 2))\n",
" y_max = int(y_center + (height / 2))\n",
"\n",
" data.append([x_min, y_min, x_max, y_max, class_name])\n",
"\n",
" df = pd.DataFrame(data, columns=[\"x\", \"y\", \"X\", \"Y\", class_column])\n",
" return df"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
2 changes: 1 addition & 1 deletion nbs/jupyter_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
" \"display.max_rows\",\n",
" max_rows,\n",
" ):\n",
" show(df, max_rows=max_rows)"
" show(df, max_rows=max_rows, frame_count=2)"
]
},
{
Expand Down
28 changes: 26 additions & 2 deletions nbs/logging.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -834,15 +834,39 @@
"\n",
"\n",
"@contextmanager\n",
"def logger_mode(level):\n",
"def _logger_mode_context(level):\n",
" lv = get_logger_level()\n",
" try:\n",
" lv = get_logger_level()\n",
" reset_logger(level.upper())\n",
" yield\n",
" finally:\n",
" reset_logger(lv.upper())\n",
"\n",
"\n",
"def logger_mode(level):\n",
" if callable(level):\n",
" # Used as a decorator without arguments\n",
" func = level\n",
"\n",
" @wraps(func)\n",
" def wrapper(*args, **kwargs):\n",
" with _logger_mode_context(\"DEBUG\"):\n",
" return func(*args, **kwargs)\n",
"\n",
" return wrapper\n",
" else:\n",
" # Used as a decorator with arguments or as a context manager\n",
" def decorator(func):\n",
" @wraps(func)\n",
" def wrapper(*args, **kwargs):\n",
" with _logger_mode_context(level):\n",
" return func(*args, **kwargs)\n",
"\n",
" return wrapper\n",
"\n",
" return _logger_mode_context(level) if not callable(level) else decorator\n",
"\n",
"\n",
"def in_logger_mode(level):\n",
" return get_logger_level() == level\n",
"\n",
Expand Down
Loading

0 comments on commit 3edebb3

Please sign in to comment.