summaryrefslogtreecommitdiff
path: root/notebooks/Untitled1.ipynb
diff options
context:
space:
mode:
authorGustaf Rydholm <gustaf.rydholm@gmail.com>2023-09-11 22:09:53 +0200
committerGustaf Rydholm <gustaf.rydholm@gmail.com>2023-09-11 22:09:53 +0200
commit43b10ea57f40983ec53c17a05f5b9fd2501f4eea (patch)
tree756b4cd2483a0d794b057cb6bb398f99991b01e1 /notebooks/Untitled1.ipynb
parent1732ed564a738a42c1bf6e8127ae810f5658cb06 (diff)
Update notebooks
Diffstat (limited to 'notebooks/Untitled1.ipynb')
-rw-r--r--notebooks/Untitled1.ipynb111
1 files changed, 109 insertions, 2 deletions
diff --git a/notebooks/Untitled1.ipynb b/notebooks/Untitled1.ipynb
index 92b35c9..d996e98 100644
--- a/notebooks/Untitled1.ipynb
+++ b/notebooks/Untitled1.ipynb
@@ -2,12 +2,24 @@
"cells": [
{
"cell_type": "code",
- "execution_count": 73,
+ "execution_count": 14,
"id": "a15a452c-bbbc-4227-90fb-ad573f82c43f",
"metadata": {
"tags": []
},
- "outputs": [],
+ "outputs": [
+ {
+ "ename": "ModuleNotFoundError",
+ "evalue": "No module named 'text_recognizer.network.transformer.embeddings'",
+ "output_type": "error",
+ "traceback": [
+ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
+ "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
+ "Cell \u001b[0;32mIn[14], line 15\u001b[0m\n\u001b[1;32m 12\u001b[0m sys\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m..\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtext_recognizer\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mdata\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01miam_lines\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m IAMLines\n\u001b[0;32m---> 15\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtext_recognizer\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mnetwork\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtransformer\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01membeddings\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01msincos\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m sincos_2d\n",
+ "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'text_recognizer.network.transformer.embeddings'"
+ ]
+ }
+ ],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
@@ -430,6 +442,101 @@
"plt.figure(figsize=(40, 20))\n",
"plt.imshow(xxx, cmap='gray')"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "4535cb1c-fc97-4393-8348-649d06030931",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [],
+ "source": [
+ "conv = torch.nn.Conv2d(1, 1, kernel_size=3, stride=2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "id": "d3092482-a2d5-4b52-9967-8d18cab35f42",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "torch.Size([1, 1, 13, 255])"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "x = torch.randn(1, 1, 56, 1024)\n",
+ "conv(conv(x)).shape"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 18,
+ "id": "44183fe9-f798-4755-8db5-491b8a3dbf2f",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "text": [
+ "tensor([[True, True, True],\n",
+ " [True, True, True]])\n"
+ ]
+ }
+ ],
+ "source": [
+ "import torch\n",
+ "import torch.nn.functional as F\n",
+ "source = torch.randn((2,3)).bool()\n",
+ "print(source)\n",
+ "# now we expand to size (7, 11) by appending a row of 0s at pos 0 and pos 6, \n",
+ "# and a column of 0s at pos 10\n",
+ "result = F.pad(source, pad=(0, 1), value=False)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 19,
+ "id": "34220755-4224-458e-94b8-ea1fa0488a65",
+ "metadata": {
+ "tags": []
+ },
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "tensor([[ True, True, True, False],\n",
+ " [ True, True, True, False]])"
+ ]
+ },
+ "execution_count": 19,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "result"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "dfc269b8-8242-41ee-9190-73df0af47e83",
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {