{"version":2,"relationshipURLBase":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html","relationshipResolution":"Resolve relative relationship URLs against relationshipURLBase; complete records and absolute URLs are in blocks.","title":"准备：本实验的固定材料 · 实现代码","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html","markdown":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.md","pages":[{"id":"reading-opening","title":"准备：本实验的固定材料 · 实现代码","unit":"准备：本实验的固定材料 · 实现代码","unitId":"notebook-blocks/186427ff91eb43f1841c3fb1342dc90a","chapter":"course","number":1}],"aliases":[{"oldId":"b-d58079ec9ab91304d3f6c624","targetId":"b-d58079ec9ab91304d3f6c624","page":"reading-opening","operation":"move","beforeSHA256":"f107bd31e942a5cf605f3183c89731efbb5349a4bf8c063087e5d29bebde50b5","afterSHA256":"f107bd31e942a5cf605f3183c89731efbb5349a4bf8c063087e5d29bebde50b5","reason":"Same source body in authored semantic page"},{"oldId":"b-9093b9186881cf3f14edff91","targetId":"b-9093b9186881cf3f14edff91","page":"reading-opening","operation":"move","beforeSHA256":"5921c0537ec13d0d8bedb07c2d73686e3eec06ccda769319a707c32881e44682","afterSHA256":"5921c0537ec13d0d8bedb07c2d73686e3eec06ccda769319a707c32881e44682","reason":"Same source body in authored semantic page"},{"oldId":"b-fc21bc79719950c129bda095","targetId":"b-fc21bc79719950c129bda095","page":"reading-opening","operation":"move","beforeSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","afterSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","reason":"Same source body in authored semantic page"},{"oldId":"b-0505e27b25ec982a4176139d","targetId":"b-0505e27b25ec982a4176139d","page":"reading-opening","operation":"move","beforeSHA256":"5f1e2e7a35a6afaca427b0b03cfec448b4aac4324b16108f14671986a2d98b38","afterSHA256":"5f1e2e7a35a6afaca427b0b03cfec448b4aac4324b16108f14671986a2d98b38","reason":"Same source body in authored semantic page"},{"oldId":"b-c4eb92822b746229dbcd8d82","targetId":"b-c4eb92822b746229dbcd8d82","page":"reading-opening","operation":"move","beforeSHA256":"9e914efedd4eae705e14123b928f44c3ddc6b8152586aa5cba003c756c27e34c","afterSHA256":"9e914efedd4eae705e14123b928f44c3ddc6b8152586aa5cba003c756c27e34c","reason":"Same source body in authored semantic page"}],"blocks":[{"id":"b-d58079ec9ab91304d3f6c624","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html#b-d58079ec9ab91304d3f6c624","content":"[LAB 02 · 参数迁移：冻结、局部与全量微调](/course/notebooks/4bd450d54870432db91c80a4df563b8e.html)","sha256":"f107bd31e942a5cf605f3183c89731efbb5349a4bf8c063087e5d29bebde50b5","chapter":{"id":"course","title":"准备：本实验的固定材料 · 实现代码"},"unit":{"id":"notebook-blocks/186427ff91eb43f1841c3fb1342dc90a","title":"准备：本实验的固定材料 · 实现代码"},"page":{"id":"reading-opening","title":"准备：本实验的固定材料 · 实现代码","number":1},"sectionTitle":"准备：本实验的固定材料 · 实现代码","currentQuestion":"准备：本实验的固定材料 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":null,"nextBlock":"b-9093b9186881cf3f14edff91","prerequisites":[],"relatedBlocks":[]},{"id":"b-9093b9186881cf3f14edff91","type":"h1","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html#b-9093b9186881cf3f14edff91","content":"# 准备：本实验的固定材料 · 实现代码","sha256":"5921c0537ec13d0d8bedb07c2d73686e3eec06ccda769319a707c32881e44682","chapter":{"id":"course","title":"准备：本实验的固定材料 · 实现代码"},"unit":{"id":"notebook-blocks/186427ff91eb43f1841c3fb1342dc90a","title":"准备：本实验的固定材料 · 实现代码"},"page":{"id":"reading-opening","title":"准备：本实验的固定材料 · 实现代码","number":1},"sectionTitle":"准备：本实验的固定材料 · 实现代码","currentQuestion":"准备：本实验的固定材料 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-d58079ec9ab91304d3f6c624","nextBlock":"b-fc21bc79719950c129bda095","prerequisites":[{"id":"b-d58079ec9ab91304d3f6c624","url":"#b-d58079ec9ab91304d3f6c624","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-fc21bc79719950c129bda095","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html#b-fc21bc79719950c129bda095","content":"按问题继续","sha256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","chapter":{"id":"course","title":"准备：本实验的固定材料 · 实现代码"},"unit":{"id":"notebook-blocks/186427ff91eb43f1841c3fb1342dc90a","title":"准备：本实验的固定材料 · 实现代码"},"page":{"id":"reading-opening","title":"准备：本实验的固定材料 · 实现代码","number":1},"sectionTitle":"准备：本实验的固定材料 · 实现代码","currentQuestion":"准备：本实验的固定材料 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-9093b9186881cf3f14edff91","nextBlock":"b-0505e27b25ec982a4176139d","prerequisites":[{"id":"b-9093b9186881cf3f14edff91","url":"#b-9093b9186881cf3f14edff91","role":"section-title"},{"id":"b-d58079ec9ab91304d3f6c624","url":"#b-d58079ec9ab91304d3f6c624","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-0505e27b25ec982a4176139d","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html#b-0505e27b25ec982a4176139d","content":"同源参数的冻结/局部/全量/scratch与BN模式辨析","sha256":"5f1e2e7a35a6afaca427b0b03cfec448b4aac4324b16108f14671986a2d98b38","chapter":{"id":"course","title":"准备：本实验的固定材料 · 实现代码"},"unit":{"id":"notebook-blocks/186427ff91eb43f1841c3fb1342dc90a","title":"准备：本实验的固定材料 · 实现代码"},"page":{"id":"reading-opening","title":"准备：本实验的固定材料 · 实现代码","number":1},"sectionTitle":"准备：本实验的固定材料 · 实现代码","currentQuestion":"准备：本实验的固定材料 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-fc21bc79719950c129bda095","nextBlock":"b-c4eb92822b746229dbcd8d82","prerequisites":[{"id":"b-9093b9186881cf3f14edff91","url":"#b-9093b9186881cf3f14edff91","role":"section-title"},{"id":"b-d58079ec9ab91304d3f6c624","url":"#b-d58079ec9ab91304d3f6c624","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-c4eb92822b746229dbcd8d82","type":"pre","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/186427ff91eb43f1841c3fb1342dc90a.html#b-c4eb92822b746229dbcd8d82","content":"```\n# 当前项目中的独立材料：已存在则复用，缺失才从本讲原站准备。\nfrom pathlib import Path\nimport io, zipfile, urllib.request\n_base = Path.cwd()\n_folder = 'lab09-transfer'\n_sentinel = 'data/train-images-idx3-ubyte.gz'\n_choices = [_base/_folder, _base/'lecture03-labs'/_folder, _base]\n_ready = next((p for p in _choices if (p/_sentinel).is_file()), None)\nif _ready is None:\n    _url = 'https://codingai-lec03.pages.dev/course/materials/' + _folder + '.zip'\n    _payload = urllib.request.urlopen(_url, timeout=60).read()\n    with zipfile.ZipFile(io.BytesIO(_payload)) as _archive:\n        _names = [i.filename for i in _archive.infolist() if not i.is_dir()]\n        _prefix = _folder + '/'\n        _prefixed = all(n.startswith(_prefix) for n in _names)\n        _destination = _base if _prefixed else _base/_folder\n        for _item in _archive.infolist():\n            _target = (_destination/_item.filename).resolve()\n            if not _target.is_relative_to(_destination.resolve()):\n                raise ValueError('材料包中有越界路径，停止解压。')\n            if _item.is_dir():\n                _target.mkdir(parents=True, exist_ok=True)\n            elif not _target.exists():\n                _target.parent.mkdir(parents=True, exist_ok=True)\n                _target.write_bytes(_archive.read(_item))\n    _ready = next((p for p in _choices if (p/_sentinel).is_file()), None)\nassert _ready is not None, '请将本讲完整材料包解压到当前项目的 ' + _folder + '/；保留文件结构。'\nLAB_ROOT = _ready\nprint('材料目录已就绪：', LAB_ROOT)\n\nimport copy, gzip, hashlib, io, json, os, time\nfrom pathlib import Path\nfrom collections import OrderedDict\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nimport torch\nfrom torch import nn\nfrom torch.nn import functional as F\ntorch.set_num_threads(2)\ntorch.manual_seed(20260917)\n\nROOT=LAB_ROOT\nif not (ROOT/'data').is_dir() and (ROOT/'lab09-transfer/data').is_dir():ROOT=ROOT/'lab09-transfer'\nassert (ROOT/'data').is_dir(), '请解压独立 lab09-transfer 包并保留目录结构。'\nOUT=ROOT/'runs/current';OUT.mkdir(parents=True,exist_ok=True)\n\n```","sha256":"9e914efedd4eae705e14123b928f44c3ddc6b8152586aa5cba003c756c27e34c","chapter":{"id":"course","title":"准备：本实验的固定材料 · 实现代码"},"unit":{"id":"notebook-blocks/186427ff91eb43f1841c3fb1342dc90a","title":"准备：本实验的固定材料 · 实现代码"},"page":{"id":"reading-opening","title":"准备：本实验的固定材料 · 实现代码","number":1},"sectionTitle":"准备：本实验的固定材料 · 实现代码","currentQuestion":"准备：本实验的固定材料 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-0505e27b25ec982a4176139d","nextBlock":null,"prerequisites":[{"id":"b-9093b9186881cf3f14edff91","url":"#b-9093b9186881cf3f14edff91","role":"section-title"},{"id":"b-d58079ec9ab91304d3f6c624","url":"#b-d58079ec9ab91304d3f6c624","role":"problem-context"}],"relatedBlocks":[]}]}
