Moving around the testing notebooks. Autocropping is about done with exception to any new versions or converting the stuff to C code. Signed-off-by: Ethan Wellenreiter <ewellenreiter@gmail.com>
145 lines
4.2 KiB
Plaintext
145 lines
4.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"version=2.0\n",
|
|
"cachepath=\"../.cache/\"\n",
|
|
"savepath=\"./savespot/\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stderr",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/datapoints/__init__.py:12: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().\n",
|
|
" warnings.warn(_BETA_TRANSFORMS_WARNING)\n",
|
|
"/usr/local/lib/python3.10/dist-packages/torchvision/transforms/v2/__init__.py:54: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753, and you can also check out https://github.com/pytorch/vision/issues/7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().\n",
|
|
" warnings.warn(_BETA_TRANSFORMS_WARNING)\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"import torch\n",
|
|
"from torch.utils.data import DataLoader\n",
|
|
"import torch.nn as nn\n",
|
|
"import torch.nn.functional as fn\n",
|
|
"import torch.optim as optim\n",
|
|
"import torchvision.transforms.functional as tvf\n",
|
|
"import torchvision.transforms.v2 as v2\n",
|
|
"import torchvision.models as models\n",
|
|
"\n",
|
|
"\n",
|
|
"from PIL import Image\n",
|
|
"\n",
|
|
"import datasets as ds\n",
|
|
"from tqdm.autonotebook import tqdm\n",
|
|
"\n",
|
|
"import random\n",
|
|
"\n",
|
|
"import matplotlib.pyplot as plt\n",
|
|
"\n",
|
|
"\n",
|
|
"import cv2\n",
|
|
"import numpy as np\n",
|
|
"import myfunctions as mf\n",
|
|
"\n",
|
|
"torch.cuda.empty_cache()\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# array = np.load(\"./testing_space/outputarray.npy\")\n",
|
|
"# counter = np.load(\"./testing_space/counter.npy\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# print(array)\n",
|
|
"# print(counter)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"img = cv2.imread('./test_images/IMG_7605.jpg')\n",
|
|
"# img = mf.ResizeWithAspectRatio(img, 1000)\n",
|
|
"# img = mf.ResizeWithAspectRatio(mf.SquarePad(fill=255)(img),1000)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"rotatedimg = mf.houghlinedeskewandcrop(img)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"# out = mf.morphologyCrop(img)\n",
|
|
"# out = cv2.cvtColor(out, cv2.COLOR_BGR2GRAY)\n",
|
|
"# out = cv2.threshold(out, 200, 255, cv2.THRESH_BINARY)[1]"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"cv2.imshow(\"result1\", rotatedimg)\n",
|
|
"# cv2.imshow(\"result2\", result2)\n",
|
|
"cv2.waitKey(0)\n",
|
|
"cv2.destroyAllWindows()"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"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.10.12"
|
|
},
|
|
"orig_nbformat": 4
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|