<jupyter_start><jupyter_text>Basic data handling> How to open images, apply transforms.  Open From file name:<jupyter_code>fn = Path('assets/cthulhu.jpeg')
im = PILImage.create(fn); im<jupyter_output><empty_output><jupyter_text>Open as black and white:<jupyter_code>im_bw = PILImageBW.create(fn); im_bw<jupyter_output><empty_output><jupyter_text>From tensor/numpy-array:<jupyter_code>tim = ToTensor()(im)
_ = PILImage.create(ToTensor()(im))<jupyter_output><empty_output><jupyter_text>Resize<jupyter_code>im.resize((128,128))<jupyter_output><empty_output><jupyter_text>Save<jupyter_code>im.save(fn)<jupyter_output><empty_output><jupyter_text>Convert to Tensor<jupyter_code>tim = ToTensor()(im); tim.shape<jupyter_output><empty_output><jupyter_text>Pipeline A pipeline can be used to combine a sequence of functions.<jupyter_code>def get_size(x): return x.size
pipe = Pipeline([PILImage.create, Resize(128), get_size])
pipe(fn)<jupyter_output><empty_output><jupyter_text>**IMPORTANT:** The expected output of the cell above would be `(128,128)` since we are calling `Resize(128)`, but we are instead getting `(256,144)`.  This happens because `Pipeline` reorders our functions based on an attribute called `order`, which defaults to **0** for all functions we pass.<jupyter_code>[(f.name, f.order) for f in pipe]<jupyter_output><empty_output><jupyter_text>For our function to execute after `Resize`, it's `order` has to be greater than 1 (the execution order is ascedent).<jupyter_code>get_size_tfm = mk_transform(get_size)
get_size_tfm.order = 2
pipe = Pipeline([PILImage.create, Resize(128), get_size_tfm])
pipe(fn)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1270516717325228, 'fraction_numerical': 0.0182370820668693, 'mean_word_length': 9.417721518987342, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '115846', 'license': 'Apache-2.0', 'n_tokens_mistral': 620, 'n_tokens_neox': 595, 'n_words': 124, 'path': 'nbs/08_vision.basic.ipynb', 'repo_name': 'lgvaz/fastcook2', 'size': '1645'}