{"version":2,"relationshipURLBase":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html","relationshipResolution":"Resolve relative relationship URLs against relationshipURLBase; complete records and absolute URLs are in blocks.","title":"3. 实例掩码 · 实现代码","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html","markdown":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.md","pages":[{"id":"reading-opening","title":"3. 实例掩码 · 实现代码","unit":"3. 实例掩码 · 实现代码","unitId":"notebook-blocks/231837089e9a4369aa7529f300a99919","chapter":"course","number":1}],"aliases":[{"oldId":"b-44c1effc005d65b499b7c402","targetId":"b-44c1effc005d65b499b7c402","page":"reading-opening","operation":"move","beforeSHA256":"ddf3568d0338b754fc16cebc1db88a677c1a74738b534f3ccc508b72e6f23a78","afterSHA256":"ddf3568d0338b754fc16cebc1db88a677c1a74738b534f3ccc508b72e6f23a78","reason":"Same source body in authored semantic page"},{"oldId":"b-82327676f7cc22803a9fd933","targetId":"b-82327676f7cc22803a9fd933","page":"reading-opening","operation":"move","beforeSHA256":"76ed8d35d49e15307904a9a40e0f5ebb7e3b010d7bd4584aa8439911fa3756b7","afterSHA256":"76ed8d35d49e15307904a9a40e0f5ebb7e3b010d7bd4584aa8439911fa3756b7","reason":"Same source body in authored semantic page"},{"oldId":"b-ed25658939f6a3a0bbaed087","targetId":"b-ed25658939f6a3a0bbaed087","page":"reading-opening","operation":"move","beforeSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","afterSHA256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","reason":"Same source body in authored semantic page"},{"oldId":"b-b12a59d7fa0bb40653d53c56","targetId":"b-b12a59d7fa0bb40653d53c56","page":"reading-opening","operation":"move","beforeSHA256":"93fe7c165c595944c7af5b3abd9e50016526d59fcb6d412fbfb865bd208f77c4","afterSHA256":"93fe7c165c595944c7af5b3abd9e50016526d59fcb6d412fbfb865bd208f77c4","reason":"Same source body in authored semantic page"},{"oldId":"b-7cdab304c338e58762e0a961","targetId":"b-7cdab304c338e58762e0a961","page":"reading-opening","operation":"move","beforeSHA256":"cb6c660ec4d907ba6d21c960a631ec2fa5dd33a029ea2378765c42ac6c5c7d33","afterSHA256":"cb6c660ec4d907ba6d21c960a631ec2fa5dd33a029ea2378765c42ac6c5c7d33","reason":"Same source body in authored semantic page"}],"blocks":[{"id":"b-44c1effc005d65b499b7c402","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html#b-44c1effc005d65b499b7c402","content":"[LAB 03 · 空间信息：表示、采样与掩码](/course/notebooks/49a2c030eafa4e1db6fc4f1a08c3810a.html)","sha256":"ddf3568d0338b754fc16cebc1db88a677c1a74738b534f3ccc508b72e6f23a78","chapter":{"id":"course","title":"3. 实例掩码 · 实现代码"},"unit":{"id":"notebook-blocks/231837089e9a4369aa7529f300a99919","title":"3. 实例掩码 · 实现代码"},"page":{"id":"reading-opening","title":"3. 实例掩码 · 实现代码","number":1},"sectionTitle":"3. 实例掩码 · 实现代码","currentQuestion":"3. 实例掩码 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":null,"nextBlock":"b-82327676f7cc22803a9fd933","prerequisites":[],"relatedBlocks":[]},{"id":"b-82327676f7cc22803a9fd933","type":"h1","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html#b-82327676f7cc22803a9fd933","content":"# 3. 实例掩码 · 实现代码","sha256":"76ed8d35d49e15307904a9a40e0f5ebb7e3b010d7bd4584aa8439911fa3756b7","chapter":{"id":"course","title":"3. 实例掩码 · 实现代码"},"unit":{"id":"notebook-blocks/231837089e9a4369aa7529f300a99919","title":"3. 实例掩码 · 实现代码"},"page":{"id":"reading-opening","title":"3. 实例掩码 · 实现代码","number":1},"sectionTitle":"3. 实例掩码 · 实现代码","currentQuestion":"3. 实例掩码 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-44c1effc005d65b499b7c402","nextBlock":"b-ed25658939f6a3a0bbaed087","prerequisites":[{"id":"b-44c1effc005d65b499b7c402","url":"#b-44c1effc005d65b499b7c402","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-ed25658939f6a3a0bbaed087","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html#b-ed25658939f6a3a0bbaed087","content":"按问题继续","sha256":"e91f24e4e4ca40e2099a0d81d30db6568f4bf2074b499eeee6e3959617bd97ac","chapter":{"id":"course","title":"3. 实例掩码 · 实现代码"},"unit":{"id":"notebook-blocks/231837089e9a4369aa7529f300a99919","title":"3. 实例掩码 · 实现代码"},"page":{"id":"reading-opening","title":"3. 实例掩码 · 实现代码","number":1},"sectionTitle":"3. 实例掩码 · 实现代码","currentQuestion":"3. 实例掩码 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-82327676f7cc22803a9fd933","nextBlock":"b-b12a59d7fa0bb40653d53c56","prerequisites":[{"id":"b-82327676f7cc22803a9fd933","url":"#b-82327676f7cc22803a9fd933","role":"section-title"},{"id":"b-44c1effc005d65b499b7c402","url":"#b-44c1effc005d65b499b7c402","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-b12a59d7fa0bb40653d53c56","type":"p","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html#b-b12a59d7fa0bb40653d53c56","content":"同源场景标签、插值、信息碰撞的轻量解析代码","sha256":"93fe7c165c595944c7af5b3abd9e50016526d59fcb6d412fbfb865bd208f77c4","chapter":{"id":"course","title":"3. 实例掩码 · 实现代码"},"unit":{"id":"notebook-blocks/231837089e9a4369aa7529f300a99919","title":"3. 实例掩码 · 实现代码"},"page":{"id":"reading-opening","title":"3. 实例掩码 · 实现代码","number":1},"sectionTitle":"3. 实例掩码 · 实现代码","currentQuestion":"3. 实例掩码 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-ed25658939f6a3a0bbaed087","nextBlock":"b-7cdab304c338e58762e0a961","prerequisites":[{"id":"b-82327676f7cc22803a9fd933","url":"#b-82327676f7cc22803a9fd933","role":"section-title"},{"id":"b-44c1effc005d65b499b7c402","url":"#b-44c1effc005d65b499b7c402","role":"problem-context"}],"relatedBlocks":[]},{"id":"b-7cdab304c338e58762e0a961","type":"pre","scope":"document","url":"https://codingai-lec03.pages.dev/course/notebook-blocks/231837089e9a4369aa7529f300a99919.html#b-7cdab304c338e58762e0a961","content":"```\n# 本册独立素材准备：内嵌预览与精确原图坐标，不下载外站，也不依赖其他 notebook 的变量。\nfrom pathlib import Path\nimport base64, json\nfrom IPython.display import SVG, display\nscene_uri = 'https://codingai-lec03.pages.dev/course/knowledge-assets/46ffa1170be676ea38dfc1ee.jpg'\nannotation = {'version': 'L03-r2-20260922', 'image': 'tabletop-occlusion.png', 'size': [1536, 1024], 'label': '手工教学标注：可见轮廓，非模型输出或数据集真值', 'objects': [{'id': 'cup-red', 'category': 'cup', 'polygon': [[280, 270], [295, 251], [362, 241], [448, 242], [527, 253], [565, 270], [562, 361], [554, 454], [542, 532], [526, 565], [491, 579], [432, 586], [369, 582], [329, 568], [307, 541], [297, 516], [258, 497], [224, 471], [194, 433], [179, 392], [178, 356], [190, 326], [210, 308], [242, 303], [278, 314]], 'holes': [[[280, 351], [251, 328], [227, 328], [209, 343], [200, 368], [204, 400], [219, 432], [244, 459], [276, 480], [290, 481]]], 'box': [177, 238, 390, 351]}, {'id': 'cup-blue', 'category': 'cup', 'polygon': [[642, 266], [663, 248], [732, 238], [814, 238], [888, 249], [925, 267], [925, 306], [954, 296], [985, 296], [1009, 310], [1022, 334], [1025, 366], [1018, 396], [1010, 418], [934, 435], [850, 450], [746, 466], [659, 482], [650, 414], [644, 341]], 'holes': [[[925, 348], [944, 323], [965, 318], [986, 326], [1000, 347], [1002, 373], [993, 404], [984, 424], [919, 438]]], 'box': [641, 235, 386, 249]}, {'id': 'book', 'category': 'book', 'polygon': [[602, 500], [626, 490], [1051, 412], [1450, 548], [1451, 560], [1438, 576], [1438, 633], [1454, 648], [918, 770], [602, 586], [597, 560], [598, 516]], 'holes': [], 'box': [596, 411, 860, 362]}]}\nasset_dir = Path.cwd() / 'lecture03-assets-r2'\nasset_dir.mkdir(exist_ok=True)\npreview_file = asset_dir / 'tabletop-occlusion-preview.jpg'\nif not preview_file.exists():\n    preview_file.write_bytes(base64.b64decode(scene_uri.split(',',1)[1]))\n(asset_dir / 'scene-annotations.json').write_text(json.dumps(annotation,ensure_ascii=False,indent=2))\nprint('可用材料:', preview_file.name, 'scene-annotations.json')\nprint('标注坐标系:', annotation['size'], '；图片预览768×512，展示时同比例映射。')\n# 修改这一项为 cup-red、cup-blue 或 book，预测红框和局部窗口怎样改变。\nselected_id = 'cup-blue'\nobj = next(o for o in annotation['objects'] if o['id']==selected_id)\nx,y,w,h = obj['box']\nprint('所选对象:',selected_id,'类别:',obj['category'],'框(x,y,w,h):',[x,y,w,h])\nsvg = f'<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"768\" height=\"512\" viewBox=\"0 0 1536 1024\"><image href=\"{scene_uri}\" width=\"1536\" height=\"1024\"/><rect x=\"{x}\" y=\"{y}\" width=\"{w}\" height=\"{h}\" fill=\"none\" stroke=\"#431170\" stroke-width=\"10\"/></svg>'\ndisplay(SVG(svg))\n# 将所选框显示在归一化的局部窗口；不把此教学裁剪称为 RoIAlign。\nlocal_svg = f'<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"320\" height=\"240\" viewBox=\"{x} {y} {w} {h}\" preserveAspectRatio=\"none\"><image href=\"{scene_uri}\" width=\"1536\" height=\"1024\"/></svg>'\ndisplay(SVG(local_svg))\n\n```","sha256":"cb6c660ec4d907ba6d21c960a631ec2fa5dd33a029ea2378765c42ac6c5c7d33","chapter":{"id":"course","title":"3. 实例掩码 · 实现代码"},"unit":{"id":"notebook-blocks/231837089e9a4369aa7529f300a99919","title":"3. 实例掩码 · 实现代码"},"page":{"id":"reading-opening","title":"3. 实例掩码 · 实现代码","number":1},"sectionTitle":"3. 实例掩码 · 实现代码","currentQuestion":"3. 实例掩码 · 实现代码","sourceSlides":[],"knowledgeBlock":null,"formulas":[],"previousBlock":"b-b12a59d7fa0bb40653d53c56","nextBlock":null,"prerequisites":[{"id":"b-82327676f7cc22803a9fd933","url":"#b-82327676f7cc22803a9fd933","role":"section-title"},{"id":"b-44c1effc005d65b499b7c402","url":"#b-44c1effc005d65b499b7c402","role":"problem-context"}],"relatedBlocks":[]}]}
