Timothy Chan
commited on
Delete donut_train.ipynb
Browse files- donut_train.ipynb +0 -110
donut_train.ipynb
DELETED
@@ -1,110 +0,0 @@
|
|
1 |
-
{
|
2 |
-
"cells": [
|
3 |
-
{
|
4 |
-
"cell_type": "code",
|
5 |
-
"execution_count": null,
|
6 |
-
"metadata": {
|
7 |
-
"id": "-BZ2HFB9OtWP"
|
8 |
-
},
|
9 |
-
"outputs": [],
|
10 |
-
"source": [
|
11 |
-
"from google.colab import drive\n",
|
12 |
-
"drive.mount('/content/drive')\n",
|
13 |
-
"%cd /content/drive/MyDrive/donut"
|
14 |
-
]
|
15 |
-
},
|
16 |
-
{
|
17 |
-
"cell_type": "code",
|
18 |
-
"execution_count": null,
|
19 |
-
"metadata": {
|
20 |
-
"colab": {
|
21 |
-
"background_save": true
|
22 |
-
},
|
23 |
-
"id": "SJpD4AAj7qeZ"
|
24 |
-
},
|
25 |
-
"outputs": [],
|
26 |
-
"source": [
|
27 |
-
"!pip install transformers==4.25.1\n",
|
28 |
-
"!pip install timm==0.5.4\n",
|
29 |
-
"!pip install donut-python"
|
30 |
-
]
|
31 |
-
},
|
32 |
-
{
|
33 |
-
"cell_type": "code",
|
34 |
-
"source": [
|
35 |
-
"from donut import DonutModel\n",
|
36 |
-
"from PIL import Image\n",
|
37 |
-
"import torch"
|
38 |
-
],
|
39 |
-
"metadata": {
|
40 |
-
"id": "PxFaO3rfDHQJ"
|
41 |
-
},
|
42 |
-
"execution_count": null,
|
43 |
-
"outputs": []
|
44 |
-
},
|
45 |
-
{
|
46 |
-
"cell_type": "code",
|
47 |
-
"execution_count": null,
|
48 |
-
"metadata": {
|
49 |
-
"id": "Ro21MdJPSTZs"
|
50 |
-
},
|
51 |
-
"outputs": [],
|
52 |
-
"source": [
|
53 |
-
"# Copy one default config yaml file and amend to fit your use case.\n",
|
54 |
-
"!python train.py --config ./config/train_Booking.yaml"
|
55 |
-
]
|
56 |
-
},
|
57 |
-
{
|
58 |
-
"cell_type": "code",
|
59 |
-
"execution_count": null,
|
60 |
-
"metadata": {
|
61 |
-
"id": "J1ITHX4jV2Go"
|
62 |
-
},
|
63 |
-
"outputs": [],
|
64 |
-
"source": [
|
65 |
-
"# After train, you can evaluate and use the model.\n",
|
66 |
-
"\n",
|
67 |
-
"model = DonutModel.from_pretrained(\"/content/drive/MyDrive/donut/result/train_Booking/20240327_032854\")\n",
|
68 |
-
"if torch.cuda.is_available():\n",
|
69 |
-
" model.half()\n",
|
70 |
-
" device = torch.device(\"cuda\")\n",
|
71 |
-
" model.to(device)\n",
|
72 |
-
"else:\n",
|
73 |
-
" model.encoder.to(torch.bfloat16)\n",
|
74 |
-
"\n",
|
75 |
-
"model.eval()"
|
76 |
-
]
|
77 |
-
},
|
78 |
-
{
|
79 |
-
"cell_type": "code",
|
80 |
-
"execution_count": null,
|
81 |
-
"metadata": {
|
82 |
-
"id": "2UhjFTmrWIrX"
|
83 |
-
},
|
84 |
-
"outputs": [],
|
85 |
-
"source": [
|
86 |
-
"image = Image.open(\"/content/COSCO_000.jpg\").convert(\"RGB\")\n",
|
87 |
-
"with torch.no_grad():\n",
|
88 |
-
" # My dataset name is Booking , tag i.e. <s_Booking>\n",
|
89 |
-
" output = model.inference(image=image, prompt=\"<s_Booking>\")\n",
|
90 |
-
"output"
|
91 |
-
]
|
92 |
-
}
|
93 |
-
],
|
94 |
-
"metadata": {
|
95 |
-
"accelerator": "GPU",
|
96 |
-
"colab": {
|
97 |
-
"gpuType": "V100",
|
98 |
-
"provenance": []
|
99 |
-
},
|
100 |
-
"kernelspec": {
|
101 |
-
"display_name": "Python 3",
|
102 |
-
"name": "python3"
|
103 |
-
},
|
104 |
-
"language_info": {
|
105 |
-
"name": "python"
|
106 |
-
}
|
107 |
-
},
|
108 |
-
"nbformat": 4,
|
109 |
-
"nbformat_minor": 0
|
110 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|