Skip to content

Commit 3f5e5f5

Browse files
authored
Merge pull request #1059 from cindyhfls/DL_2026_final_review
Dl 2026 final review
2 parents 183709b + a87d8fa commit 3f5e5f5

15 files changed

Lines changed: 106 additions & 134 deletions

File tree

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ numpy>=2.0
55
pandas>=2.2
66
matplotlib>=3.9
77
torch>=2.6
8-
torchvision>=0.15
9-
torchaudio>=2.0
10-
scikit-learn>=1.7
8+
torchvision>=0.21
9+
torchaudio>=2.6
10+
scikit-learn>=1.6
1111
scipy>=1.13
1212
Pillow>=10.0
1313
imageio>=2.30
@@ -38,3 +38,4 @@ textattack
3838
tokenizers==0.22.2
3939
transformers
4040
vibecheck
41+
typing_extensions

tutorials/W2D1_Regularization/W2D1_Tutorial1.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,9 @@
112112
},
113113
"outputs": [],
114114
"source": [
115-
"# @title Install dependencies\n",
116-
"!pip install imageio --quiet\n",
117-
"!pip install imageio-ffmpeg --quiet"
115+
"# @title Uncomment to install dependencies\n",
116+
"# !pip install imageio --quiet\n",
117+
"# !pip install imageio-ffmpeg --quiet"
118118
]
119119
},
120120
{

tutorials/W2D1_Regularization/W2D1_Tutorial2.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@
115115
},
116116
"outputs": [],
117117
"source": [
118-
"# @title Install and check dependencies\n",
119-
"!pip install imageio --quiet\n",
120-
"!pip install imageio-ffmpeg --quiet"
118+
"# @title Uncomment to install dependencies\n",
119+
"# !pip install imageio --quiet\n",
120+
"# !pip install imageio-ffmpeg --quiet"
121121
]
122122
},
123123
{

tutorials/W2D2_Convnets/W2D2_Tutorial1.ipynb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@
105105
"feedback_prefix = \"W2D2_T1\""
106106
]
107107
},
108-
{
109-
"cell_type": "code",
110-
"execution_count": null,
111-
"metadata": {
112-
"cellView": "form",
113-
"execution": {}
114-
},
115-
"outputs": [],
116-
"source": [
117-
"# @title Install dependencies\n",
118-
"!pip install Pillow --quiet"
119-
]
120-
},
121108
{
122109
"cell_type": "code",
123110
"execution_count": null,
@@ -4485,7 +4472,7 @@
44854472
"name": "python",
44864473
"nbconvert_exporter": "python",
44874474
"pygments_lexer": "ipython3",
4488-
"version": "3.10.20"
4475+
"version": "3.9.25"
44894476
}
44904477
},
44914478
"nbformat": 4,

tutorials/W2D2_Convnets/W2D2_Tutorial2.ipynb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,6 @@
105105
"feedback_prefix = \"W2D2_T2\""
106106
]
107107
},
108-
{
109-
"cell_type": "code",
110-
"execution_count": null,
111-
"metadata": {
112-
"cellView": "form",
113-
"execution": {}
114-
},
115-
"outputs": [],
116-
"source": [
117-
"# @title Install dependencies\n",
118-
"!pip install Pillow --quiet"
119-
]
120-
},
121108
{
122109
"cell_type": "code",
123110
"execution_count": null,
@@ -1638,7 +1625,8 @@
16381625
"name": "python3"
16391626
},
16401627
"kernelspec": {
1641-
"display_name": "Python 3",
1628+
"display_name": "nma-dl",
1629+
"language": "python",
16421630
"name": "python3"
16431631
},
16441632
"language_info": {
@@ -1651,7 +1639,7 @@
16511639
"name": "python",
16521640
"nbconvert_exporter": "python",
16531641
"pygments_lexer": "ipython3",
1654-
"version": "3.10.20"
1642+
"version": "3.9.25"
16551643
}
16561644
},
16571645
"nbformat": 4,

