Skip to content

Commit f47d321

Browse files
Added Manual dataset download (#286)
* Added Manual dataset download * Modified formatting * Added Specific Commands in different Cells * Added a different list with all the notebook commands * Correct typo * Refactored Code * Refactored Code * Fixed failing null error * Fix Typo for function * Removed redundant if condition * Fix lint * Renamed variable nb_commands to nb_cells
1 parent 6efaa4c commit f47d321

File tree

2 files changed

+58
-24
lines changed

2 files changed

+58
-24
lines changed

functions/colab.js

+42-24
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,47 @@ exports.handler = async function (event, _) {
4242
.map((v) => v[0].toUpperCase() + v.slice(1))
4343
.join(' ')
4444
// notebook cell structure
45+
46+
function create_nb_cell(source_array, cell_type) {
47+
return {
48+
cell_type: cell_type,
49+
metadata: {},
50+
execution_count: null,
51+
outputs: [],
52+
source: source_array
53+
}
54+
}
55+
56+
let specific_commands = []
57+
58+
if (title === 'Template Vision Segmentation') {
59+
specific_commands.push(
60+
'!python -c "from data import download_datasets; download_datasets(\'./\')"'
61+
)
62+
}
63+
64+
const md_cell = [
65+
`# ${title} by PyTorch-Ignite Code-Generator\n\n`,
66+
'Please, run the cell below to execute your code.'
67+
]
68+
69+
const common_nb_commands = [
70+
`!wget ${zipRes}\n`,
71+
`!unzip ${template}.zip\n`,
72+
'!pip install -r requirements.txt'
73+
]
74+
75+
const execution_nb_commands = ['!python main.py config.yaml']
76+
77+
let nb_cells = [
78+
create_nb_cell(md_cell, 'markdown'),
79+
create_nb_cell(common_nb_commands, 'code')
80+
]
81+
if (specific_commands.length > 0) {
82+
nb_cells.push(create_nb_cell(specific_commands, 'code'))
83+
}
84+
nb_cells.push(create_nb_cell(execution_nb_commands, 'code'))
85+
4586
const nb = {
4687
nbformat: 4,
4788
nbformat_minor: 0,
@@ -52,30 +93,7 @@ exports.handler = async function (event, _) {
5293
},
5394
accelerator: 'GPU'
5495
},
55-
cells: [
56-
{
57-
cell_type: 'markdown',
58-
metadata: {},
59-
execution_count: null,
60-
outputs: [],
61-
source: [
62-
`# ${title} by PyTorch-Ignite Code-Generator\n\n`,
63-
'Please, run the cell below to execute your code.'
64-
]
65-
},
66-
{
67-
cell_type: 'code',
68-
metadata: {},
69-
execution_count: null,
70-
outputs: [],
71-
source: [
72-
`!wget ${zipRes}\n`,
73-
`!unzip ${template}.zip\n`,
74-
'!pip install -r requirements.txt\n',
75-
'!python main.py config.yaml\n'
76-
]
77-
}
78-
]
96+
cells: nb_cells
7997
}
8098
// Create the notebook on GitHub
8199
await pushToGitHub(

src/templates/template-vision-segmentation/README.md

+16
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,20 @@
44

55
This is the segmentation template by Code-Generator using `deeplabv3_resnet101` and `cifar10` dataset from TorchVision and training is powered by PyTorch and PyTorch-Ignite.
66

7+
**Note:**
8+
The dataset used in this template is quite substantial, with a size of several GBs and automatically downloading it can be seen as an unexpected behaviour. To prevent unexpected behavior or excessive bandwidth usage, the automatic downloading of the dataset has been disabled by default.
9+
10+
To download the dataset:
11+
12+
```python
13+
python -c "from data import download_datasets; download_datasets('/path/to/data')"
14+
```
15+
16+
or
17+
18+
```py
19+
from data import download_datasets
20+
download_datasets('/path/to/data')
21+
```
22+
723
#::= from_template_common ::#

0 commit comments

Comments
 (0)