{
  "source_file": "0930",
  "source_platform": "Dev.to",
  "author": "Wesam Khallaf",
  "title_listed": "Your CNN's Advantage Is One Assumption — and I Measured What Happens When It Breaks",
  "keywords": "",
  "domain": "图像处理",
  "content_type": "技术教程",
  "is_paid_flag": "否",
  "url": "https://dev.to/pytorchfromgroundup/your-cnns-advantage-is-one-assumption-and-i-measured-what-happens-when-it-breaks-490d",
  "publish_date": "2026-08-08",
  "corpus_stage": "",
  "notes": "",
  "id": "5295aeb5bbb9",
  "collected_at": "2026-10-02T13:53:59",
  "title": "Your CNN's Advantage Is One Assumption — and I Measured What Happens When It Breaks - DEV Community",
  "body_markdown": "A small convolutional network beats a plain flatten-and-feed-it-forward network by\n7.0 points\non CIFAR-10. That's convolutions, pooling, normalisation and skip connections doing honest work.\nThen I shuffled the rows of every image, destroying no information at all, and that 7.0-point margin fell to\n0.3\n.\nSame architecture. Same data, in a strict sense I'll defend in a moment. Almost the entire advantage, gone.\nThe experiment\nTake one fixed permutation of the 32 row indices. Apply it to every image in the training set and every image in the test set — the\nsame\npermutation, every time.\nimport\ntorch\ng\n=\ntorch\n.\nGenerator\n().\nmanual_seed\n(\n1234\n)\nrow_perm\n=\ntorch\n.\nrandperm\n(\n32\n,\ngenerator\n=\ng\n)\ndef\nshuffle_rows\n(\nx\n):\n# x: (C, H, W)\nreturn\nx\n[:,\nrow_perm\n,\n:]\nprint\n(\nrow_perm\n[:\n8\n].\ntolist\n())\n# [15, 9, 8, 1, 4, 12, 30, 7]\nEnter fullscreen mode\nExit fullscreen mode\nThat's the whole intervention. Then train two models twice each — once on natural images, once on shuffled ones:\nModel\nParams\nNatural rows\nShuffled rows\nFlatten → 512 → 10 (MLP)\n1,578,506\n51.4%\n51.7%\nSmall CNN\n94,538\n58.4%\n52.0%\nCNN's margin\n+7.0 pts\n+0.3 pts\nThe baseline is a real fully-connected network, not a single linear layer —\nFlatten → Linear(3072, 512) → ReLU → Linear(512, 10)\n. It has the capacity to learn anything the CNN can; what it lacks is any reason to look at pixels near each other.\nTwo things in that table are worth sitting with. The CNN wins the natural case with\nsixteen times fewer parameters\n— that's the prior paying for itself. And in the shuffled case it doesn't just lose its lead; it drops 6.4 points in absolute terms, down to roughly where the linear model already was.\n\"You destroyed the data\" — no, and this is the important part\nThis is the objection everyone raises, so let's take it seriously, because the experiment is worthless if the objection holds.\nA fixed permutation is a\nbijection\n. Nothing is added, nothing is removed, nothing is averaged or blurred:\nimg\n=\ntorch\n.\narange\n(\n3\n*\n32\n*\n32\n,\ndtype\n=\ntorch\n.\nfloat32\n).\nreshape\n(\n3\n,\n32\n,\n32\n)\nsh\n=\nshuffle_rows\n(\nimg\n)\nprint\n(\nsh\n.\nshape\n)\n# torch.Size([3, 32, 32])\n# every value still present, exactly once\nprint\n(\ntorch\n.\nequal\n(\nsh\n.\nflatten\n().\nsort\n().\nvalues\n,\nimg\n.\nflatten\n().\nsort\n().\nvalues\n))\n# True\n# and it's perfectly reversible\ninv\n=\ntorch\n.\nempty_like\n(\nrow_perm\n)\ninv\n[\nrow_perm\n]\n=\ntorch\n.\narange\n(\n32\n)\nprint\n(\ntorch\n.\nequal\n(\nsh\n[:,\ninv\n,\n:],\nimg\n))\n# True\nEnter fullscreen mode\nExit fullscreen mode\nEvery pixel is still there, with its original value. The transformation is invertible, so no information has been lost in any sense that information theory would recognise. What changed is\nwhich pixels sit next to which\n.\nAnd here's the control experiment that settles it:\nthe fully-connected model scores the same either way\n— 51.4% natural, 51.7% shuffled, a difference well inside run-to-run noise. If the shuffle had damaged the data, the linear model would have suffered too. It didn't, because it never used the layout in the first place — after\nflatten()\n, position 400 is just position 400, and a fixed permutation of the input columns is something the first layer absorbs by permuting its own weights. The network is free to relearn the identical function; only the column labels moved.\nSo the shuffle removes exactly one thing: the\nusefulness\nof the assumption that neighbouring pixels are related. And that assumption turns out to be worth 6.7 of the CNN's 7.0 points.\nWhich is the uncomfortable version of the finding: the convolutions, the pooling, the normalisation — all of it — were converting one true fact about photographs into 7 points of accuracy. Take the fact away and the machinery has nothing left to convert.\nWhat a convolution actually assumes\nWritten out, a conv layer makes three claims about your data, none of which are claims about tensors:\nLocality.\nA 3×3 kernel only ever sees a 3×3 neighbourhood. This is a bet that meaningful patterns are\nlocal\n— that to recognise an edge you need nearby pixels and not distant ones. True of photographs. Not true of a shuffled photograph, where the pixels that formed an edge are now scattered across the image.\nWeight sharing.\nThe same kernel slides over every position, so a feature detected in the top-left uses identical weights to the same feature bottom-right. This is a bet that\nwhat\na pattern is doesn't depend on\nwhere\nit is. It's also where the parameter savings come from — and it's why the shuffled case doesn't merely lose the advantage but wastes capacity, since the kernel is now sharing weights across positions that have nothing in common.\nHierarchy.\nStacked layers assume small patterns compose into larger ones: edges into corners, corners into shapes. A shuffled image has edges nowhere, so there is nothing to compose.\nAll three are statements about the world, not the maths. When they hold, they're enormously valuable — a prior that good is worth more than a lot of data. When they don't hold, depth doesn't manufacture them.\nTry it yourself\nRoughly this, on CPU, in a few minutes:\nimport\ntorch\n,\ntorchvision\nfrom\ntorchvision\nimport\ntransforms\ng\n=\ntorch\n.\nGenerator\n().\nmanual_seed\n(\n0\n)\nrow_perm\n=\ntorch\n.\nrandperm\n(\n32\n,\ngenerator\n=\ng\n)\nnorm\n=\ntransforms\n.\nNormalize\n([\n0.5\n]\n*\n3\n,\n[\n0.5\n]\n*\n3\n)\nbase\n=\n[\ntransforms\n.\nToTensor\n(),\nnorm\n]\nshuffled\n=\nbase\n+\n[\ntransforms\n.\nLambda\n(\nlambda\nx\n:\nx\n[:,\nrow_perm\n,\n:])]\ntrain_nat\n=\ntorchvision\n.\ndatasets\n.\nCIFAR10\n(\nroot\n=\n\"\n./data\n\"\n,\ntrain\n=\nTrue\n,\ndownload\n=\nTrue\n,\ntransform\n=\ntransforms\n.\nCompose\n(\nbase\n))\ntrain_shuf\n=\ntorchvision\n.\ndatasets\n.\nCIFAR10\n(\nroot\n=\n\"\n./data\n\"\n,\ntrain\n=\nTrue\n,\ndownload\n=\nTrue\n,\ntransform\n=\ntransforms\n.\nCompose\n(\nshuffled\n))\n# ...and the same two for train=False\nEnter fullscreen mode\nExit fullscreen mode\nThen train any small CNN and any\nFlatten → Linear → ReLU → Linear\non each of the four loaders. Four runs. Watch the CNN's lead evaporate while the fully-connected model shrugs.\nTwo things to keep honest while you do it: build the permutation\nonce\n, outside the transform, or you'll get a different shuffle per image, which really does destroy information and proves nothing. And use the same seed and epoch count across all four runs, or you're measuring your own variance.\nMy run, for the record: torch 2.13.0 on CPU,\nmanual_seed(0)\n, Adam at 1e-3, batch 128 train / 256 eval, 5 epochs, normalised to mean 0.5 / std 0.5, row permutation seeded 1234.\nWhere this actually matters\nThis isn't a party trick. It's the question to ask before choosing any architecture:\nwhat is this thing assuming about my data, and is the assumption true?\nTabular data.\nColumns have no spatial relationship —\nage\nnext to\npostcode\nnext to\nincome\nis an arbitrary ordering you could permute at will. A CNN over columns is the shuffled experiment, permanently. This is a large part of why gradient-boosted trees still win on tabular problems.\nSpectrograms and time series.\nThese\ndo\nhave local structure along at least one axis, so a 1-D convolution is a real prior rather than a fashion choice. Neighbouring time steps are genuinely related.\nChannel order.\nPermuting the\nchannel\naxis of an image is not the same operation and is nearly harmless, because a conv kernel spans all channels at once — there's no locality assumption along that axis to break. Worth knowing, because it's the first thing people try to use as a counter-example.\nAttention.\nSelf-attention makes no locality assumption at all, which is exactly why transformers need positional encoding bolted on and why they need more data to reach the same place on images. Fewer assumptions is not automatically better; it means less free knowledge and more required evidence.\nThe honest caveats\nOne dataset, one small architecture, one seed, at 32×32, five epochs — nobody's state of the art. The\ndirection\nof this result is robust and it's the standard inductive-bias argument that the literature has made for years. The specific numbers are mine and yours will differ — the point of running it isn't the decimal places, it's watching a 7-point advantage turn into a rounding error while the data stays intact.\nThe takeaway\nArchitecture isn't magic and it isn't a leaderboard. It's a bet about the structure of your data, made before training starts. A convolution bets that nearby things belong together. On photographs that bet pays enormously. Break its truth without touching a single pixel value and the same architecture is worth about a third of a point.\nSo when someone asks why your model isn't learning, the useful question often isn't \"should I go deeper\" — it's whether the architecture's assumptions were ever true of your data.\nThis experiment is from Chapter 8 of **PyTorch From Ground Up, Volume 2\n, which I'm writing now. The whole book works this way: no solution gets introduced until you've watched the failure it fixes — no convolution before a linear layer fails, no skip connection before a 56-layer network loses to a 20-layer one.\nRun it yourself:\nopen the Chapter 8 notebook in Colab\n— every code block from the chapter, in order, CPU-only, nothing to install. The four-model comparison is the slow cell, about 15 minutes.\nVolume 2 isn't finished yet.\nVolume 1 —\nFoundations\n, the tensors-and-training-loop book underneath all of this — is out, and\n8 of its chapters are free with no email required\n.\nWhat's an architecture choice that quietly bought you nothing?\nI collect these — the ones that surprise me end up as experiments.",
  "metadata": {
    "title": "Your CNN's Advantage Is One Assumption — and I Measured What Happens When It Breaks - DEV Community",
    "description": "A small convolutional network beats a plain flatten-and-feed-it-forward network by 7.0 points on... Tagged with computervision, deeplearning, machinelearning, python.",
    "keywords": "computervision, deeplearning, machinelearning, python, software, coding, development, engineering, inclusive, community",
    "author": null,
    "og:type": "article",
    "og:url": "https://dev.to/pytorchfromgroundup/your-cnns-advantage-is-one-assumption-and-i-measured-what-happens-when-it-breaks-490d",
    "og:title": "Your CNN's Advantage Is One Assumption — and I Measured What Happens When It Breaks",
    "og:description": "A small convolutional network beats a plain flatten-and-feed-it-forward network by 7.0 points on...",
    "og:site_name": "DEV Community",
    "og:image": "https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo0xaxaccvzhd6rx1rjs9.png",
    "twitter:site": "@thepracticaldev",
    "twitter:creator": "@wesamkhallaf",
    "twitter:title": "Your CNN's Advantage Is One Assumption — and I Measured What Happens When It Breaks",
    "twitter:description": "A small convolutional network beats a plain flatten-and-feed-it-forward network by 7.0 points on...",
    "twitter:card": "summary_large_image",
    "twitter:widgets:new-embed-design": "on",
    "twitter:image:src": "https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fo0xaxaccvzhd6rx1rjs9.png"
  },
  "paywall": {
    "listed_paid": false,
    "detected": false,
    "marker": "",
    "public_only": false,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "file": "attachments/5295aeb5bbb9/code/body-000.txt",
      "chars": 232,
      "language": "text"
    },
    {
      "file": "attachments/5295aeb5bbb9/code/body-001.txt",
      "chars": 477,
      "language": "text"
    },
    {
      "file": "attachments/5295aeb5bbb9/code/body-002.txt",
      "chars": 662,
      "language": "text"
    }
  ],
  "images": [],
  "audio": [],
  "videos": [],
  "links": [
    {
      "href": "https://colab.research.google.com/github/pytorch-from-ground-up/book_code/blob/main/notebooks/volume-2-architectures/08-sequences-time-order.ipynb",
      "label": "open the Chapter 8 notebook in Colab",
      "type": "a"
    },
    {
      "href": "https://github.com/pytorch-from-ground-up/book_code/blob/main/PyTorch-From-Ground-Up-8-Free-Chapters.pdf",
      "label": "8 of its chapters are free with no email required",
      "type": "a"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T10:48:51Z",
  "source_url": "https://dev.to/pytorchfromgroundup/your-cnns-advantage-is-one-assumption-and-i-measured-what-happens-when-it-breaks-490d",
  "papers": [
    {
      "status": "ok",
      "url": "https://raw.githubusercontent.com/pytorch-from-ground-up/book_code/main/PyTorch-From-Ground-Up-8-Free-Chapters.pdf",
      "bytes": 2552607,
      "reused": false,
      "local_path": "papers/repair/2927ef550363909d894f.pdf"
    }
  ],
  "actual_video_files": [],
  "body_chars": 9467,
  "expected_body_images": 0,
  "discovery_status": "ok",
  "delivery_status": "ok",
  "missing_reason": "",
  "raw_html": "attachments/5295aeb5bbb9/pages/source.html",
  "local_html": "attachments/5295aeb5bbb9/pages/article.html",
  "body_base_path": "attachments/5295aeb5bbb9/pages/",
  "body_markdown_path": "attachments/5295aeb5bbb9/pages/article.md"
}