Created
March 14, 2020 11:54
-
-
Save takotab/93fa66f73f57a2c2e0295bb9161d48bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/home/tako/dev/env37/lib/python3.7/site-packages/pandas/compat/__init__.py:117: UserWarning: Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.\n", | |
" warnings.warn(msg)\n" | |
] | |
} | |
], | |
"source": [ | |
"from fastai2.data.all import *" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [], | |
"source": [ | |
"class OtherTuple(Tuple):pass\n", | |
"class Tfm(ItemTransform): \n", | |
" def encodes(self, o:OtherTuple):\n", | |
" print('tmf.encodes triggered')\n", | |
" return list(o)\n", | |
" \n", | |
" def decodes(self, o:list): \n", | |
" return Tuple(o)\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"[0, 1]" | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"t = Tfm()\n", | |
"t(OtherTuple(0,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tmf.encodes triggered\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[0, 1]" | |
] | |
}, | |
"execution_count": 9, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"t.encodes(OtherTuple(0,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [], | |
"source": [ | |
"class Tfm2(ItemTransform): \n", | |
" def encodes(self, o):\n", | |
" print('tmf.encodes triggered')\n", | |
" return list(o)\n", | |
" \n", | |
" def decodes(self, o:list): \n", | |
" return Tuple(o)\n", | |
" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tmf.encodes triggered\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[0, 1]" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"t = Tfm2()\n", | |
"t((0,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"tmf.encodes triggered\n" | |
] | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"[0, 1]" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"t.encodes(OtherTuple(0,1))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"Collapsed": "false" | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "env37", | |
"language": "python", | |
"name": "env37" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.7.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment