mirror of
https://github.com/mrdbourke/pytorch-deep-learning.git
synced 2026-11-27 06:07:09 +00:00
update 05
This commit is contained in:
1 parent
b49836126d
commit
3c28f2bce8
2 files changed
+16
-12
No files matched your search
@@ -2,7 +2,7 @@
|
||||
|
||||
This section answers the question, "how do I turn my notebook code into Python scripts?"
|
||||
|
||||
To do so, we're going to turn the code cells in notebook 04 into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular).
|
||||
To do so, we're going to turn the most useful code cells in [notebook 04. PyTorch Custom Datasets](https://www.learnpytorch.io/04_pytorch_custom_datasets/) into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular).
|
||||
|
||||
## What is going modular?
|
||||
|
||||
@@ -43,7 +43,9 @@ But this list sums up a few of the main topics.
|
||||
| **Notebooks** | Easy to experiment/get started | Versioning can be hard |
|
||||
| | Easy to share (e.g. a link to a Google Colab notebook) | Hard to use only specific parts |
|
||||
| | Very visual | Text and graphics can get in the way of code |
|
||||
|
||||
| | **Pros** | **Cons** |
|
||||
| ----- | ----- | ----- |
|
||||
| **Python scripts** | Can package code together (saves rewriting similar code across different notebooks) | Experimenting isn't as visual (usually have to run the whole script rather than one cell) |
|
||||
| | Can use git for versioning | |
|
||||
| | Many open source projects use scripts | |
|
||||
@@ -55,7 +57,7 @@ I usually start machine learning projects in Jupyter/Google Colab notebooks for
|
||||
|
||||
Then when I've got something working, I move the most useful pieces of code to Python scripts.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-my-workflow-for-experimenting.png" alt="one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working." width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-my-workflow-for-experimenting.png" alt="one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working." width=800/>
|
||||
|
||||
*There are many possible workflows for writing machine learning code. Some prefer to start with scripts, others (like me) prefer to start with notebooks and go to scripts later on.*
|
||||
|
||||
@@ -69,7 +71,7 @@ For example, you might be instructred to run code like the following in a termin
|
||||
python train.py --model MODEL_NAME --batch_size BATCH_SIZE --lr LEARNING_RATE --num_epochs NUM_EPOCHS
|
||||
```
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-python-train-command-line-annotated.png" alt="command line call for training a PyTorch model with different hyperparameters" width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-python-train-command-line-annotated.png" alt="command line call for training a PyTorch model with different hyperparameters" width=800/>
|
||||
|
||||
*Running a PyTorch `train.py` script on the command line with various hyperparameter settings.*
|
||||
|
||||
@@ -89,7 +91,7 @@ You could setup any number of these argument flags in your `train.py` script to
|
||||
|
||||
The PyTorch blog post for training state-of-the-art computer vision models uses this style.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-training-sota-recipe.png" alt="PyTorch training script recipe for training state of the art computer vision models" width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-training-sota-recipe.png" alt="PyTorch training script recipe for training state of the art computer vision models" width=800/>
|
||||
|
||||
*PyTorch command line training script recipe for training state-of-the-art computer vision models with 8 GPUs. Source: [PyTorch blog](https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/#the-training-recipe).*
|
||||
|
||||
@@ -112,7 +114,7 @@ Because sometimes the best way to learn something is to see how it *differs* fro
|
||||
|
||||
If you run each notebook side-by-side you'll see how they differ and that's where the key learnings are.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-notebook-cell-mode-vs-script-mode.png" alt="running cell mode notebook vs a script mode notebook" width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-notebook-cell-mode-vs-script-mode.png" alt="running cell mode notebook vs a script mode notebook" width=800/>
|
||||
|
||||
*Running the two notebooks for section 05 side-by-side. You'll notice that the **script mode notebook has extra code cells** to turn code from the cell mode notebook into Python scripts.*
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
This section answers the question, "how do I turn my notebook code into Python scripts?"
|
||||
|
||||
To do so, we're going to turn the code cells in notebook 04 into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular).
|
||||
To do so, we're going to turn the most useful code cells in [notebook 04. PyTorch Custom Datasets](https://www.learnpytorch.io/04_pytorch_custom_datasets/) into a series of Python scripts saved to a directory called [`going_modular`](https://github.com/mrdbourke/pytorch-deep-learning/tree/main/going_modular).
|
||||
|
||||
## What is going modular?
|
||||
|
||||
@@ -43,7 +43,9 @@ But this list sums up a few of the main topics.
|
||||
| **Notebooks** | Easy to experiment/get started | Versioning can be hard |
|
||||
| | Easy to share (e.g. a link to a Google Colab notebook) | Hard to use only specific parts |
|
||||
| | Very visual | Text and graphics can get in the way of code |
|
||||
|
||||
| | **Pros** | **Cons** |
|
||||
| ----- | ----- | ----- |
|
||||
| **Python scripts** | Can package code together (saves rewriting similar code across different notebooks) | Experimenting isn't as visual (usually have to run the whole script rather than one cell) |
|
||||
| | Can use git for versioning | |
|
||||
| | Many open source projects use scripts | |
|
||||
@@ -55,7 +57,7 @@ I usually start machine learning projects in Jupyter/Google Colab notebooks for
|
||||
|
||||
Then when I've got something working, I move the most useful pieces of code to Python scripts.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-my-workflow-for-experimenting.png" alt="one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working." width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-my-workflow-for-experimenting.png" alt="one possible workflow for writing machine learning code, start with jupyter or google colab notebooks and then move to Python scripts when you've got something working." width=800/>
|
||||
|
||||
*There are many possible workflows for writing machine learning code. Some prefer to start with scripts, others (like me) prefer to start with notebooks and go to scripts later on.*
|
||||
|
||||
@@ -69,7 +71,7 @@ For example, you might be instructred to run code like the following in a termin
|
||||
python train.py --model MODEL_NAME --batch_size BATCH_SIZE --lr LEARNING_RATE --num_epochs NUM_EPOCHS
|
||||
```
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-python-train-command-line-annotated.png" alt="command line call for training a PyTorch model with different hyperparameters" width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-python-train-command-line-annotated.png" alt="command line call for training a PyTorch model with different hyperparameters" width=800/>
|
||||
|
||||
*Running a PyTorch `train.py` script on the command line with various hyperparameter settings.*
|
||||
|
||||
@@ -89,7 +91,7 @@ You could setup any number of these argument flags in your `train.py` script to
|
||||
|
||||
The PyTorch blog post for training state-of-the-art computer vision models uses this style.
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-training-sota-recipe.png" alt="PyTorch training script recipe for training state of the art computer vision models" width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-training-sota-recipe.png" alt="PyTorch training script recipe for training state of the art computer vision models" width=800/>
|
||||
|
||||
*PyTorch command line training script recipe for training state-of-the-art computer vision models with 8 GPUs. Source: [PyTorch blog](https://pytorch.org/blog/how-to-train-state-of-the-art-models-using-torchvision-latest-primitives/#the-training-recipe).*
|
||||
|
||||
@@ -104,15 +106,15 @@ There are two notebooks for this section:
|
||||
1. [**05. Going Modular: Part 1 (cell mode)**](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/going_modular/05_pytorch_going_modular_cell_mode.ipynb) - this notebook is run as a traditional Jupyter Notebook/Google Colab notebook and is a condensed version of [notebook 04](https://www.learnpytorch.io/04_pytorch_custom_datasets/).
|
||||
2. [**05. Going Modular: Part 2 (script mode)**](https://github.com/mrdbourke/pytorch-deep-learning/blob/main/going_modular/05_pytorch_going_modular_script_mode.ipynb) - this notebook is the same as number 1 but with added functionality to turn each of the major sections into Python scripts, such as, `data_setup.py` and `train.py`.
|
||||
|
||||
The text in this document focuses on the code cells 05. Going Modular: Part 2 (script mode), the ones with `%%writefile ...` at the top.
|
||||
|
||||
### Why two parts?
|
||||
|
||||
Because sometimes the best way to learn something is to see how it *differs* from something else.
|
||||
|
||||
If you run each notebook side-by-side you'll see how they differ and that's where the key learnings are.
|
||||
|
||||
The text in this document focuses on 05. Going Modular: Part 2 (script mode).
|
||||
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-notebook-cell-mode-vs-script-mode.png" alt="running cell mode notebook vs a script mode notebook" width=600/>
|
||||
<img src="https://raw.githubusercontent.com/mrdbourke/pytorch-deep-learning/main/images/05-notebook-cell-mode-vs-script-mode.png" alt="running cell mode notebook vs a script mode notebook" width=800/>
|
||||
|
||||
*Running the two notebooks for section 05 side-by-side. You'll notice that the **script mode notebook has extra code cells** to turn code from the cell mode notebook into Python scripts.*
|
||||
|
||||
|
||||
Reference in new issue
Block a user