|
16 | 16 | "metadata": {}, |
17 | 17 | "outputs": [], |
18 | 18 | "source": [ |
19 | | - "MAX_TIME = 600\n", |
20 | | - "INIT_SIZE = 20" |
| 19 | + "MAX_TIME = 1\n", |
| 20 | + "INIT_SIZE = 5\n", |
| 21 | + "DEVICE = \"cpu\" # \"cuda:0\"" |
21 | 22 | ] |
22 | 23 | }, |
23 | 24 | { |
|
43 | 44 | "metadata": {}, |
44 | 45 | "source": [ |
45 | 46 | "# Chapter 11: Sequential Parameter Optimization\n", |
46 | | - "## Hyperparameter Tuning: pytorch with fashionMNIST Data " |
| 47 | + "## Hyperparameter Tuning: pytorch with fashionMNIST Data Using Hold-out Data Sets" |
47 | 48 | ] |
48 | 49 | }, |
49 | 50 | { |
|
133 | 134 | " iterate_dict_values,\n", |
134 | 135 | ")\n", |
135 | 136 | "\n", |
| 137 | + "from spotPython.torch.traintest import evaluate_cv, evaluate_hold_out\n", |
136 | 138 | "from spotPython.utils.convert import class_for_name\n", |
137 | 139 | "from spotPython.utils.eda import (\n", |
138 | 140 | " get_stars,\n", |
|
149 | 151 | "warnings.filterwarnings(\"ignore\")\n", |
150 | 152 | "\n", |
151 | 153 | "# Neural Net specific imports:\n", |
152 | | - "from spotPython.torch.netcvfashionMNIST import Net_CV_fashionMNIST" |
| 154 | + "from spotPython.torch.netfashionMNIST import Net_fashionMNIST" |
153 | 155 | ] |
154 | 156 | }, |
155 | 157 | { |
|
281 | 283 | "## 3. Select `algorithm` and `core_model_hyper_dict`" |
282 | 284 | ] |
283 | 285 | }, |
| 286 | + { |
| 287 | + "attachments": {}, |
| 288 | + "cell_type": "markdown", |
| 289 | + "metadata": {}, |
| 290 | + "source": [ |
| 291 | + "`spotPython` implements a class which is similar to the class described in the PyTorch tutorial. The class is called `Net_fashionMNIST` and is implemented in the file `netcifar10.py`. The class is imported here.\n", |
| 292 | + "\n", |
| 293 | + "Note: In addition to the class Net from the PyTorch tutorial, the class Net_CIFAR10 has additional attributes, namely:\n", |
| 294 | + "\n", |
| 295 | + "* learning rate (`lr`),\n", |
| 296 | + "* batchsize (`batch_size`),\n", |
| 297 | + "* epochs (`epochs`), and\n", |
| 298 | + "* k_folds (`k_folds`).\n", |
| 299 | + "\n", |
| 300 | + "Further attributes can be easily added to the class, e.g., `optimizer` or `loss_function`." |
| 301 | + ] |
| 302 | + }, |
284 | 303 | { |
285 | 304 | "cell_type": "code", |
286 | 305 | "execution_count": null, |
287 | 306 | "metadata": {}, |
288 | 307 | "outputs": [], |
289 | 308 | "source": [ |
290 | | - "# core_model = RidgeCV\n", |
291 | 309 | "core_model = Net_CV_fashionMNIST\n", |
292 | 310 | "fun_control = add_core_model_to_fun_control(core_model=core_model,\n", |
293 | 311 | " fun_control=fun_control,\n", |
|
381 | 399 | "weights = 1.0\n", |
382 | 400 | "shuffle = True\n", |
383 | 401 | "eval = \"train_hold_out\"\n", |
| 402 | + "device = DEVICE\n", |
384 | 403 | "\n", |
385 | 404 | "fun_control.update({\n", |
386 | 405 | " \"data_dir\": None,\n", |
|
690 | 709 | "metadata": {}, |
691 | 710 | "outputs": [], |
692 | 711 | "source": [ |
693 | | - "model_default.evaluate_hold_out(dataset = testset, shuffle=False)" |
| 712 | + "evaluate_hold_out(model_default, dataset = testset, shuffle=False)" |
694 | 713 | ] |
695 | 714 | }, |
696 | 715 | { |
|
699 | 718 | "metadata": {}, |
700 | 719 | "outputs": [], |
701 | 720 | "source": [ |
702 | | - "model_spot.evaluate_hold_out(dataset = testset, shuffle=False)" |
| 721 | + "evaluate_hold_out(model_spot, dataset = testset, shuffle=False)" |
703 | 722 | ] |
704 | 723 | }, |
705 | 724 | { |
|
0 commit comments