Skip to content

Commit

Permalink
0.532
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhky committed May 9, 2024
1 parent c181448 commit f86e59c
Show file tree
Hide file tree
Showing 30 changed files with 2,817 additions and 1,166 deletions.
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# Changelog

#### 0.531
🎉 AD `__contains__` can do a nested `in` 'x.y.z' in AD(x={'y': {'z': 10}}) == True

#### 0.530
☠️ Stop using rich's print and revert back to builtin print
🐞 Decouple AD and torch
🎉 Add a new chart - spider / radar
🎉 Add scp client with download upload functionality

#### 0.529
🧹 change code to remove future warnings in text_utils

Expand Down
6 changes: 3 additions & 3 deletions conda/torch_snippets/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package:
name: torch_snippets
version: '0.528'
version: '0.530'
source:
sha256: 06f5ca72a5cefe10bbf448c71886b15d0e5ec59a199528ff248c2a0918de32cd
url: https://files.pythonhosted.org/packages/fc/f6/0beee4f16392f42a8c5a23948e09549617479540e724e40b8e291b8c2b06/torch_snippets-0.528.tar.gz
sha256: b0c5de8108d4ec175ec40b73dcfd0e8cec29c0e83171cec8aaeb865f9200f696
url: https://files.pythonhosted.org/packages/33/29/ec172cc92aaf82303a25784f9470114ed76acfd52b734a1a9cfd93d20c64/torch_snippets-0.530.tar.gz
about:
description: "# Utilities for simple needs\n\n\n\n## torch snippets does a lot of\
\ default importing for you\nWhether it is numpy, pandas, matplotlib or the useful\
Expand Down
81 changes: 79 additions & 2 deletions nbs/adapters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@
"\n",
"\n",
"def b64_2_np(input: str) -> np.ndarray:\n",
" \"\"\"Converts a base64 encoded image to a NumPy array.\n",
"\n",
" Args:\n",
" input (str): The base64 encoded image.\n",
"\n",
" Returns:\n",
" np.ndarray: The NumPy array representation of the image in RGB format.\n",
" \"\"\"\n",
" input = bytes(input, \"utf-8\")\n",
" input = base64.b64decode(input)\n",
" img_nparr = np.frombuffer(input, np.uint8)\n",
Expand Down Expand Up @@ -99,6 +107,17 @@
"def _process(\n",
" df: pd.DataFrame, label_column=\"readable_label\", default_label=\"Background\"\n",
"):\n",
" \"\"\"\n",
" Process the given DataFrame and convert it into a list of records.\n",
"\n",
" Args:\n",
" df (pd.DataFrame): The input DataFrame to be processed.\n",
" label_column (str, optional): The column name for the label. Defaults to \"readable_label\".\n",
" default_label (str, optional): The default label value. Defaults to \"Background\".\n",
"\n",
" Returns:\n",
" list: A list of records, where each record is a dictionary representing a row in the DataFrame.\n",
" \"\"\"\n",
" df[\"@xbr\"] = df[\"X\"]\n",
" df[\"@xtl\"] = df[\"x\"]\n",
" df[\"@ybr\"] = df[\"Y\"]\n",
Expand Down Expand Up @@ -148,6 +167,22 @@
" default_label=\"Background\",\n",
" extension=\"jpg\",\n",
"):\n",
" \"\"\"\n",
" Convert CSV annotations to CVAT XML format.\n",
"\n",
" Args:\n",
" images_folder (str): Path to the folder containing the images.\n",
" csvs_folder (str): Path to the folder containing the CSV annotations.\n",
" xml_output_file (str): Path to the output XML file.\n",
" items (list, optional): List of items to process. If None, all items will be processed. Defaults to None.\n",
" parquet (bool, optional): Whether the annotations are stored in Parquet format. Defaults to False.\n",
" relative_df (bool, optional): Whether the bounding box coordinates in the CSV are relative to the image size. Defaults to True.\n",
" default_label (str, optional): Default label for the bounding boxes. Defaults to \"Background\".\n",
" extension (str, optional): Image file extension. Defaults to \"jpg\".\n",
"\n",
" Returns:\n",
" None\n",
" \"\"\"\n",
" images_folder, csvs_folder = [P(_) for _ in [images_folder, csvs_folder]]\n",
" data = AttrDict({\"annotations\": {\"image\": []}})\n",
" if items is None:\n",
Expand All @@ -174,6 +209,16 @@
"\n",
"\n",
"def _get_attribute_columns(column):\n",
" \"\"\"\n",
" Get attribute columns from a given column.\n",
"\n",
" Args:\n",
" column (pandas.Series): The input column.\n",
"\n",
" Returns:\n",
" set: A set of attribute columns extracted from the input column.\n",
" \"\"\"\n",
"\n",
" def _get_columns_from_row(item):\n",
" if item != item:\n",
" return []\n",
Expand All @@ -187,6 +232,16 @@
"\n",
"\n",
"def _get_attribute_data(item, column_name):\n",
" \"\"\"\n",
" Retrieves the attribute data for a given item and column name.\n",
"\n",
" Parameters:\n",
" - item: The item to retrieve the attribute data from.\n",
" - column_name: The name of the column to retrieve the attribute data for.\n",
"\n",
" Returns:\n",
" - The attribute data for the given item and column name, or np.nan if not found.\n",
" \"\"\"\n",
" if item != item:\n",
" return item\n",
" if isinstance(item, dict):\n",
Expand All @@ -203,6 +258,15 @@
"\n",
"\n",
"def _cvat_ann_2_csv(ann):\n",
" \"\"\"\n",
" Convert CVAT annotation to a pandas DataFrame in CSV format.\n",
"\n",
" Args:\n",
" ann (dict): CVAT annotation dictionary.\n",
"\n",
" Returns:\n",
" pandas.DataFrame: DataFrame containing the converted annotation data in CSV format.\n",
" \"\"\"\n",
" if \"box\" not in ann:\n",
" return pd.DataFrame()\n",
" if isinstance(ann.box, AttrDict):\n",
Expand Down Expand Up @@ -236,8 +300,21 @@
"\n",
"\n",
"def cvat_2_csvs(xmlfile, csvs_folder):\n",
" \"\"\"\n",
" Convert CVAT XML annotations to CSV files.\n",
"\n",
" Args:\n",
" xmlfile (str): Path to the CVAT XML file.\n",
" csvs_folder (str): Path to the folder where the CSV files will be saved.\n",
"\n",
" Returns:\n",
" None\n",
" \"\"\"\n",
" data = read_xml(xmlfile)\n",
" for item in data.annotations.image:\n",
" items = data.annotations.image\n",
" if not isinstance(items, list):\n",
" items = [items]\n",
" for item in items:\n",
" try:\n",
" df = _cvat_ann_2_csv(item)\n",
" save_at = f'{csvs_folder}/{stem(item[\"@name\"])}.csv'\n",
Expand Down Expand Up @@ -271,7 +348,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.8.undefined"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
23 changes: 23 additions & 0 deletions nbs/bokeh_plotting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,18 @@
"# | export\n",
"# | hide\n",
"def parse_sz(size):\n",
" \"\"\"\n",
" Parses the size argument and returns a tuple of width and height.\n",
"\n",
" Args:\n",
" size (int or tuple): The size argument to be parsed.\n",
"\n",
" Returns:\n",
" tuple: A tuple of width and height.\n",
"\n",
" Raises:\n",
" NotImplementedError: If the size argument is not an int or a tuple of length 2.\n",
" \"\"\"\n",
" if isinstance(size, int):\n",
" return size, size\n",
" elif isinstance(size, tuple):\n",
Expand All @@ -74,6 +86,17 @@
"\n",
"\n",
"def get_bplot(sz=500, **kwargs):\n",
" \"\"\"\n",
" Create a Bokeh plot with specified size and tools.\n",
"\n",
" Parameters:\n",
" - sz (int): Size of the plot in pixels.\n",
" - **kwargs: Additional keyword arguments for customizing the plot.\n",
"\n",
" Returns:\n",
" - plot (bokeh.plotting.Figure): Bokeh plot object.\n",
"\n",
" \"\"\"\n",
" h, w = parse_sz(sz)\n",
" output_notebook()\n",
" plot = figure(\n",
Expand Down
Loading

0 comments on commit f86e59c

Please sign in to comment.