tutorials/W2D2_Convnets/W2D2_Tutorial3.ipynb

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@
112112
{
113113
"cell_type": "code",
114114
"execution_count": null,
115-
"metadata": {
116-
"cellView": "form",
117-
"execution": {}
118-
},
115+
"metadata": {},
119116
"outputs": [],
120117
"source": [
121-
"# @title Install dependencies\n",
122-
"!pip install facenet-pytorch torchaudio==2.2.2 torchvision==0.17.2 torch==2.2.2 numpy==1.26.4 --quiet\n",
123-
"!pip install Pillow>=10.2.0 --quiet"
118+
"# # @title Uncomment to install dependencies\n",
119+
"# # @markdown Install `facenet` - A model used to do facial recognition.\n",
120+
"# # @markdown This is an old package and requires we downgrade many others.\n",
121+
"# # @markdown You may be asked to restart your session the first time you run this.\n",
122+
"# !pip install facenet-pytorch torchvision==0.17.2 torchaudio==2.2.2 torch==2.2.2 numpy==1.26.4 --quiet\n",
123+
"# !pip install Pillow==10.2.0 --quiet"
124124
]
125125
},
126126
{
@@ -534,21 +534,29 @@
534534
{
535535
"cell_type": "code",
536536
"execution_count": null,
537-
"metadata": {
538-
"cellView": "form",
539-
"execution": {}
540-
},
537+
"metadata": {},
541538
"outputs": [],
542539
"source": [
543540
"# @title Import Alexnet\n",
544-
"# @markdown This cell gives you the `alexnet` model as well as the `input_image` and `input_batch` variables used below\n",
545-
"import requests, urllib\n",
546-
"\n",
547-
"# Original link: https://s3.amazonaws.com/pytorch/models/alexnet-owt-4df8aa71.pth\n",
548-
"state_dict = torch.hub.load_state_dict_from_url(\"https://osf.io/9dzeu/download\")\n",
541+
"import requests, urllib, io, os\n",
542+
"\n",
543+
"# Download and save to disk first\n",
544+
"weights_path = \"alexnet-owt-4df8aa71.pth\"\n",
545+
"if not os.path.exists(weights_path):\n",
546+
" print(\"Downloading weights...\")\n",
547+
" response = requests.get(\"https://osf.io/9dzeu/download\", allow_redirects=True)\n",
548+
" response.raise_for_status()\n",
549+
" with open(weights_path, \"wb\") as f:\n",
550+
" f.write(response.content)\n",
551+
" print(f\"Saved {len(response.content) / 1e6:.1f} MB\")\n",
552+
"\n",
553+
"# Verify it's a valid torch file before loading\n",
554+
"print(f\"File size on disk: {os.path.getsize(weights_path) / 1e6:.1f} MB\")\n",
555+
"state_dict = torch.load(weights_path, map_location=\"cpu\", weights_only=False)\n",
549556
"\n",
550557
"alexnet = AlexNet()\n",
551558
"alexnet.load_state_dict(state_dict=state_dict)\n",
559+
"print(\"Model loaded successfully!\")\n",
552560
"\n",
553561
"url, filename = (\"https://raw.githubusercontent.com/NeuromatchAcademy/course-content-dl/main/tutorials/W2D2_Convnets/static/dog.jpg\", \"dog.jpg\")\n",
554562
"try: urllib.URLopener().retrieve(url, filename)\n",
@@ -563,12 +571,11 @@
563571
" std=[0.229, 0.224, 0.225]),\n",
564572
" ])\n",
565573
"input_tensor = preprocess(input_image)\n",
566-
"input_batch = input_tensor.unsqueeze(0) # Create a mini-batch as expected by the model\n",
574+
"input_batch = input_tensor.unsqueeze(0)\n",
567575
"\n",
568-
"# Move the input and model to GPU for speed if available\n",
569576
"if torch.cuda.is_available():\n",
570-
" input_batch = input_batch.cuda()\n",
571-
" alexnet.cuda()"
577+
" input_batch = input_batch.cuda()\n",
578+
" alexnet.cuda()"
572579
]
573580
},
574581
{
@@ -3017,7 +3024,7 @@
30173024
"---\n",
30183025
"# Summary\n",
30193026
"\n",
3020-
"In this tutorial, you have learned about the modern Convnets (CNNs), their architecture, and operating principles. Also, you are now familiar with the notion of *Transfer Learning*, and you have learned when to apply it. If you have time left, you will learn more about the speed vs. accuracy trade-off. In the next tutorial, we will see the modern convnets in a facial recognition task."
3027+
"So far, you have learned about the modern Convnets (CNNs), their architecture, and operating principles. If you have time left, you can continue to learn more about the speed vs. accuracy trade-off, as well as the modern convnets in a facial recognition task."
30213028
]
30223029
},
30233030
{
@@ -4477,7 +4484,7 @@
44774484
"name": "python",
44784485
"nbconvert_exporter": "python",
44794486
"pygments_lexer": "ipython3",
4480-
"version": "3.10.20"
4487+
"version": "3.9.25"
44814488
}
44824489
},
44834490
"nbformat": 4,

tutorials/W2D3_GenerativeModelsAndDeepLearningDiscussion1/W2D3_Tutorial1.ipynb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@
119119
},
120120
"outputs": [],
121121
"source": [
122-
"# @title Install and check dependencies\n",
123-
"!pip install pytorch-pretrained-biggan --quiet\n",
124-
"!pip install Pillow libsixel-python --quiet"
122+
"# @title Uncomment to install dependencies\n",
123+
"# !pip install pytorch-pretrained-biggan --quiet\n",
124+
"# !pip install libsixel-python --quiet"
125125
]
126126
},
127127
{
@@ -3106,19 +3106,19 @@
31063106
"\n",
31073107
"\n",
31083108
"trained_conv_VarAE = ConvVAE(K=K_VAE)\n",
3109-
"elbo_vals = train_vae(trained_conv_VarAE, train_set, n_samples=10000)\n",
3110-
"\n",
3111-
"print(f'Learned sigma_x is {torch.exp(trained_conv_VarAE.log_sig_x)}')\n",
3109+
"if DEVICE != 'cpu':\n",
3110+
" elbo_vals = train_vae(trained_conv_VarAE, train_set, n_samples=10000)\n",
3111+
" print(f'Learned sigma_x is {torch.exp(trained_conv_VarAE.log_sig_x)}')\n",
31123112
"\n",
31133113
"# Uncomment below if you'd like to see the the training\n",
31143114
"# curve of the evaluated ELBO loss function\n",
31153115
"# ELBO is the loss function used to train VAEs\n",
31163116
"# (see lecture!)\n",
3117-
"plt.figure()\n",
3118-
"plt.plot(elbo_vals)\n",
3119-
"plt.xlabel('Batch #')\n",
3120-
"plt.ylabel('ELBO')\n",
3121-
"plt.show()"
3117+
"# plt.figure()\n",
3118+
"# plt.plot(elbo_vals)\n",
3119+
"# plt.xlabel('Batch #')\n",
3120+
"# plt.ylabel('ELBO')\n",
3121+
"# plt.show()"
31223122
]
31233123
},
31243124
{

tutorials/W2D4_DiffusionGenerativeModels/W2D4_Tutorial1.ipynb

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,6 @@
102102
"feedback_prefix = \"W2D4_T1\""
103103
]
104104
},
105-
{
106-
"cell_type": "code",
107-
"execution_count": null,
108-
"metadata": {
109-
"cellView": "form",
110-
"execution": {}
111-
},
112-
"outputs": [],
113-
"source": [
114-
"# @title Install dependencies\n",
115-
"!pip install pillow --quiet\n",
116-
"!pip install seaborn --quiet"
117-
]
118-
},
119105
{
120106
"cell_type": "code",
121107
"execution_count": null,

tutorials/W2D4_DiffusionGenerativeModels/W2D4_Tutorial2.ipynb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,9 @@
111111
},
112112
"outputs": [],
113113
"source": [
114-
"# @title Install and check dependencies\n",
115-
"!pip install pillow --quiet\n",
116-
"!pip install diffusers transformers tokenizers --quiet\n",
117-
"!pip install accelerate --quiet"
114+
"# @title Uncomment to install dependencies\n",
115+
"# !pip install diffusers transformers tokenizers --quiet\n",
116+
"# !pip install accelerate --quiet"
118117
]
119118
},
120119
{
@@ -279,7 +278,7 @@
279278
},
280279
"source": [
281280
"---\n",
282-
"# Neural Network Architecture"
281+
"# Section 1: Neural Network Architecture"
283282
]
284283
},
285284
{

tutorials/W2D5_TimeSeriesAndNaturalLanguageProcessing/W2D5_Tutorial1.ipynb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@
113113
},
114114
"outputs": [],
115115
"source": [
116-
"# @title Install dependencies\n",
117-
"!pip install nltk --quiet\n",
118-
"!pip install fasttext --quiet\n",
119-
"!pip install -U datasets --quiet\n",
120-
"!pip install -U tokenizers --quiet"
116+
"# @title Uncomment to install dependencies\n",
117+
"# !pip install nltk --quiet\n",
118+
"# !pip install fasttext --quiet\n",
119+
"# !pip install -U datasets --quiet\n",
120+
"# !pip install -U tokenizers==0.22.2 --quiet"
121121
]
122122
},
123123
{
@@ -1910,7 +1910,8 @@
19101910
"name": "python3"
19111911
},
19121912
"kernelspec": {
1913-
"display_name": "Python 3",
1913+
"display_name": "nma-dl",
1914+
"language": "python",
19141915
"name": "python3"
19151916
},
19161917
"language_info": {
@@ -1923,7 +1924,7 @@
19231924
"name": "python",
19241925
"nbconvert_exporter": "python",
19251926
"pygments_lexer": "ipython3",
1926-
"version": "3.10.20"
1927+
"version": "3.9.25"
19271928
}
19281929
},
19291930
"nbformat": 4,

0 commit comments

Comments
 (0)