Skip to content

Commit 820384e

Browse files
committed
differences for PR #583
1 parent 57f2a35 commit 820384e

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

5-transfer-learning.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,65 @@ https://mermaid.live/edit#pako:eNpVkE1vgzAMhv9K5MPUSrQKAWUlh0kr9NZetp02drAgUCRIq
3030

3131
In this episode we will learn how use Keras to adapt a state-of-the-art pre-trained model to the [Dollar Street Dataset](https://zenodo.org/records/10970014).
3232

33+
::: spoiler
34+
### Google Colab + GPUs recommended
35+
This episode uses a respectably sized neural network — *DenseNet121*, which has 121 layers and over 7 million parameters. Training or "finetuning" this large of a model on a CPU is slow. Graphical Processing Units (GPUs) dramatically accelerate deep learning by speeding up the underlying matrix operations, often achieving **10-100x faster performance** than CPUs.
36+
37+
To speed things up, we recommend using [Google Colab](https://colab.research.google.com/), which provides free access to a GPU.
38+
39+
#### How to run this episode in Colab:
40+
41+
**A. Upload the `dl_workshop` folder to your Google Drive (excluding the `venv` folder).**
42+
43+
- This folder should contain the `data/` directory with the `.npy` files used in this episode. If the instructor has provided pre-filled notebooks for the workshop, please upload these as well. DO NOT UPLOAD your virtual environment folder as it is very large, and we'll be using Google Colab's pre-built environment instead.
44+
45+
**B. Start a blank notebook in Colab or open pre-filled notebook provided by instructor**
46+
47+
- Go to [https://colab.research.google.com/](https://colab.research.google.com/), click "New Notebook", and copy/paste code from this episode into cells.
48+
49+
**C. Enable GPU**
50+
51+
- Go to `Runtime > Change runtime type`
52+
- Set "Hardware accelerator" to `GPU`
53+
- Click "Save"
54+
55+
**D. Mount your Google Drive in the notebook:**
56+
57+
```python
58+
from google.colab import drive
59+
drive.mount('/content/drive')
60+
```
61+
**E. Set the data path to point to your uploaded folder, and load data:**
62+
63+
```python
64+
import pathlib
65+
import numpy as np
66+
DATA_FOLDER = pathlib.Path('/content/drive/MyDrive/dl_workshop/data')
67+
train_images = np.load(DATA_FOLDER / 'train_images.npy')
68+
val_images = np.load(DATA_FOLDER / 'test_images.npy')
69+
train_labels = np.load(DATA_FOLDER / 'train_labels.npy')
70+
val_labels = np.load(DATA_FOLDER / 'test_labels.npy')
71+
```
72+
73+
**F. Check if GPU is active:**
74+
75+
```python
76+
import tensorflow as tf
77+
78+
if tf.config.list_physical_devices('GPU'):
79+
print("GPU is available and will be used.")
80+
else:
81+
print("GPU not found. Training will use CPU and may be slow.")
82+
```
83+
84+
```output
85+
GPU is available and will be used.
86+
```
87+
88+
Assuming you have installed the GPU-enabled version of TensorFlow (which is pre-installed in Colab), you don't need to do anything else to enable GPU usage during training, tuning, or inference. TensorFlow/Keras will automatically use the GPU whenever it's available and supported. Note — we didn't include the GPU version of Tensorflow in this workshop's virtual environment because it can be finnicky to configure across operating systems, and many learners don't have the appropriate GPU hardware available.
89+
90+
:::
91+
3392

3493
## 1. Formulate / Outline the problem
3594

@@ -41,7 +100,8 @@ We load the data in the same way as the previous episode:
41100
import pathlib
42101
import numpy as np
43102

44-
DATA_FOLDER = pathlib.Path('data/dataset_dollarstreet/') # change to location where you stored the data
103+
# DATA_FOLDER = pathlib.Path('data/') # local path
104+
DATA_FOLDER = pathlib.Path('/content/drive/MyDrive/dl_workshop/data') # Colab path
45105
train_images = np.load(DATA_FOLDER / 'train_images.npy')
46106
val_images = np.load(DATA_FOLDER / 'test_images.npy')
47107
train_labels = np.load(DATA_FOLDER / 'train_labels.npy')

fig/.gitkeep

Whitespace-only changes.

md5sum.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"episodes/2-keras.md" "ebddf0ec35a0e97735a1ea7f1d204a40" "site/built/2-keras.md" "2025-02-11"
1010
"episodes/3-monitor-the-model.md" "93984f2bd862ddc2f10ba6749950b719" "site/built/3-monitor-the-model.md" "2025-02-11"
1111
"episodes/4-advanced-layer-types.md" "97b49e9dad76479bcfe608f0de2d52a4" "site/built/4-advanced-layer-types.md" "2025-02-11"
12-
"episodes/5-transfer-learning.md" "5808f2218c3f2d2d400e1ec1ad9f1f3c" "site/built/5-transfer-learning.md" "2025-02-11"
12+
"episodes/5-transfer-learning.md" "6118c2c2d1c86ec045309932b6edba8c" "site/built/5-transfer-learning.md" "2025-05-15"
1313
"episodes/6-outlook.md" "007728216562f3b52b983ff1908af5b7" "site/built/6-outlook.md" "2025-02-11"
1414
"instructors/bonus-material.md" "382832ea4eb097fc7781cb36992c1955" "site/built/bonus-material.md" "2025-02-11"
1515
"instructors/design.md" "1537f9d0c90cdfdb1781bd3daf94dadd" "site/built/design.md" "2025-02-11"

0 commit comments

Comments
 (0)