Timothy Chan
commited on
Delete donut_simple.ipynb
Browse files- donut_simple.ipynb +0 -115
donut_simple.ipynb
DELETED
@@ -1,115 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "markdown",
|
5 |
-
"source": [
|
6 |
-
"1. Download the repo from Github https://github.com/clovaai/donut using git command or through direct download.\n",
|
7 |
-
"2. (The base model config for document classification / document parsing / document Q&A tasks is stored under /config.\n",
|
8 |
-
"3. Copy a copy of any YAML file, rename arbitarily and set your parameters.\n",
|
9 |
-
"3. Prepare your dataset (train, validation, test) along with JSONL files on the /dataset folder. You can use program to generate JSONL files from csv files. Be remind of the format. One line per one data. One JSONL file in each folder (train/valdidation/test)\n",
|
10 |
-
"4. Refer to donut_training.ipynb to train your model. Use A-100/V-100 GPU to avoid troublesome settings / slow training time. The trained model is stored under /result folder.\n",
|
11 |
-
"5. Run the trained model using this ipynb file.\n",
|
12 |
-
"6. Don't change the version of transformers and timm. It is a nightmare if you don't understand what you do."
|
13 |
-
],
|
14 |
-
"metadata": {
|
15 |
-
"id": "L5U1ACZZBxfh"
|
16 |
-
}
|
17 |
-
},
|
18 |
-
{
|
19 |
-
"cell_type": "code",
|
20 |
-
"source": [
|
21 |
-
"# Enable Google Drive and Go to the donut folder\n",
|
22 |
-
"from google.colab import drive\n",
|
23 |
-
"drive.mount('/content/drive')\n",
|
24 |
-
"%cd /content/drive/MyDrive/donut"
|
25 |
-
],
|
26 |
-
"metadata": {
|
27 |
-
"id": "-BZ2HFB9OtWP"
|
28 |
-
},
|
29 |
-
"execution_count": null,
|
30 |
-
"outputs": []
|
31 |
-
},
|
32 |
-
{
|
33 |
-
"cell_type": "code",
|
34 |
-
"execution_count": null,
|
35 |
-
"metadata": {
|
36 |
-
"id": "SJpD4AAj7qeZ"
|
37 |
-
},
|
38 |
-
"outputs": [],
|
39 |
-
"source": [
|
40 |
-
"#Install all necessary modules. Don't change the version number!\n",
|
41 |
-
"!pip install transformers==4.25.1\n",
|
42 |
-
"!pip install timm==0.5.4\n",
|
43 |
-
"!pip install donut-python"
|
44 |
-
]
|
45 |
-
},
|
46 |
-
{
|
47 |
-
"cell_type": "code",
|
48 |
-
"source": [
|
49 |
-
"# import necessary modules\n",
|
50 |
-
"from donut import DonutModel\n",
|
51 |
-
"from PIL import Image\n",
|
52 |
-
"import torch\n",
|
53 |
-
"import argparse"
|
54 |
-
],
|
55 |
-
"metadata": {
|
56 |
-
"id": "gSatjcDn5S89"
|
57 |
-
},
|
58 |
-
"execution_count": null,
|
59 |
-
"outputs": []
|
60 |
-
},
|
61 |
-
{
|
62 |
-
"cell_type": "code",
|
63 |
-
"source": [
|
64 |
-
"# Input the default arguments\n",
|
65 |
-
"parser = argparse.ArgumentParser()"
|
66 |
-
],
|
67 |
-
"metadata": {
|
68 |
-
"id": "RZSmy3Riz7ia"
|
69 |
-
},
|
70 |
-
"execution_count": null,
|
71 |
-
"outputs": []
|
72 |
-
},
|
73 |
-
{
|
74 |
-
"cell_type": "code",
|
75 |
-
"source": [
|
76 |
-
"model = DonutModel.from_pretrained(\"./result/train_Booking/donut-booking-extract\")\n",
|
77 |
-
"if torch.cuda.is_available():\n",
|
78 |
-
" model.half()\n",
|
79 |
-
" device = torch.device(\"cuda\")\n",
|
80 |
-
" model.to(device)\n",
|
81 |
-
"else:\n",
|
82 |
-
" model.encoder.to(torch.bfloat16)\n",
|
83 |
-
"\n",
|
84 |
-
"model.eval()\n",
|
85 |
-
"\n",
|
86 |
-
"image = Image.open(\"/content/drive/MyDrive/donut/test/4.jpg\").convert(\"RGB\")\n",
|
87 |
-
"\n",
|
88 |
-
"with torch.no_grad():\n",
|
89 |
-
" output = model.inference(image=image, prompt=\"<s_Booking>\")\n",
|
90 |
-
"output"
|
91 |
-
],
|
92 |
-
"metadata": {
|
93 |
-
"id": "dFfm72T93Z8G"
|
94 |
-
},
|
95 |
-
"execution_count": null,
|
96 |
-
"outputs": []
|
97 |
-
}
|
98 |
-
],
|
99 |
-
"metadata": {
|
100 |
-
"accelerator": "GPU",
|
101 |
-
"colab": {
|
102 |
-
"gpuType": "V100",
|
103 |
-
"provenance": []
|
104 |
-
},
|
105 |
-
"kernelspec": {
|
106 |
-
"display_name": "Python 3",
|
107 |
-
"name": "python3"
|
108 |
-
},
|
109 |
-
"language_info": {
|
110 |
-
"name": "python"
|
111 |
-
}
|
112 |
-
},
|
113 |
-
"nbformat": 4,
|
114 |
-
"nbformat_minor": 0
|
115 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|