nina-m-m
commited on
Commit
•
ce4554c
1
Parent(s):
4537af3
Test modelrun using timm library
Browse files
notebooks/01_Demo_Pipeline_Usage_In_Code.ipynb
CHANGED
@@ -3,7 +3,10 @@
|
|
3 |
{
|
4 |
"cell_type": "markdown",
|
5 |
"source": [
|
6 |
-
"-
|
|
|
|
|
|
|
7 |
],
|
8 |
"metadata": {
|
9 |
"collapsed": false
|
@@ -11,84 +14,314 @@
|
|
11 |
},
|
12 |
{
|
13 |
"cell_type": "code",
|
14 |
-
"execution_count":
|
15 |
"outputs": [],
|
16 |
"source": [
|
17 |
-
"
|
18 |
-
"
|
19 |
"from pipeline_wrapper import MyPipeline"
|
20 |
],
|
21 |
"metadata": {
|
22 |
"collapsed": false,
|
23 |
"ExecuteTime": {
|
24 |
-
"end_time": "2024-02-
|
25 |
-
"start_time": "2024-02-
|
26 |
}
|
27 |
}
|
28 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
{
|
30 |
"cell_type": "code",
|
31 |
-
"execution_count":
|
32 |
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
{
|
34 |
"name": "stderr",
|
35 |
"output_type": "stream",
|
36 |
"text": [
|
37 |
-
"
|
|
|
|
|
38 |
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
}
|
40 |
],
|
41 |
"source": [
|
42 |
-
"
|
43 |
-
"
|
44 |
-
"
|
45 |
-
"
|
46 |
-
"
|
47 |
],
|
48 |
"metadata": {
|
49 |
"collapsed": false,
|
50 |
"ExecuteTime": {
|
51 |
-
"end_time": "2024-02-
|
52 |
-
"start_time": "2024-02-
|
53 |
}
|
54 |
}
|
55 |
},
|
56 |
{
|
57 |
"cell_type": "code",
|
58 |
-
"execution_count":
|
59 |
"outputs": [
|
60 |
{
|
61 |
-
"ename": "
|
62 |
-
"evalue": "'
|
63 |
"output_type": "error",
|
64 |
"traceback": [
|
65 |
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
66 |
-
"\u001B[1;
|
67 |
-
"
|
68 |
-
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\
|
69 |
-
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\
|
70 |
-
"\u001B[1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
]
|
72 |
}
|
73 |
],
|
74 |
"source": [
|
75 |
-
"feature_extractor = pipeline(\"
|
76 |
],
|
77 |
"metadata": {
|
78 |
"collapsed": false,
|
79 |
"ExecuteTime": {
|
80 |
-
"end_time": "2024-02-
|
81 |
-
"start_time": "2024-02-
|
82 |
}
|
83 |
}
|
84 |
},
|
85 |
{
|
86 |
"cell_type": "code",
|
87 |
-
"execution_count":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
"outputs": [
|
89 |
{
|
90 |
"ename": "OSError",
|
91 |
-
"evalue": "It looks like the config file at 'C:\\Users\\merti\\.cache\\huggingface\\hub\\models--HUBII-Platform--ECG2HRV\\snapshots\\
|
92 |
"output_type": "error",
|
93 |
"traceback": [
|
94 |
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
@@ -101,29 +334,44 @@
|
|
101 |
"\u001B[1;31mJSONDecodeError\u001B[0m: Expecting value: line 1 column 1 (char 0)",
|
102 |
"\nDuring handling of the above exception, another exception occurred:\n",
|
103 |
"\u001B[1;31mOSError\u001B[0m Traceback (most recent call last)",
|
104 |
-
"Cell \u001B[1;32mIn[
|
105 |
-
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\
|
106 |
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\models\\auto\\configuration_auto.py:1100\u001B[0m, in \u001B[0;36mAutoConfig.from_pretrained\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 1097\u001B[0m trust_remote_code \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtrust_remote_code\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[0;32m 1098\u001B[0m code_revision \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcode_revision\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[1;32m-> 1100\u001B[0m config_dict, unused_kwargs \u001B[38;5;241m=\u001B[39m PretrainedConfig\u001B[38;5;241m.\u001B[39mget_config_dict(pretrained_model_name_or_path, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 1101\u001B[0m has_remote_code \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto_map\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAutoConfig\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto_map\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[0;32m 1102\u001B[0m has_local_code \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodel_type\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict \u001B[38;5;129;01mand\u001B[39;00m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodel_type\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;129;01min\u001B[39;00m CONFIG_MAPPING\n",
|
107 |
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:634\u001B[0m, in \u001B[0;36mPretrainedConfig.get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 632\u001B[0m original_kwargs \u001B[38;5;241m=\u001B[39m copy\u001B[38;5;241m.\u001B[39mdeepcopy(kwargs)\n\u001B[0;32m 633\u001B[0m \u001B[38;5;66;03m# Get config dict associated with the base config file\u001B[39;00m\n\u001B[1;32m--> 634\u001B[0m config_dict, kwargs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mcls\u001B[39m\u001B[38;5;241m.\u001B[39m_get_config_dict(pretrained_model_name_or_path, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 635\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict:\n\u001B[0;32m 636\u001B[0m original_kwargs[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n",
|
108 |
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:722\u001B[0m, in \u001B[0;36mPretrainedConfig._get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 720\u001B[0m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m commit_hash\n\u001B[0;32m 721\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m (json\u001B[38;5;241m.\u001B[39mJSONDecodeError, \u001B[38;5;167;01mUnicodeDecodeError\u001B[39;00m):\n\u001B[1;32m--> 722\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mEnvironmentError\u001B[39;00m(\n\u001B[0;32m 723\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mIt looks like the config file at \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresolved_config_file\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m is not a valid JSON file.\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 724\u001B[0m )\n\u001B[0;32m 726\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m is_local:\n\u001B[0;32m 727\u001B[0m logger\u001B[38;5;241m.\u001B[39minfo(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mloading configuration file \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresolved_config_file\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
|
109 |
-
"\u001B[1;31mOSError\u001B[0m: It looks like the config file at 'C:\\Users\\merti\\.cache\\huggingface\\hub\\models--HUBII-Platform--ECG2HRV\\snapshots\\
|
110 |
]
|
111 |
}
|
112 |
],
|
113 |
"source": [
|
114 |
-
"
|
|
|
|
|
115 |
],
|
116 |
"metadata": {
|
117 |
"collapsed": false,
|
118 |
"ExecuteTime": {
|
119 |
-
"end_time": "2024-02-
|
120 |
-
"start_time": "2024-02-
|
121 |
}
|
122 |
}
|
123 |
},
|
124 |
{
|
125 |
"cell_type": "markdown",
|
126 |
-
"source": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
"metadata": {
|
128 |
"collapsed": false
|
129 |
}
|
@@ -132,7 +380,26 @@
|
|
132 |
"cell_type": "code",
|
133 |
"execution_count": null,
|
134 |
"outputs": [],
|
135 |
-
"source": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
"metadata": {
|
137 |
"collapsed": false
|
138 |
}
|
|
|
3 |
{
|
4 |
"cell_type": "markdown",
|
5 |
"source": [
|
6 |
+
"- https://huggingface.co/docs/transformers/custom_models - Alternative creating custom models\n",
|
7 |
+
"- https://huggingface.co/templates/feature-extraction - Template for inference API\n",
|
8 |
+
"- https://huggingface-widgets.netlify.app/ - Widgets for visualizing models in inference API\n",
|
9 |
+
"- https://huggingface.co/docs/hub/models-widgets#how-can-i-control-my-models-widget-inference-api-parameters - Controlling inference API parameters"
|
10 |
],
|
11 |
"metadata": {
|
12 |
"collapsed": false
|
|
|
14 |
},
|
15 |
{
|
16 |
"cell_type": "code",
|
17 |
+
"execution_count": 12,
|
18 |
"outputs": [],
|
19 |
"source": [
|
20 |
+
"import timm\n",
|
21 |
+
"import torch\n",
|
22 |
"from pipeline_wrapper import MyPipeline"
|
23 |
],
|
24 |
"metadata": {
|
25 |
"collapsed": false,
|
26 |
"ExecuteTime": {
|
27 |
+
"end_time": "2024-02-15T08:30:05.075994Z",
|
28 |
+
"start_time": "2024-02-15T08:29:59.741405700Z"
|
29 |
}
|
30 |
}
|
31 |
},
|
32 |
+
{
|
33 |
+
"cell_type": "markdown",
|
34 |
+
"source": [
|
35 |
+
"# Using timm to extract features"
|
36 |
+
],
|
37 |
+
"metadata": {
|
38 |
+
"collapsed": false
|
39 |
+
}
|
40 |
+
},
|
41 |
{
|
42 |
"cell_type": "code",
|
43 |
+
"execution_count": 10,
|
44 |
"outputs": [
|
45 |
+
{
|
46 |
+
"ename": "NameError",
|
47 |
+
"evalue": "name 'torch' is not defined",
|
48 |
+
"output_type": "error",
|
49 |
+
"traceback": [
|
50 |
+
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
51 |
+
"\u001B[1;31mNameError\u001B[0m Traceback (most recent call last)",
|
52 |
+
"Cell \u001B[1;32mIn[10], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m test_tensor \u001B[38;5;241m=\u001B[39m \u001B[43mtorch\u001B[49m\u001B[38;5;241m.\u001B[39mrandn(\u001B[38;5;241m2\u001B[39m, \u001B[38;5;241m3\u001B[39m, \u001B[38;5;241m1\u001B[39m, \u001B[38;5;241m1\u001B[39m)\n",
|
53 |
+
"\u001B[1;31mNameError\u001B[0m: name 'torch' is not defined"
|
54 |
+
]
|
55 |
+
}
|
56 |
+
],
|
57 |
+
"source": [
|
58 |
+
"test_tensor = torch.randn(2, 3, 1, 1)"
|
59 |
+
],
|
60 |
+
"metadata": {
|
61 |
+
"collapsed": false,
|
62 |
+
"ExecuteTime": {
|
63 |
+
"end_time": "2024-02-15T08:29:09.423837500Z",
|
64 |
+
"start_time": "2024-02-15T08:29:09.397259300Z"
|
65 |
+
}
|
66 |
+
}
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"cell_type": "code",
|
70 |
+
"execution_count": 31,
|
71 |
+
"outputs": [],
|
72 |
+
"source": [
|
73 |
+
"feature_extractor = timm.create_model('resnet18', pretrained=True, num_classes=0, global_pool='')\n",
|
74 |
+
"features = feature_extractor.forward_features(test_tensor)"
|
75 |
+
],
|
76 |
+
"metadata": {
|
77 |
+
"collapsed": false,
|
78 |
+
"ExecuteTime": {
|
79 |
+
"end_time": "2024-02-15T07:55:57.395514300Z",
|
80 |
+
"start_time": "2024-02-15T07:55:56.561361800Z"
|
81 |
+
}
|
82 |
+
}
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"execution_count": 32,
|
87 |
+
"outputs": [
|
88 |
+
{
|
89 |
+
"data": {
|
90 |
+
"text/plain": "tensor([[[[0.0000]],\n\n [[0.6944]],\n\n [[0.0000]],\n\n ...,\n\n [[0.0000]],\n\n [[0.0000]],\n\n [[0.0000]]],\n\n\n [[[0.0000]],\n\n [[0.0000]],\n\n [[0.0143]],\n\n ...,\n\n [[0.0000]],\n\n [[0.0000]],\n\n [[0.0000]]]], grad_fn=<ReluBackward0>)"
|
91 |
+
},
|
92 |
+
"execution_count": 32,
|
93 |
+
"metadata": {},
|
94 |
+
"output_type": "execute_result"
|
95 |
+
}
|
96 |
+
],
|
97 |
+
"source": [
|
98 |
+
"features"
|
99 |
+
],
|
100 |
+
"metadata": {
|
101 |
+
"collapsed": false,
|
102 |
+
"ExecuteTime": {
|
103 |
+
"end_time": "2024-02-15T07:55:58.303122200Z",
|
104 |
+
"start_time": "2024-02-15T07:55:58.266709100Z"
|
105 |
+
}
|
106 |
+
}
|
107 |
+
},
|
108 |
+
{
|
109 |
+
"cell_type": "code",
|
110 |
+
"execution_count": 15,
|
111 |
+
"outputs": [
|
112 |
+
{
|
113 |
+
"ename": "RuntimeError",
|
114 |
+
"evalue": "Unknown model (ECG2HRV)",
|
115 |
+
"output_type": "error",
|
116 |
+
"traceback": [
|
117 |
+
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
118 |
+
"\u001B[1;31mRuntimeError\u001B[0m Traceback (most recent call last)",
|
119 |
+
"Cell \u001B[1;32mIn[15], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m feature_extractor \u001B[38;5;241m=\u001B[39m \u001B[43mtimm\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mcreate_model\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mHUBII-Platform/ECG2HRV\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mpretrained\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;28;43;01mTrue\u001B[39;49;00m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mnum_classes\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mglobal_pool\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n",
|
120 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\timm\\models\\_factory.py:113\u001B[0m, in \u001B[0;36mcreate_model\u001B[1;34m(model_name, pretrained, pretrained_cfg, pretrained_cfg_overlay, checkpoint_path, scriptable, exportable, no_jit, **kwargs)\u001B[0m\n\u001B[0;32m 110\u001B[0m pretrained_cfg \u001B[38;5;241m=\u001B[39m pretrained_tag\n\u001B[0;32m 112\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m is_model(model_name):\n\u001B[1;32m--> 113\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mRuntimeError\u001B[39;00m(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mUnknown model (\u001B[39m\u001B[38;5;132;01m%s\u001B[39;00m\u001B[38;5;124m)\u001B[39m\u001B[38;5;124m'\u001B[39m \u001B[38;5;241m%\u001B[39m model_name)\n\u001B[0;32m 115\u001B[0m create_fn \u001B[38;5;241m=\u001B[39m model_entrypoint(model_name)\n\u001B[0;32m 116\u001B[0m \u001B[38;5;28;01mwith\u001B[39;00m set_layer_config(scriptable\u001B[38;5;241m=\u001B[39mscriptable, exportable\u001B[38;5;241m=\u001B[39mexportable, no_jit\u001B[38;5;241m=\u001B[39mno_jit):\n",
|
121 |
+
"\u001B[1;31mRuntimeError\u001B[0m: Unknown model (ECG2HRV)"
|
122 |
+
]
|
123 |
+
}
|
124 |
+
],
|
125 |
+
"source": [
|
126 |
+
"feature_extractor = timm.create_model('HUBII-Platform/ECG2HRV', pretrained=True, num_classes=0, global_pool='')"
|
127 |
+
],
|
128 |
+
"metadata": {
|
129 |
+
"collapsed": false,
|
130 |
+
"ExecuteTime": {
|
131 |
+
"end_time": "2024-02-15T08:30:32.648960900Z",
|
132 |
+
"start_time": "2024-02-15T08:30:32.601345400Z"
|
133 |
+
}
|
134 |
+
}
|
135 |
+
},
|
136 |
+
{
|
137 |
+
"cell_type": "markdown",
|
138 |
+
"source": [
|
139 |
+
"# Using transformers to extract features"
|
140 |
+
],
|
141 |
+
"metadata": {
|
142 |
+
"collapsed": false
|
143 |
+
}
|
144 |
+
},
|
145 |
+
{
|
146 |
+
"cell_type": "markdown",
|
147 |
+
"source": [
|
148 |
+
"1. Feature extraction task"
|
149 |
+
],
|
150 |
+
"metadata": {
|
151 |
+
"collapsed": false
|
152 |
+
}
|
153 |
+
},
|
154 |
+
{
|
155 |
+
"cell_type": "code",
|
156 |
+
"execution_count": 33,
|
157 |
+
"outputs": [
|
158 |
+
{
|
159 |
+
"data": {
|
160 |
+
"text/plain": "config.json: 0%| | 0.00/1.72k [00:00<?, ?B/s]",
|
161 |
+
"application/vnd.jupyter.widget-view+json": {
|
162 |
+
"version_major": 2,
|
163 |
+
"version_minor": 0,
|
164 |
+
"model_id": "b3723308dd9940aaa268f8f474eeb5df"
|
165 |
+
}
|
166 |
+
},
|
167 |
+
"metadata": {},
|
168 |
+
"output_type": "display_data"
|
169 |
+
},
|
170 |
{
|
171 |
"name": "stderr",
|
172 |
"output_type": "stream",
|
173 |
"text": [
|
174 |
+
"C:\\Users\\merti\\anaconda3\\envs\\py310\\lib\\site-packages\\huggingface_hub\\file_download.py:149: UserWarning: `huggingface_hub` cache-system uses symlinks by default to efficiently store duplicated files but your machine does not support them in C:\\Users\\merti\\.cache\\huggingface\\hub\\models--facebook--bart-base. Caching files will still work but in a degraded version that might require more space on your disk. This warning can be disabled by setting the `HF_HUB_DISABLE_SYMLINKS_WARNING` environment variable. For more details, see https://huggingface.co/docs/huggingface_hub/how-to-cache#limitations.\n",
|
175 |
+
"To support symlinks on Windows, you either need to activate Developer Mode or to run Python as an administrator. In order to see activate developer mode, see this article: https://docs.microsoft.com/en-us/windows/apps/get-started/enable-your-device-for-development\n",
|
176 |
+
" warnings.warn(message)\n"
|
177 |
]
|
178 |
+
},
|
179 |
+
{
|
180 |
+
"data": {
|
181 |
+
"text/plain": "model.safetensors: 0%| | 0.00/558M [00:00<?, ?B/s]",
|
182 |
+
"application/vnd.jupyter.widget-view+json": {
|
183 |
+
"version_major": 2,
|
184 |
+
"version_minor": 0,
|
185 |
+
"model_id": "5bffab7288404bc284624575d056c74d"
|
186 |
+
}
|
187 |
+
},
|
188 |
+
"metadata": {},
|
189 |
+
"output_type": "display_data"
|
190 |
+
},
|
191 |
+
{
|
192 |
+
"data": {
|
193 |
+
"text/plain": "vocab.json: 0%| | 0.00/899k [00:00<?, ?B/s]",
|
194 |
+
"application/vnd.jupyter.widget-view+json": {
|
195 |
+
"version_major": 2,
|
196 |
+
"version_minor": 0,
|
197 |
+
"model_id": "2f3359fbba014f02994e17163fcc0f1c"
|
198 |
+
}
|
199 |
+
},
|
200 |
+
"metadata": {},
|
201 |
+
"output_type": "display_data"
|
202 |
+
},
|
203 |
+
{
|
204 |
+
"data": {
|
205 |
+
"text/plain": "merges.txt: 0%| | 0.00/456k [00:00<?, ?B/s]",
|
206 |
+
"application/vnd.jupyter.widget-view+json": {
|
207 |
+
"version_major": 2,
|
208 |
+
"version_minor": 0,
|
209 |
+
"model_id": "b315c7ae15b64a148df558539c3fc980"
|
210 |
+
}
|
211 |
+
},
|
212 |
+
"metadata": {},
|
213 |
+
"output_type": "display_data"
|
214 |
+
},
|
215 |
+
{
|
216 |
+
"data": {
|
217 |
+
"text/plain": "tokenizer.json: 0%| | 0.00/1.36M [00:00<?, ?B/s]",
|
218 |
+
"application/vnd.jupyter.widget-view+json": {
|
219 |
+
"version_major": 2,
|
220 |
+
"version_minor": 0,
|
221 |
+
"model_id": "1b275b44c1cf4d8eaa9b57aedad04240"
|
222 |
+
}
|
223 |
+
},
|
224 |
+
"metadata": {},
|
225 |
+
"output_type": "display_data"
|
226 |
}
|
227 |
],
|
228 |
"source": [
|
229 |
+
"# Example with pipeline\n",
|
230 |
+
"from transformers import pipeline\n",
|
231 |
+
"checkpoint = \"facebook/bart-base\"\n",
|
232 |
+
"feature_extractor = pipeline(\"feature-extraction\", framework=\"pt\",model=checkpoint)\n",
|
233 |
+
"text = \"Transformers is an awesome library!\""
|
234 |
],
|
235 |
"metadata": {
|
236 |
"collapsed": false,
|
237 |
"ExecuteTime": {
|
238 |
+
"end_time": "2024-02-15T08:02:58.086587200Z",
|
239 |
+
"start_time": "2024-02-15T08:02:15.582501300Z"
|
240 |
}
|
241 |
}
|
242 |
},
|
243 |
{
|
244 |
"cell_type": "code",
|
245 |
+
"execution_count": 7,
|
246 |
"outputs": [
|
247 |
{
|
248 |
+
"ename": "OSError",
|
249 |
+
"evalue": "It looks like the config file at 'C:\\Users\\merti\\.cache\\huggingface\\hub\\models--HUBII-Platform--ECG2HRV\\snapshots\\75f67e01de12e33cfb05cfbfed35ff621246b3f9\\config.json' is not a valid JSON file.",
|
250 |
"output_type": "error",
|
251 |
"traceback": [
|
252 |
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
253 |
+
"\u001B[1;31mJSONDecodeError\u001B[0m Traceback (most recent call last)",
|
254 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:719\u001B[0m, in \u001B[0;36mPretrainedConfig._get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 717\u001B[0m \u001B[38;5;28;01mtry\u001B[39;00m:\n\u001B[0;32m 718\u001B[0m \u001B[38;5;66;03m# Load config dict\u001B[39;00m\n\u001B[1;32m--> 719\u001B[0m config_dict \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mcls\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_dict_from_json_file\u001B[49m\u001B[43m(\u001B[49m\u001B[43mresolved_config_file\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 720\u001B[0m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m commit_hash\n",
|
255 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:818\u001B[0m, in \u001B[0;36mPretrainedConfig._dict_from_json_file\u001B[1;34m(cls, json_file)\u001B[0m\n\u001B[0;32m 817\u001B[0m text \u001B[38;5;241m=\u001B[39m reader\u001B[38;5;241m.\u001B[39mread()\n\u001B[1;32m--> 818\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43mjson\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mloads\u001B[49m\u001B[43m(\u001B[49m\u001B[43mtext\u001B[49m\u001B[43m)\u001B[49m\n",
|
256 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\json\\__init__.py:346\u001B[0m, in \u001B[0;36mloads\u001B[1;34m(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)\u001B[0m\n\u001B[0;32m 343\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m (\u001B[38;5;28mcls\u001B[39m \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m object_hook \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m\n\u001B[0;32m 344\u001B[0m parse_int \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m parse_float \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m\n\u001B[0;32m 345\u001B[0m parse_constant \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m object_pairs_hook \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m kw):\n\u001B[1;32m--> 346\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m \u001B[43m_default_decoder\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mdecode\u001B[49m\u001B[43m(\u001B[49m\u001B[43ms\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 347\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mcls\u001B[39m \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n",
|
257 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\json\\decoder.py:337\u001B[0m, in \u001B[0;36mJSONDecoder.decode\u001B[1;34m(self, s, _w)\u001B[0m\n\u001B[0;32m 333\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"Return the Python representation of ``s`` (a ``str`` instance\u001B[39;00m\n\u001B[0;32m 334\u001B[0m \u001B[38;5;124;03mcontaining a JSON document).\u001B[39;00m\n\u001B[0;32m 335\u001B[0m \n\u001B[0;32m 336\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[1;32m--> 337\u001B[0m obj, end \u001B[38;5;241m=\u001B[39m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mraw_decode\u001B[49m\u001B[43m(\u001B[49m\u001B[43ms\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43midx\u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m_w\u001B[49m\u001B[43m(\u001B[49m\u001B[43ms\u001B[49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m0\u001B[39;49m\u001B[43m)\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mend\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m 338\u001B[0m end \u001B[38;5;241m=\u001B[39m _w(s, end)\u001B[38;5;241m.\u001B[39mend()\n",
|
258 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\json\\decoder.py:355\u001B[0m, in \u001B[0;36mJSONDecoder.raw_decode\u001B[1;34m(self, s, idx)\u001B[0m\n\u001B[0;32m 354\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m \u001B[38;5;167;01mStopIteration\u001B[39;00m \u001B[38;5;28;01mas\u001B[39;00m err:\n\u001B[1;32m--> 355\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m JSONDecodeError(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mExpecting value\u001B[39m\u001B[38;5;124m\"\u001B[39m, s, err\u001B[38;5;241m.\u001B[39mvalue) \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m\n\u001B[0;32m 356\u001B[0m \u001B[38;5;28;01mreturn\u001B[39;00m obj, end\n",
|
259 |
+
"\u001B[1;31mJSONDecodeError\u001B[0m: Expecting value: line 1 column 1 (char 0)",
|
260 |
+
"\nDuring handling of the above exception, another exception occurred:\n",
|
261 |
+
"\u001B[1;31mOSError\u001B[0m Traceback (most recent call last)",
|
262 |
+
"Cell \u001B[1;32mIn[7], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m feature_extractor \u001B[38;5;241m=\u001B[39m \u001B[43mpipeline\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[38;5;124;43mfeature-extraction\u001B[39;49m\u001B[38;5;124;43m\"\u001B[39;49m\u001B[43m,\u001B[49m\u001B[43m \u001B[49m\u001B[43mmodel\u001B[49m\u001B[43m \u001B[49m\u001B[38;5;241;43m=\u001B[39;49m\u001B[43m \u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mHUBII-Platform/ECG2HRV\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n",
|
263 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\pipelines\\__init__.py:782\u001B[0m, in \u001B[0;36mpipeline\u001B[1;34m(task, model, config, tokenizer, feature_extractor, image_processor, framework, revision, use_fast, token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs)\u001B[0m\n\u001B[0;32m 779\u001B[0m adapter_config \u001B[38;5;241m=\u001B[39m json\u001B[38;5;241m.\u001B[39mload(f)\n\u001B[0;32m 780\u001B[0m model \u001B[38;5;241m=\u001B[39m adapter_config[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mbase_model_name_or_path\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[1;32m--> 782\u001B[0m config \u001B[38;5;241m=\u001B[39m AutoConfig\u001B[38;5;241m.\u001B[39mfrom_pretrained(\n\u001B[0;32m 783\u001B[0m model, _from_pipeline\u001B[38;5;241m=\u001B[39mtask, code_revision\u001B[38;5;241m=\u001B[39mcode_revision, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mhub_kwargs, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mmodel_kwargs\n\u001B[0;32m 784\u001B[0m )\n\u001B[0;32m 785\u001B[0m hub_kwargs[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m config\u001B[38;5;241m.\u001B[39m_commit_hash\n\u001B[0;32m 787\u001B[0m custom_tasks \u001B[38;5;241m=\u001B[39m {}\n",
|
264 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\models\\auto\\configuration_auto.py:1100\u001B[0m, in \u001B[0;36mAutoConfig.from_pretrained\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 1097\u001B[0m trust_remote_code \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtrust_remote_code\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[0;32m 1098\u001B[0m code_revision \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcode_revision\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[1;32m-> 1100\u001B[0m config_dict, unused_kwargs \u001B[38;5;241m=\u001B[39m PretrainedConfig\u001B[38;5;241m.\u001B[39mget_config_dict(pretrained_model_name_or_path, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 1101\u001B[0m has_remote_code \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto_map\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAutoConfig\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto_map\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[0;32m 1102\u001B[0m has_local_code \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodel_type\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict \u001B[38;5;129;01mand\u001B[39;00m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodel_type\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;129;01min\u001B[39;00m CONFIG_MAPPING\n",
|
265 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:634\u001B[0m, in \u001B[0;36mPretrainedConfig.get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 632\u001B[0m original_kwargs \u001B[38;5;241m=\u001B[39m copy\u001B[38;5;241m.\u001B[39mdeepcopy(kwargs)\n\u001B[0;32m 633\u001B[0m \u001B[38;5;66;03m# Get config dict associated with the base config file\u001B[39;00m\n\u001B[1;32m--> 634\u001B[0m config_dict, kwargs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mcls\u001B[39m\u001B[38;5;241m.\u001B[39m_get_config_dict(pretrained_model_name_or_path, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 635\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict:\n\u001B[0;32m 636\u001B[0m original_kwargs[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n",
|
266 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:722\u001B[0m, in \u001B[0;36mPretrainedConfig._get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 720\u001B[0m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m commit_hash\n\u001B[0;32m 721\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m (json\u001B[38;5;241m.\u001B[39mJSONDecodeError, \u001B[38;5;167;01mUnicodeDecodeError\u001B[39;00m):\n\u001B[1;32m--> 722\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mEnvironmentError\u001B[39;00m(\n\u001B[0;32m 723\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mIt looks like the config file at \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresolved_config_file\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m is not a valid JSON file.\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 724\u001B[0m )\n\u001B[0;32m 726\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m is_local:\n\u001B[0;32m 727\u001B[0m logger\u001B[38;5;241m.\u001B[39minfo(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mloading configuration file \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresolved_config_file\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
|
267 |
+
"\u001B[1;31mOSError\u001B[0m: It looks like the config file at 'C:\\Users\\merti\\.cache\\huggingface\\hub\\models--HUBII-Platform--ECG2HRV\\snapshots\\75f67e01de12e33cfb05cfbfed35ff621246b3f9\\config.json' is not a valid JSON file."
|
268 |
]
|
269 |
}
|
270 |
],
|
271 |
"source": [
|
272 |
+
"feature_extractor = pipeline(\"feature-extraction\", model = 'HUBII-Platform/ECG2HRV')"
|
273 |
],
|
274 |
"metadata": {
|
275 |
"collapsed": false,
|
276 |
"ExecuteTime": {
|
277 |
+
"end_time": "2024-02-15T08:25:26.931190300Z",
|
278 |
+
"start_time": "2024-02-15T08:25:25.877444800Z"
|
279 |
}
|
280 |
}
|
281 |
},
|
282 |
{
|
283 |
"cell_type": "code",
|
284 |
+
"execution_count": null,
|
285 |
+
"outputs": [],
|
286 |
+
"source": [
|
287 |
+
"PIPELINE_REGISTRY.register_pipeline(\n",
|
288 |
+
" \"ecg2hrv\",\n",
|
289 |
+
" pipeline_class=MyPipeline,\n",
|
290 |
+
" # model_class=MyModel\n",
|
291 |
+
")\n",
|
292 |
+
"feature_extractor = pipeline(\"ecg2hrv\")"
|
293 |
+
],
|
294 |
+
"metadata": {
|
295 |
+
"collapsed": false
|
296 |
+
}
|
297 |
+
},
|
298 |
+
{
|
299 |
+
"cell_type": "code",
|
300 |
+
"execution_count": null,
|
301 |
+
"outputs": [],
|
302 |
+
"source": [
|
303 |
+
"feature_extractor = pipeline(\"ecg2hrv\", model=\"HUBII-Platform/ECG2HRV\")"
|
304 |
+
],
|
305 |
+
"metadata": {
|
306 |
+
"collapsed": false
|
307 |
+
}
|
308 |
+
},
|
309 |
+
{
|
310 |
+
"cell_type": "markdown",
|
311 |
+
"source": [
|
312 |
+
"2. AutoModel"
|
313 |
+
],
|
314 |
+
"metadata": {
|
315 |
+
"collapsed": false
|
316 |
+
}
|
317 |
+
},
|
318 |
+
{
|
319 |
+
"cell_type": "code",
|
320 |
+
"execution_count": 2,
|
321 |
"outputs": [
|
322 |
{
|
323 |
"ename": "OSError",
|
324 |
+
"evalue": "It looks like the config file at 'C:\\Users\\merti\\.cache\\huggingface\\hub\\models--HUBII-Platform--ECG2HRV\\snapshots\\75f67e01de12e33cfb05cfbfed35ff621246b3f9\\config.json' is not a valid JSON file.",
|
325 |
"output_type": "error",
|
326 |
"traceback": [
|
327 |
"\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
|
|
|
334 |
"\u001B[1;31mJSONDecodeError\u001B[0m: Expecting value: line 1 column 1 (char 0)",
|
335 |
"\nDuring handling of the above exception, another exception occurred:\n",
|
336 |
"\u001B[1;31mOSError\u001B[0m Traceback (most recent call last)",
|
337 |
+
"Cell \u001B[1;32mIn[2], line 3\u001B[0m\n\u001B[0;32m 1\u001B[0m \u001B[38;5;66;03m# Example with AutoModel\u001B[39;00m\n\u001B[0;32m 2\u001B[0m \u001B[38;5;28;01mfrom\u001B[39;00m \u001B[38;5;21;01mtransformers\u001B[39;00m \u001B[38;5;28;01mimport\u001B[39;00m AutoTokenizer, AutoModel\n\u001B[1;32m----> 3\u001B[0m model \u001B[38;5;241m=\u001B[39m \u001B[43mAutoModel\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mfrom_pretrained\u001B[49m\u001B[43m(\u001B[49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[38;5;124;43mHUBII-Platform/ECG2HRV\u001B[39;49m\u001B[38;5;124;43m'\u001B[39;49m\u001B[43m)\u001B[49m\n",
|
338 |
+
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\models\\auto\\auto_factory.py:526\u001B[0m, in \u001B[0;36m_BaseAutoModelClass.from_pretrained\u001B[1;34m(cls, pretrained_model_name_or_path, *model_args, **kwargs)\u001B[0m\n\u001B[0;32m 523\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m kwargs\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mquantization_config\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m) \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m 524\u001B[0m _ \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mquantization_config\u001B[39m\u001B[38;5;124m\"\u001B[39m)\n\u001B[1;32m--> 526\u001B[0m config, kwargs \u001B[38;5;241m=\u001B[39m AutoConfig\u001B[38;5;241m.\u001B[39mfrom_pretrained(\n\u001B[0;32m 527\u001B[0m pretrained_model_name_or_path,\n\u001B[0;32m 528\u001B[0m return_unused_kwargs\u001B[38;5;241m=\u001B[39m\u001B[38;5;28;01mTrue\u001B[39;00m,\n\u001B[0;32m 529\u001B[0m trust_remote_code\u001B[38;5;241m=\u001B[39mtrust_remote_code,\n\u001B[0;32m 530\u001B[0m code_revision\u001B[38;5;241m=\u001B[39mcode_revision,\n\u001B[0;32m 531\u001B[0m _commit_hash\u001B[38;5;241m=\u001B[39mcommit_hash,\n\u001B[0;32m 532\u001B[0m \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mhub_kwargs,\n\u001B[0;32m 533\u001B[0m \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs,\n\u001B[0;32m 534\u001B[0m )\n\u001B[0;32m 536\u001B[0m \u001B[38;5;66;03m# if torch_dtype=auto was passed here, ensure to pass it on\u001B[39;00m\n\u001B[0;32m 537\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m kwargs_orig\u001B[38;5;241m.\u001B[39mget(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtorch_dtype\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m) \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto\u001B[39m\u001B[38;5;124m\"\u001B[39m:\n",
|
339 |
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\models\\auto\\configuration_auto.py:1100\u001B[0m, in \u001B[0;36mAutoConfig.from_pretrained\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 1097\u001B[0m trust_remote_code \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mtrust_remote_code\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[0;32m 1098\u001B[0m code_revision \u001B[38;5;241m=\u001B[39m kwargs\u001B[38;5;241m.\u001B[39mpop(\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mcode_revision\u001B[39m\u001B[38;5;124m\"\u001B[39m, \u001B[38;5;28;01mNone\u001B[39;00m)\n\u001B[1;32m-> 1100\u001B[0m config_dict, unused_kwargs \u001B[38;5;241m=\u001B[39m PretrainedConfig\u001B[38;5;241m.\u001B[39mget_config_dict(pretrained_model_name_or_path, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 1101\u001B[0m has_remote_code \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto_map\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict \u001B[38;5;129;01mand\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mAutoConfig\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mauto_map\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n\u001B[0;32m 1102\u001B[0m has_local_code \u001B[38;5;241m=\u001B[39m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodel_type\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict \u001B[38;5;129;01mand\u001B[39;00m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mmodel_type\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;129;01min\u001B[39;00m CONFIG_MAPPING\n",
|
340 |
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:634\u001B[0m, in \u001B[0;36mPretrainedConfig.get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 632\u001B[0m original_kwargs \u001B[38;5;241m=\u001B[39m copy\u001B[38;5;241m.\u001B[39mdeepcopy(kwargs)\n\u001B[0;32m 633\u001B[0m \u001B[38;5;66;03m# Get config dict associated with the base config file\u001B[39;00m\n\u001B[1;32m--> 634\u001B[0m config_dict, kwargs \u001B[38;5;241m=\u001B[39m \u001B[38;5;28mcls\u001B[39m\u001B[38;5;241m.\u001B[39m_get_config_dict(pretrained_model_name_or_path, \u001B[38;5;241m*\u001B[39m\u001B[38;5;241m*\u001B[39mkwargs)\n\u001B[0;32m 635\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m \u001B[38;5;129;01min\u001B[39;00m config_dict:\n\u001B[0;32m 636\u001B[0m original_kwargs[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m]\n",
|
341 |
"File \u001B[1;32m~\\anaconda3\\envs\\py310\\lib\\site-packages\\transformers\\configuration_utils.py:722\u001B[0m, in \u001B[0;36mPretrainedConfig._get_config_dict\u001B[1;34m(cls, pretrained_model_name_or_path, **kwargs)\u001B[0m\n\u001B[0;32m 720\u001B[0m config_dict[\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124m_commit_hash\u001B[39m\u001B[38;5;124m\"\u001B[39m] \u001B[38;5;241m=\u001B[39m commit_hash\n\u001B[0;32m 721\u001B[0m \u001B[38;5;28;01mexcept\u001B[39;00m (json\u001B[38;5;241m.\u001B[39mJSONDecodeError, \u001B[38;5;167;01mUnicodeDecodeError\u001B[39;00m):\n\u001B[1;32m--> 722\u001B[0m \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mEnvironmentError\u001B[39;00m(\n\u001B[0;32m 723\u001B[0m \u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mIt looks like the config file at \u001B[39m\u001B[38;5;124m'\u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresolved_config_file\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m'\u001B[39m\u001B[38;5;124m is not a valid JSON file.\u001B[39m\u001B[38;5;124m\"\u001B[39m\n\u001B[0;32m 724\u001B[0m )\n\u001B[0;32m 726\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m is_local:\n\u001B[0;32m 727\u001B[0m logger\u001B[38;5;241m.\u001B[39minfo(\u001B[38;5;124mf\u001B[39m\u001B[38;5;124m\"\u001B[39m\u001B[38;5;124mloading configuration file \u001B[39m\u001B[38;5;132;01m{\u001B[39;00mresolved_config_file\u001B[38;5;132;01m}\u001B[39;00m\u001B[38;5;124m\"\u001B[39m)\n",
|
342 |
+
"\u001B[1;31mOSError\u001B[0m: It looks like the config file at 'C:\\Users\\merti\\.cache\\huggingface\\hub\\models--HUBII-Platform--ECG2HRV\\snapshots\\75f67e01de12e33cfb05cfbfed35ff621246b3f9\\config.json' is not a valid JSON file."
|
343 |
]
|
344 |
}
|
345 |
],
|
346 |
"source": [
|
347 |
+
"# Example with AutoModel\n",
|
348 |
+
"from transformers import AutoTokenizer, AutoModel\n",
|
349 |
+
"model = AutoModel.from_pretrained('HUBII-Platform/ECG2HRV')"
|
350 |
],
|
351 |
"metadata": {
|
352 |
"collapsed": false,
|
353 |
"ExecuteTime": {
|
354 |
+
"end_time": "2024-02-15T08:19:30.471734700Z",
|
355 |
+
"start_time": "2024-02-15T08:19:29.806536100Z"
|
356 |
}
|
357 |
}
|
358 |
},
|
359 |
{
|
360 |
"cell_type": "markdown",
|
361 |
+
"source": [
|
362 |
+
"3. Batched feature extraction - not supported (see https://huggingface.co/docs/transformers/main_classes/feature_extractor#transformers.BatchFeature)\n",
|
363 |
+
"Not possible since it is not a model itself but a component used in the pipeline"
|
364 |
+
],
|
365 |
+
"metadata": {
|
366 |
+
"collapsed": false
|
367 |
+
}
|
368 |
+
},
|
369 |
+
{
|
370 |
+
"cell_type": "markdown",
|
371 |
+
"source": [
|
372 |
+
"# Using simple download\n",
|
373 |
+
"(See https://huggingface.co/julien-c/wine-quality?structured_data=%7B%7D)"
|
374 |
+
],
|
375 |
"metadata": {
|
376 |
"collapsed": false
|
377 |
}
|
|
|
380 |
"cell_type": "code",
|
381 |
"execution_count": null,
|
382 |
"outputs": [],
|
383 |
+
"source": [
|
384 |
+
"from huggingface_hub import hf_hub_url, cached_download\n",
|
385 |
+
"import joblib"
|
386 |
+
],
|
387 |
+
"metadata": {
|
388 |
+
"collapsed": false
|
389 |
+
}
|
390 |
+
},
|
391 |
+
{
|
392 |
+
"cell_type": "code",
|
393 |
+
"execution_count": null,
|
394 |
+
"outputs": [],
|
395 |
+
"source": [
|
396 |
+
"REPO_ID = \"HUBII-Platform/ECG2HRV\"\n",
|
397 |
+
"FILENAME = \"feature-extractor.joblib\"\n",
|
398 |
+
"\n",
|
399 |
+
"model = joblib.load(cached_download(\n",
|
400 |
+
" hf_hub_url(REPO_ID, FILENAME)\n",
|
401 |
+
"))\n"
|
402 |
+
],
|
403 |
"metadata": {
|
404 |
"collapsed": false
|
405 |
}
|