Skip to content

Commit

Permalink
0.499.34
Browse files Browse the repository at this point in the history
  • Loading branch information
sizhky committed Jun 29, 2023
1 parent 1b1da3a commit a2abef7
Show file tree
Hide file tree
Showing 8 changed files with 468 additions and 219 deletions.
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.499.33
version: 0.499.34
source:
sha256: 600a4e6ab5d8539f94ceebcc82180eda82dfbce57e081230788a2595a9d0462d
url: https://files.pythonhosted.org/packages/3f/bb/c2ccb89e806ea62339f164be9fd9a5d3fa791312b0a0ec559807ceffec8f/torch_snippets-0.499.33.tar.gz
sha256: 9fb11abf70db9855972d92d0c2185e29c8cbf08f8bca30fb4aea080f282955e9
url: https://files.pythonhosted.org/packages/c5/fd/31535a73899128862b6a9b53b4f1fcb079bbbb7c0026ca27fdb241b6b396/torch_snippets-0.499.34.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
4 changes: 2 additions & 2 deletions nbs/adapters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
" df[\"@source\"] = \"manual\"\n",
" df[\"@z_order\"] = \"0\"\n",
" if \"text\" in df.columns:\n",
" df[\"attribute\"] = [[{\"@name\": \"OCR\", \"#text\": text}] for text in df[\"text\"]]\n",
" df[\"attribute\"] = [[{\"@name\": \"OCR\", \"#text\": text if text==text else ''}] for text in df[\"text\"]]\n",
" df.drop(\n",
" [\n",
" c\n",
Expand Down Expand Up @@ -269,7 +269,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15 (default, Nov 24 2022, 09:04:07) \n[Clang 14.0.6 ]"
"version": "3.8.15"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
636 changes: 436 additions & 200 deletions scripts.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ author = Yeshwanth Reddy
author_email = 1992chinna@gmail.com
copyright = sizhky
branch = master
version = 0.499.33
version = 0.499.34
min_python = 3.7
audience = Developers
language = English
Expand Down
2 changes: 1 addition & 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.499.33
Version: 0.499.34
Summary: One line functions for common tasks
Home-page: https://github.com/sizhky/torch_snippets/tree/master/
Author: Yeshwanth Reddy
Expand Down
2 changes: 1 addition & 1 deletion torch_snippets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "0.499.33"
__version__ = "0.499.34"
from .loader import *
from .paths import *
from .markup import *
Expand Down
30 changes: 20 additions & 10 deletions torch_snippets/adapters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/adapters.ipynb.

# %% auto 0
__all__ = ['np_2_b64', 'b64_2_np', 'b64_2_file', 'bytes_2_file', 'file_2_bytes', 'csvs_2_cvat', 'cvat_2_csvs']
__all__ = [
"np_2_b64",
"b64_2_np",
"b64_2_file",
"bytes_2_file",
"file_2_bytes",
"csvs_2_cvat",
"cvat_2_csvs",
]

# %% ../nbs/adapters.ipynb 2
import base64, cv2, numpy as np
Expand All @@ -28,9 +36,9 @@ def b64_2_np(input: str) -> np.ndarray:


def b64_2_file(
input: str, # base64 encoded string
fpath: Union[str, P] # Place where you want to save the file
) -> None:
input: str, # base64 encoded string
fpath: Union[str, P], # Place where you want to save the file
) -> None:
"""Save a file encoded as a base64 `input` at given `fpath`"""
with open(fpath, "wb") as pdf_file:
input = bytes(input, "utf-8")
Expand All @@ -42,7 +50,7 @@ def b64_2_file(
def bytes_2_file(
input: bytes, # bytes
fpath: Union[str, P], # Place where you want to save the file
silent: bool = False
silent: bool = False,
) -> None:
"""Save bytes `input` at given `fpath`"""
with open(fpath, "wb") as file_to_write:
Expand All @@ -56,6 +64,7 @@ def file_2_bytes(fpath):
output = f.read()
return output


# %% ../nbs/adapters.ipynb 4
def _process(
df: pd.DataFrame, label_column="readable_label", default_label="Background"
Expand All @@ -69,7 +78,10 @@ def _process(
df["@source"] = "manual"
df["@z_order"] = "0"
if "text" in df.columns:
df["attribute"] = [[{"@name": "OCR", "#text": text}] for text in df["text"]]
df["attribute"] = [
[{"@name": "OCR", "#text": text if text == text else ""}]
for text in df["text"]
]
df.drop(
[
c
Expand Down Expand Up @@ -104,7 +116,7 @@ def csvs_2_cvat(
parquet=False,
relative_df=True,
default_label="Background",
extension='jpg'
extension="jpg",
):
images_folder, csvs_folder = [P(_) for _ in [images_folder, csvs_folder]]
data = AttrDict({"annotations": {"image": []}})
Expand Down Expand Up @@ -161,7 +173,7 @@ def _get_attribute_data(item, column_name):


def _cvat_ann_2_csv(ann):
if 'box' not in ann:
if "box" not in ann:
return pd.DataFrame()
if isinstance(ann.box, AttrDict):
rows = [a.to_dict() for a in [ann.box]]
Expand Down Expand Up @@ -203,5 +215,3 @@ def cvat_2_csvs(xmlfile, csvs_folder):
df.to_csv(save_at, index=False)
except Exception as e:
Warn(f'{e} @ {item["@name"]}')


5 changes: 4 additions & 1 deletion torch_snippets/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@

__all__ += ["torch", "nn", "F", "Dataset", "DataLoader", "optim"]
except:
Warn(
"Unable to load torch and dependent libraries from torch-snippets. \n"
"Functionalities might be limited. pip install lovely-tensors in case there are torch related errors"
)
...
import matplotlib # ; matplotlib.use('Agg')
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -318,7 +322,6 @@ def show(
try:
if isinstance(img, (str, Path)):
img = read(str(img), 1)
if isinstance(img, torch.Tensor):
img = img.cpu().detach().numpy().copy()
if isinstance(img, PIL.Image.Image):
img = np.array(img)
Expand Down

0 comments on commit a2abef7

Please sign in to comment.