CoolFace
Datasetpublic

Anurag1734/cuda-error-resolution-analysis

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes7downloads
topics_batch_91.json61735 linesDownload Raw Back to raw
1[2  {3    "post_stream": {4      "posts": [5        {6          "id": 399551,7          "name": "",8          "username": "rhwang",9          "avatar_template": "/user_avatar/discuss.pytorch.org/rhwang/{size}/60609_2.png",10          "created_at": "2023-04-26T04:14:10.334Z",11          "cooked": "<p>Hi, I`m trying to overlap the computation and memory operation with HuggingFace SwitchTransformer.</p>\n<p>Here’s a detailed explanation.</p>\n<ul>\n<li>The memory operation is for data movement from CPU to GPU, and its size is 4MB per block.</li>\n<li>The number of blocks is variable (typically from 2 to 6 in total).</li>\n<li>The computation operation comprises several very small computation operations like GEMM, which takes 10s to 100s microseconds per each.</li>\n<li>I’m trying to use CudaStream, so I created two different Cuda streams and pushed memory operation and computation operation to each of them.</li>\n<li>But it had not been overlapped.</li>\n</ul>\n<p><div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"https://discuss.pytorch.org/uploads/default/original/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f.png\" data-download-href=\"https://discuss.pytorch.org/uploads/default/c81014c2b4596e02379fe63c3c782d8ba943fe8f\" title=\"image\"><img src=\"https://discuss.pytorch.org/uploads/default/optimized/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f_2_690x295.png\" alt=\"image\" data-base62-sha1=\"sxPWKSrfPFEp9w66SFTicyWbIIL\" width=\"690\" height=\"295\" srcset=\"https://discuss.pytorch.org/uploads/default/optimized/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f_2_690x295.png, https://discuss.pytorch.org/uploads/default/optimized/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f_2_1035x442.png 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f.png 2x\" data-dominant-color=\"E0D8D2\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use href=\"#far-image\"></use></svg><span class=\"filename\">image</span><span class=\"informations\">1057×453 114 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use href=\"#discourse-expand\"></use></svg></div></a></div></p>\n<p>And here’s my question.</p>\n<ol>\n<li>\n<p>Firstly, I’d learn that to overlap the memory operation (CPU-&gt;GPU) and computation operation, the memory in the CPU should be pinned. But in my case, as can be seen in the figure, it is pageable memory, not pinned. Is it a reason that this cannot be overlapped?</p>\n</li>\n<li>\n<p>Second, I conducted an experiment to prove it with a simple example (overlapping GEMM with CPU-&gt;GPU memory operation), and here`s the output.<br>\n<div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"https://discuss.pytorch.org/uploads/default/original/3X/4/a/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb.png\" data-download-href=\"https://discuss.pytorch.org/uploads/default/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb\" title=\"image\"><img src=\"https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb_2_690x192.png\" alt=\"image\" data-base62-sha1=\"aFfqMmlynVnXGuXzp1iOJilkyAb\" width=\"690\" height=\"192\" srcset=\"https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb_2_690x192.png, https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb_2_1035x288.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/4/a/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb_2_1380x384.png 2x\" data-dominant-color=\"D3DFCB\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use href=\"#far-image\"></use></svg><span class=\"filename\">image</span><span class=\"informations\">1473×410 16.8 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use href=\"#discourse-expand\"></use></svg></div></a></div><br>\nThis is pageable memory.<br>\n<div class=\"lightbox-wrapper\"><a class=\"lightbox\" href=\"https://discuss.pytorch.org/uploads/default/original/3X/8/2/8261178566d0f8a63b7271c28860109f109a94fc.png\" data-download-href=\"https://discuss.pytorch.org/uploads/default/8261178566d0f8a63b7271c28860109f109a94fc\" title=\"image\"><img src=\"https://discuss.pytorch.org/uploads/default/optimized/3X/8/2/8261178566d0f8a63b7271c28860109f109a94fc_2_690x179.png\" alt=\"image\" data-base62-sha1=\"iBo5yemOfpQvPKIydDnoq1Vgi16\" width=\"690\" height=\"179\" srcset=\"https://discuss.pytorch.org/uploads/default/optimized/3X/8/2/8261178566d0f8a63b7271c28860109f109a94fc_2_690x179.png, https://discuss.pytorch.org/uploads/default/optimized/3X/8/2/8261178566d0f8a63b7271c28860109f109a94fc_2_1035x268.png 1.5x, https://discuss.pytorch.org/uploads/default/optimized/3X/8/2/8261178566d0f8a63b7271c28860109f109a94fc_2_1380x358.png 2x\" data-dominant-color=\"BCDAD6\"><div class=\"meta\"><svg class=\"fa d-icon d-icon-far-image svg-icon\" aria-hidden=\"true\"><use href=\"#far-image\"></use></svg><span class=\"filename\">image</span><span class=\"informations\">1446×376 18.7 KB</span><svg class=\"fa d-icon d-icon-discourse-expand svg-icon\" aria-hidden=\"true\"><use href=\"#discourse-expand\"></use></svg></div></a></div><br>\nThis is pinned memory.</p>\n</li>\n</ol>\n<p>It seems like pageable memory also can be overlapped.<br>\nThen, what is the reason that my application is not overlapping?</p>",12          "post_number": 1,13          "post_type": 1,14          "posts_count": 2,15          "updated_at": "2023-04-26T05:18:32.756Z",16          "reply_count": 0,17          "reply_to_post_number": null,18          "quote_count": 0,19          "incoming_link_count": 123,20          "reads": 10,21          "readers_count": 9,22          "score": 617.0,23          "yours": false,24          "topic_id": 178541,25          "topic_slug": "can-we-overlap-compute-operation-with-memory-operation-without-pinned-memory-on-cpu",26          "display_username": "",27          "primary_group_name": null,28          "flair_name": null,29          "flair_url": null,30          "flair_bg_color": null,31          "flair_color": null,32          "flair_group_id": null,33          "badges_granted": [],34          "version": 2,35          "can_edit": false,36          "can_delete": false,37          "can_recover": false,38          "can_see_hidden_post": false,39          "can_wiki": false,40          "link_counts": [41            {42              "url": "https://discuss.pytorch.org/uploads/default/original/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f.png",43              "internal": true,44              "reflection": false,45              "clicks": 046            },47            {48              "url": "https://discuss.pytorch.org/uploads/default/original/3X/4/a/4abf69916ab6bcd0cd45ed4cbd76b0d4503eeffb.png",49              "internal": true,50              "reflection": false,51              "clicks": 052            },53            {54              "url": "https://discuss.pytorch.org/uploads/default/original/3X/8/2/8261178566d0f8a63b7271c28860109f109a94fc.png",55              "internal": true,56              "reflection": false,57              "clicks": 058            }59          ],60          "read": true,61          "user_title": null,62          "bookmarked": false,63          "actions_summary": [],64          "moderator": false,65          "admin": false,66          "staff": false,67          "user_id": 62072,68          "hidden": false,69          "trust_level": 1,70          "deleted_at": null,71          "user_deleted": false,72          "edit_reason": null,73          "can_view_edit_history": true,74          "wiki": false,75          "post_url": "/t/can-we-overlap-compute-operation-with-memory-operation-without-pinned-memory-on-cpu/178541/1",76          "can_accept_answer": false,77          "can_unaccept_answer": false,78          "accepted_answer": false,79          "topic_accepted_answer": null,80          "can_vote": false81        },82        {83          "id": 427468,84          "name": "",85          "username": "DeanHHH",86          "avatar_template": "/letter_avatar_proxy/v4/letter/d/eada6e/{size}.png",87          "created_at": "2023-12-17T14:31:49.379Z",88          "cooked": "<p>I am also very concerned about this question but I have not found the answer. Do you have any progress?</p>",89          "post_number": 2,90          "post_type": 1,91          "posts_count": 2,92          "updated_at": "2023-12-17T14:31:49.379Z",93          "reply_count": 0,94          "reply_to_post_number": null,95          "quote_count": 0,96          "incoming_link_count": 2,97          "reads": 3,98          "readers_count": 2,99          "score": 10.6,100          "yours": false,101          "topic_id": 178541,102          "topic_slug": "can-we-overlap-compute-operation-with-memory-operation-without-pinned-memory-on-cpu",103          "display_username": "",104          "primary_group_name": null,105          "flair_name": null,106          "flair_url": null,107          "flair_bg_color": null,108          "flair_color": null,109          "flair_group_id": null,110          "badges_granted": [],111          "version": 1,112          "can_edit": false,113          "can_delete": false,114          "can_recover": false,115          "can_see_hidden_post": false,116          "can_wiki": false,117          "read": true,118          "user_title": null,119          "bookmarked": false,120          "actions_summary": [],121          "moderator": false,122          "admin": false,123          "staff": false,124          "user_id": 71796,125          "hidden": false,126          "trust_level": 0,127          "deleted_at": null,128          "user_deleted": false,129          "edit_reason": null,130          "can_view_edit_history": true,131          "wiki": false,132          "post_url": "/t/can-we-overlap-compute-operation-with-memory-operation-without-pinned-memory-on-cpu/178541/2",133          "can_accept_answer": false,134          "can_unaccept_answer": false,135          "accepted_answer": false,136          "topic_accepted_answer": null137        }138      ],139      "stream": [140        399551,141        427468142      ]143    },144    "timeline_lookup": [145      [146        1,147        914148      ],149      [150        2,151        678152      ]153    ],154    "suggested_topics": [155      {156        "fancy_title": "Documents as parametric memory",157        "id": 215242,158        "title": "Documents as parametric memory",159        "slug": "documents-as-parametric-memory",160        "posts_count": 1,161        "reply_count": 0,162        "highest_post_number": 1,163        "image_url": null,164        "created_at": "2025-01-11T01:22:00.572Z",165        "last_posted_at": "2025-01-11T01:22:00.615Z",166        "bumped": true,167        "bumped_at": "2025-01-11T01:22:00.615Z",168        "archetype": "regular",169        "unseen": false,170        "pinned": false,171        "unpinned": null,172        "visible": true,173        "closed": false,174        "archived": false,175        "bookmarked": null,176        "liked": null,177        "tags_descriptions": {},178        "like_count": 0,179        "views": 103,180        "category_id": 8,181        "featured_link": null,182        "has_accepted_answer": false,183        "posters": [184          {185            "extras": "latest single",186            "description": "Original Poster, Most Recent Poster",187            "user": {188              "id": 72190,189              "username": "Sai1",190              "name": "Sai",191              "avatar_template": "/user_avatar/discuss.pytorch.org/sai1/{size}/62072_2.png",192              "trust_level": 1193            }194          }195        ]196      },197      {198        "fancy_title": "How does one set the pad token correctly (not to eos) during fine-tuning to avoid model not predicting EOS?",199        "id": 213619,200        "title": "How does one set the pad token correctly (not to eos) during fine-tuning to avoid model not predicting EOS?",201        "slug": "how-does-one-set-the-pad-token-correctly-not-to-eos-during-fine-tuning-to-avoid-model-not-predicting-eos",202        "posts_count": 1,203        "reply_count": 0,204        "highest_post_number": 1,205        "image_url": null,206        "created_at": "2024-11-29T17:47:47.630Z",207        "last_posted_at": "2024-11-29T17:47:47.686Z",208        "bumped": true,209        "bumped_at": "2024-11-29T17:47:47.686Z",210        "archetype": "regular",211        "unseen": false,212        "pinned": false,213        "unpinned": null,214        "visible": true,215        "closed": false,216        "archived": false,217        "bookmarked": null,218        "liked": null,219        "tags_descriptions": {},220        "like_count": 0,221        "views": 1062,222        "category_id": 8,223        "featured_link": null,224        "has_accepted_answer": false,225        "posters": [226          {227            "extras": "latest single",228            "description": "Original Poster, Most Recent Poster",229            "user": {230              "id": 2282,231              "username": "Brando_Miranda",232              "name": "MirandaAgent",233              "avatar_template": "/user_avatar/discuss.pytorch.org/brando_miranda/{size}/14355_2.png",234              "trust_level": 2235            }236          }237        ]238      },239      {240        "fancy_title": "How to Implement Flash Attention in a Pre-Trained BERT Model on custom dataset?",241        "id": 215112,242        "title": "How to Implement Flash Attention in a Pre-Trained BERT Model on custom dataset?",243        "slug": "how-to-implement-flash-attention-in-a-pre-trained-bert-model-on-custom-dataset",244        "posts_count": 1,245        "reply_count": 0,246        "highest_post_number": 1,247        "image_url": null,248        "created_at": "2025-01-08T10:01:45.049Z",249        "last_posted_at": "2025-01-08T10:01:45.095Z",250        "bumped": true,251        "bumped_at": "2025-01-08T11:59:12.564Z",252        "archetype": "regular",253        "unseen": false,254        "pinned": false,255        "unpinned": null,256        "visible": true,257        "closed": false,258        "archived": false,259        "bookmarked": null,260        "liked": null,261        "tags_descriptions": {},262        "like_count": 0,263        "views": 197,264        "category_id": 8,265        "featured_link": null,266        "has_accepted_answer": false,267        "posters": [268          {269            "extras": "latest single",270            "description": "Original Poster, Most Recent Poster",271            "user": {272              "id": 81942,273              "username": "Karam1533",274              "name": "Karam",275              "avatar_template": "/user_avatar/discuss.pytorch.org/karam1533/{size}/74966_2.png",276              "trust_level": 0277            }278          }279        ]280      },281      {282        "fancy_title": "Need help with Recurrent lstms",283        "id": 215195,284        "title": "Need help with Recurrent lstms",285        "slug": "need-help-with-recurrent-lstms",286        "posts_count": 1,287        "reply_count": 0,288        "highest_post_number": 1,289        "image_url": "https://discuss.pytorch.org/uploads/default/original/3X/b/4/b499c6589da3192d332d676dc1096093ba3df607.jpeg",290        "created_at": "2025-01-10T08:06:38.992Z",291        "last_posted_at": "2025-01-10T08:06:39.052Z",292        "bumped": true,293        "bumped_at": "2025-01-10T08:40:23.002Z",294        "archetype": "regular",295        "unseen": false,296        "pinned": false,297        "unpinned": null,298        "visible": true,299        "closed": false,300        "archived": false,301        "bookmarked": null,302        "liked": null,303        "tags_descriptions": {},304        "like_count": 0,305        "views": 28,306        "category_id": 8,307        "featured_link": null,308        "has_accepted_answer": false,309        "posters": [310          {311            "extras": "latest single",312            "description": "Original Poster, Most Recent Poster",313            "user": {314              "id": 81982,315              "username": "MD_Shahadat_Hossain",316              "name": "MD. Shahadat Hossain Shahal",317              "avatar_template": "/user_avatar/discuss.pytorch.org/md_shahadat_hossain/{size}/75009_2.png",318              "trust_level": 0319            }320          }321        ]322      },323      {324        "fancy_title": "What is the right way to structure `input` and `label` while fine-tuning decoder only model",325        "id": 215931,326        "title": "What is the right way to structure `input` and `label` while fine-tuning decoder only model",327        "slug": "what-is-the-right-way-to-structure-input-and-label-while-fine-tuning-decoder-only-model",328        "posts_count": 1,329        "reply_count": 0,330        "highest_post_number": 1,331        "image_url": null,332        "created_at": "2025-01-27T13:15:44.900Z",333        "last_posted_at": "2025-01-27T13:15:44.942Z",334        "bumped": true,335        "bumped_at": "2025-01-27T13:48:53.036Z",336        "archetype": "regular",337        "unseen": false,338        "pinned": false,339        "unpinned": null,340        "visible": true,341        "closed": false,342        "archived": false,343        "bookmarked": null,344        "liked": null,345        "tags_descriptions": {},346        "like_count": 0,347        "views": 31,348        "category_id": 8,349        "featured_link": null,350        "has_accepted_answer": false,351        "posters": [352          {353            "extras": "latest single",354            "description": "Original Poster, Most Recent Poster",355            "user": {356              "id": 77539,357              "username": "Seungjun_Lee",358              "name": "Seungjun Lee",359              "avatar_template": "/user_avatar/discuss.pytorch.org/seungjun_lee/{size}/71547_2.png",360              "trust_level": 1361            }362          }363        ]364      }365    ],366    "tags_descriptions": {},367    "fancy_title": "Can we overlap compute operation with memory operation without pinned memory on CPU?",368    "id": 178541,369    "title": "Can we overlap compute operation with memory operation without pinned memory on CPU?",370    "posts_count": 2,371    "created_at": "2023-04-26T04:14:10.249Z",372    "views": 540,373    "reply_count": 0,374    "like_count": 0,375    "last_posted_at": "2023-12-17T14:31:49.379Z",376    "visible": true,377    "closed": false,378    "archived": false,379    "has_summary": false,380    "archetype": "regular",381    "slug": "can-we-overlap-compute-operation-with-memory-operation-without-pinned-memory-on-cpu",382    "category_id": 8,383    "word_count": 242,384    "deleted_at": null,385    "user_id": 62072,386    "featured_link": null,387    "pinned_globally": false,388    "pinned_at": null,389    "pinned_until": null,390    "image_url": "https://discuss.pytorch.org/uploads/default/optimized/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f_2_1024x438.png",391    "slow_mode_seconds": 0,392    "draft": null,393    "draft_key": "topic_178541",394    "draft_sequence": null,395    "unpinned": null,396    "pinned": false,397    "current_post_number": 1,398    "highest_post_number": 2,399    "deleted_by": null,400    "actions_summary": [401      {402        "id": 4,403        "count": 0,404        "hidden": false,405        "can_act": false406      },407      {408        "id": 8,409        "count": 0,410        "hidden": false,411        "can_act": false412      },413      {414        "id": 10,415        "count": 0,416        "hidden": false,417        "can_act": false418      },419      {420        "id": 7,421        "count": 0,422        "hidden": false,423        "can_act": false424      }425    ],426    "chunk_size": 20,427    "bookmarked": false,428    "topic_timer": null,429    "message_bus_last_id": 0,430    "participant_count": 2,431    "show_read_indicator": false,432    "thumbnails": [433      {434        "max_width": null,435        "max_height": null,436        "width": 1057,437        "height": 453,438        "url": "https://discuss.pytorch.org/uploads/default/original/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f.png"439      },440      {441        "max_width": 1024,442        "max_height": 1024,443        "width": 1024,444        "height": 438,445        "url": "https://discuss.pytorch.org/uploads/default/optimized/3X/c/8/c81014c2b4596e02379fe63c3c782d8ba943fe8f_2_1024x438.png"446      }447    ],448    "slow_mode_enabled_until": null,449    "can_vote": false,450    "vote_count": 0,451    "user_voted": false,452    "discourse_zendesk_plugin_zendesk_id": null,453    "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",454    "details": {455      "can_edit": false,456      "notification_level": 1,457      "participants": [458        {459          "id": 62072,460          "username": "rhwang",461          "name": "",462          "avatar_template": "/user_avatar/discuss.pytorch.org/rhwang/{size}/60609_2.png",463          "post_count": 1,464          "primary_group_name": null,465          "flair_name": null,466          "flair_url": null,467          "flair_color": null,468          "flair_bg_color": null,469          "flair_group_id": null,470          "trust_level": 1471        },472        {473          "id": 71796,474          "username": "DeanHHH",475          "name": "",476          "avatar_template": "/letter_avatar_proxy/v4/letter/d/eada6e/{size}.png",477          "post_count": 1,478          "primary_group_name": null,479          "flair_name": null,480          "flair_url": null,481          "flair_color": null,482          "flair_bg_color": null,483          "flair_group_id": null,484          "trust_level": 0485        }486      ],487      "created_by": {488        "id": 62072,489        "username": "rhwang",490        "name": "",491        "avatar_template": "/user_avatar/discuss.pytorch.org/rhwang/{size}/60609_2.png"492      },493      "last_poster": {494        "id": 71796,495        "username": "DeanHHH",496        "name": "",497        "avatar_template": "/letter_avatar_proxy/v4/letter/d/eada6e/{size}.png"498      }499    },500    "bookmarks": []501  },502  {503    "post_stream": {504      "posts": [505        {506          "id": 427465,507          "name": "pet shor",508          "username": "pet_shor",509          "avatar_template": "/user_avatar/discuss.pytorch.org/pet_shor/{size}/66322_2.png",510          "created_at": "2023-12-17T14:18:34.330Z",511          "cooked": "<p>Hello everyone,</p>\n<p>I’m working on a project for my school in the field of computer vision, this topic is very new to me and I have no one to help me (university particularity). I encounter the specific error “RuntimeError: Expected 3D (unbatched) or 4D (batched) input to conv2d, but got input of size: [2, 12]”.<br>\nI have tried using ChatGPT to help me but I keep getting the same things over and over again, but I’m still struggling to understand why my model got input of size [2, 12].</p>\n<p>I am using the SSD (Single Shot Detector) model with a resnet18 backbone. Also,I’m using a specific dataset with space images of different objects like spacecraft or debris. The goal is to train a model to be able to detect these different objects with a good accuracy on the images (11 classes).</p>\n<p>There is not so much information about the ssd model I think, and my case is a little bit particular from what I have seen on internet. For now I need to run my model locally on my pc with a data sample (1100 images, 100 of each class), and then i will run and train my model on a cloud platform from my university.</p>\n<p>Main code :</p>\n<pre><code class=\"lang-auto\"># Main code\nimport torch\nfrom utilsSample import SPARKDataset  # Assuming SPARKDataset is defined in utils.py\nfrom utilsSample import PyTorchSparkDataset  # Assuming SPARKDataset is defined in utils.py\nfrom torchvision import transforms\nfrom torch.utils.data import DataLoader\nfrom torchvision.models.detection import ssd\nfrom torchvision.models.mobilenet import mobilenet_v2\nfrom torchvision.models.detection.anchor_utils import AnchorGenerator\nfrom torchvision.models import resnet18\nimport matplotlib.pyplot as plt\nfrom random import randint\n\n# Assuming you have your dataset defined in SPARKDataset class in utils.py\n\n# # Define transforms (adjust these based on your requirements)\n# transform = transforms.Compose([\n#     transforms.Resize((300, 300)),  # Resizing\n#     transforms.ToTensor()\n# ])\n\n# Path to your dataset directory\ndata_root = 'C:\\\\Users\\\\alibe\\\\Documents\\\\UPSSITECH3\\\\ERASMUS cours\\\\Computer Vision and Image Analysis\\\\stream-1\\\\data samples\\\\'\n\n# Define the class map, you can use the same as previously defined\nclass_map = {\n    'proba_2': 0, 'cheops': 1, 'debris': 2, 'double_star': 3, 'earth_observation_sat_1': 4, 'lisa_pathfinder': 5,\n    'proba_3_csc': 6, 'proba_3_ocs': 7, 'smart_1': 8, 'soho': 9, 'xmm_newton': 10\n}\n\n# Dataset initialization\nvisualize_train_dataset = SPARKDataset(class_map, root_dir=data_root, split='train', transform=None)\nvisualize_val_dataset = SPARKDataset(class_map, root_dir=data_root, split='val', transform=None)\n\ntrain_dataset = PyTorchSparkDataset(class_map, root_dir=data_root, split='train', transform=None)\nval_dataset = PyTorchSparkDataset(class_map, root_dir=data_root, split='val', transform=None)\n\n# Define the model\nbackbone = resnet18(pretrained=True)\n\nnum_classes = 12  # Number of classes in your dataset\nnum_channels = 3 #Number of channels for one image in the dataset\n\n# Assuming fc layer is the fully connected layer in your model\nbackbone.fc = torch.nn.Linear(backbone.fc.in_features, num_classes)\n\n# SSD needs an anchor generator - define it\nanchor_generator = AnchorGenerator(sizes=((32, 64, 128, 256, 512),),\n                                   aspect_ratios=((0.5, 1.0, 2.0),))\n\n# Size of the image used as input (1024x1024 in your case)\nimage_size = (300, 300)\n\n# Create the SSD model with the specified components\nmodel = ssd.SSD(backbone, anchor_generator, image_size, num_classes)\n\n#######\n# Define the optimizer\noptimizer = torch.optim.SGD(model.parameters(), lr=0.001, momentum=0.9)\n\nprint(type(train_dataset))\n\n# Define the custom collate function\n# def custom_collate(batch):\n#     images, targets = zip(*batch)\n#     images = torch.stack(images)\n#     return images, targets\n\n# # Define the data loaders\ntrain_loader = DataLoader(train_dataset, batch_size=2, shuffle=True)\nval_loader = DataLoader(val_dataset, batch_size=2, shuffle=False)\n# Define the data loaders with custom collate function\n# train_loader = DataLoader(train_dataset, batch_size=1, shuffle=True, collate_fn=custom_collate)\n# val_loader = DataLoader(val_dataset, batch_size=1, shuffle=False, collate_fn=custom_collate)\n\n\nprint(type(train_loader))\nprint(train_loader)\n\n</code></pre>\n<pre><code class=\"lang-auto\"># setting device to model\ndevice = torch.device('cuda' if torch.cuda.is_available() else 'cpu')\nmodel.to(device)\ntorch.cuda.empty_cache()\n\n# Training Loop\nnum_epochs = 10\nfor epoch in range(num_epochs):\n    model.train()\n    for batch_idx, (images, targets) in enumerate(train_loader):\n        optimizer.zero_grad()\n        \n        # No need to stack, as images is already a batched tensor\n        # images = torch.stack(images)\n        # Convert images to the appropriate format\n        # images = images.to(device)\n    \n        print(targets[\"labels\"])\n        \n        print(batch_idx)\n        print(images)\n        print(targets)\n        print(\"images (input) variable type : \", type(images))\n        print(\"targets (input) variable type : \", type(targets))\n        print(len(images))\n        print(images.size)\n        print(images.shape)\n        \n        print(\"\")     \n        print(\"\")\n        # Debug print\n        # print(\"Mean of Image:\", torch.mean(images))\n        # print(\"Std of Image:\", torch.std(images))\n        print(\"\")\n        print(type(images))\n        # print(\"Input Size:\", images[0].size())\n        # print(\"Images Shape:\", images[0].shape)\n        #print(model)\n        print(\"\")\n\n        print('TARGETS PART')\n        print(type(targets))\n        print(targets)\n        print(\"\")\n        print(targets['boxes'])\n        print(targets['boxes'][0])\n        print(\"\")\n        print(targets['labels'])\n        print(\"\")\n        for key, value in targets.items():\n             print(value[0])\n        \n        \n        \n        targets_list = []\n        for i in range(len(targets[\"labels\"])):\n            boxes = targets[\"boxes\"][i].float()  # Remove the singleton dimension\n            # boxes = targets[\"boxes\"][i].squeeze(0).float()  # Remove the singleton dimension\n            # labels = targets[\"labels\"][i].squeeze(0)  # Remove the singleton dimension\n            labels = targets[\"labels\"][i].int() # Remove the singleton dimension\n            \n            # Construct a dictionary with the required structure\n            targets_dict = {\"boxes\": boxes, \"labels\": labels}\n            # Append the dictionary to the list\n            targets_list.append(targets_dict)\n        \n        \n        # print('TARGETS PART 2')\n        # print(targets)\n        # print(\"\")\n        # print(targets[\"boxes\"])\n        # print(targets[\"boxes\"].shape)\n\n        \n        \n        print(type(model))\n        print(model.transform)\n        #print(model)\n        \n        images = (images.float() / 255.0).to(device)\n        images = images.permute(0, 3, 1, 2).float() / 255.0  # Assuming the last dimension is channels\n        images = images.to(device)\n        \n        \n        print(\"Images SHAPE : \", images.shape)\n        print(\"Targets_list SHAPE : \", targets_dict[\"boxes\"].shape)\n        print(\"Targets_list SHAPE : \", targets_dict[\"labels\"].shape)\n        print(\"Targets_list TYPE : \", type(targets_dict[\"boxes\"]))\n        print(\"Targets_list TYPE : \", type(targets_dict[\"labels\"]))\n        print(targets_list)\n        \n        #print(model)\n        print(images.shape)\n        print(images)\n        \n        loss_dict = model(images, targets_list)\n        \n        \n        total_loss = sum(loss for loss in loss_dict.values())\n        total_loss.backward()\n        optimizer.step()\n        \n        \n        # # Print or log the loss if needed\n        # if batch_idx % log_interval == 0:\n        #     print(f'Epoch {epoch}, Batch {batch_idx}, Loss: {total_loss.item()}')\n\n\n</code></pre>\n<p>utilsSample.py</p>\n<pre><code class=\"lang-auto\">from ast import literal_eval\nimport os\nimport matplotlib.pyplot as plt\nfrom skimage import io , img_as_uint\nimport pandas as pd\nimport matplotlib.patches as mpatches\nfrom PIL import Image\nimport torch\nimport torchvision\nfrom torchvision import transforms\n\nclass YourCustomTransformation(transforms.Compose):\n    def __call__(self, img):\n        for t in self.transforms:\n            img = t(img)\n        return img\n\n\nclass ResizeWithBbox(transforms.Resize):\n    def __init__(self, size, apply_to_bbox=True):\n        super(ResizeWithBbox, self).__init__(size)\n        self.apply_to_bbox = apply_to_bbox\n\n    def __call__(self, img):\n        img = super(ResizeWithBbox, self).__call__(img)\n        \n        if self.apply_to_bbox:\n            # Bounding box adjustments can be done in SPARKDataset.__getitem__\n            return img\n        \n            \n        return img\n\n\n\ndef process_labels(labels_dir, split):\n    #path = os.path.join(labels_dir, file_name)\n    labels_filename = os.path.join(labels_dir, split + '.csv')  # Construct the file path correctly\n    labels = pd.read_csv(labels_filename, sep=';')\n    return labels\n\n\nclass SPARKDataset:\n\n    \"\"\" Class for dataset inspection: easily accessing single images, and corresponding ground truth pose data. \"\"\"\n\n    def __init__(self, class_map, root_dir ,split, transform=None, detection=True):\n        # self.root_dir = os.path.join(data_dir, split)\n        self.root_dir = root_dir\n        self.labels = process_labels(root_dir, split)\n        self.class_map =  class_map\n        self.transform = transform #Added the transform attribute\n        self.detection = detection #Add the detection attribute\n\n\n    def __getitem__(self, idx):\n        sat_name = self.labels.iloc[idx]['class']\n        img_name = self.labels.iloc[idx]['filename']\n        img_name_ok = 'train\\\\' + img_name\n        image_name = os.path.join(self.root_dir, img_name_ok)\n\n        # Load image as PIL image\n        image = Image.open(image_name)\n        \n        # Convert PIL image to tensor\n        image = transforms.ToTensor()(image)\n\n        # Initialize bbox\n        bbox = None\n\n        # Apply transformation if specified\n        if self.transform is not None:\n            image = self.transform(image)\n\n        if self.detection:\n            # Adjust bounding box accordingly\n            bbox = self.labels.iloc[idx]['bbox']\n            bbox = literal_eval(bbox)\n            bbox = [bbox[1], bbox[0], bbox[3], bbox[2]]  # Convert to [x_min, y_min, x_max, y_max]\n\n            targets = {\n                'boxes': torch.tensor([bbox], dtype=torch.float32),\n                'labels': torch.tensor([self.class_map[sat_name]], dtype=torch.int64),\n                #'image_id': img_name,  # Assuming 'filename' uniquely identifies each image\n            }\n\n        else:\n            # Include labeling information for non-detection case\n            targets = {\n                'labels': torch.tensor([self.class_map[sat_name]], dtype=torch.int64),\n                'image_id': img_name,  # Assuming 'filename' uniquely identifies each image\n            }\n\n        return image, targets\n\n\n\n\n    \n    \n    def __len__(self):\n        length = 1101\n        #return 66000  # Replace 66000 with the actual length of your dataset\n        return length  # Replace \"length\" with the dataset list, array, or the length of your dataset\n    \n    \n    def get_image(self, i=0):\n\n        \"\"\" Loading image as PIL image. \"\"\"\n        sat_name = self.labels.iloc[i]['class']\n        img_name = self.labels.iloc[i]['filename']\n        \n        img_name_ok = 'train\\\\' + img_name ###### To modify with the group of images choosen (train, val, test)\n        image_name = os.path.join(self.root_dir, img_name_ok) #Ensure image path is correctly created\n        \n        print('img_name_ok is : ' + img_name_ok)\n        print(\"Image Path:\", image_name) #Add this line for debugging\n        \n        image = io.imread(image_name)\n        return image , self.class_map[sat_name]\n\n    def get_bbox(self, i=0):\n\n        \"\"\" Getting bounding box for image. \"\"\"\n        bbox = self.labels.iloc[i]['bbox']\n        bbox    = literal_eval(bbox)\n        min_x, min_y, max_x, max_y = bbox\n\n        return min_x, min_y, max_x, max_y \n\n\n\n    def visualize(self,i, size=(15,15),  ax=None):\n\n        \"\"\" Visualizing image, with ground truth pose with axes projected to training image. \"\"\"\n\n        if ax is None:\n            ax = plt.gca()\n            \n        image, img_class = self.get_image(i)\n        min_x, min_y, max_x, max_y   = self.get_bbox(i)\n\n        ax.imshow(image,vmin=0, vmax=255)\n\n\n        rect = mpatches.Rectangle((min_y, min_x), max_y - min_y, max_x - min_x,\n                                        fill=False, edgecolor='red', linewidth=2)\n        ax.add_patch(rect)\n        \n        label = f\"{list(self.class_map.keys())[list(self.class_map.values()).index(img_class)]}\"\n        \n        ax.text(min_y, min_x-20, label,color='white',fontsize=15)\n        ax.set_axis_off()\n\n        return \n\n    \ntry:\n    import torch\n    from torch.utils.data import Dataset\n    from torchvision import transforms\n    has_pytorch = True\n    print('Found Pytorch')\nexcept ImportError:\n    has_pytorch = False\n\n    \nif has_pytorch:\n    class PyTorchSparkDataset(Dataset):\n\n        \"\"\" SPARK dataset that can be used with DataLoader for PyTorch training. \"\"\"\n\n        def __init__(self, class_map, split, root_dir, transform=None,detection = True):\n\n            if not has_pytorch:\n                raise ImportError('Pytorch was not imported successfully!')\n\n            if split not in {'train', 'val', 'test'}:\n                raise ValueError('Invalid split, has to be either \\'train\\', \\'val\\' or \\'test\\'')\n\n\n            self.class_map =  class_map\n            \n            self.detection = detection\n            self.split = split \n            self.root_dir = os.path.join(root_dir, self.split)\n            \n            self.labels = process_labels(root_dir,split)\n                \n            self.transform = transform\n\n        def __len__(self):\n            return len(self.labels)\n\n        def __getitem__(self, idx):\n            \n            sat_name = self.labels.iloc[idx]['class']\n            img_name = self.labels.iloc[idx]['filename']\n            image_name = f'{self.root_dir}/{img_name}'\n            \n            image = io.imread(image_name)\n\n\n            if self.transform is not None:\n                torch_image = self.transform(image)\n            \n            else:\n                torch_image = torch.from_numpy(image).permute(2,1,0)\n                \n            if self.detection:\n                \n                bbox = self.labels.iloc[idx]['bbox']\n                bbox = literal_eval(bbox)\n                bbox = [bbox[1], bbox[0], bbox[3], bbox[2]]  # Convert to [x_min, y_min, x_max, y_max]\n\n                targets = {\n                    'boxes': torch.tensor([bbox], dtype=torch.float32),\n                    'labels': torch.tensor([self.class_map[sat_name]], dtype=torch.int64),  # Use class_map here\n                    #'image_id': idx,  # Change to a single integer\n                }\n\n                return image, targets\n\n            return image, targets\n\n\nelse:\n    class PyTorchSparkDataset:\n        def __init__(self, *args, **kwargs):\n            raise ImportError('Pytorch is not available!')\n</code></pre>\n<p>My code is a bit messy with a lot of prints because I tried several things to get the right input format for the model.</p>\n<p>After running of the training loop, i have this output and this error :</p>\n<pre><code class=\"lang-auto\">Found Pytorch\nC:\\Users\\alibe\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torchvision\\models\\_utils.py:208: UserWarning: The parameter 'pretrained' is deprecated since 0.13 and may be removed in the future, please use 'weights' instead.\n  warnings.warn(\nC:\\Users\\alibe\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torchvision\\models\\_utils.py:223: UserWarning: Arguments other than a weight enum or `None` for 'weights' are deprecated since 0.13 and may be removed in the future. The current behavior is equivalent to passing `weights=ResNet18_Weights.IMAGENET1K_V1`. You can also use `weights=ResNet18_Weights.DEFAULT` to get the most up-to-date weights.\n  warnings.warn(msg)\n&lt;class 'utilsSample.PyTorchSparkDataset'&gt;\n&lt;class 'torch.utils.data.dataloader.DataLoader'&gt;\n&lt;torch.utils.data.dataloader.DataLoader object at 0x0000028DDDD64E50&gt;\nimg_name_ok is : train\\img084467.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img084467.jpg\nimg_name_ok is : train\\img068659.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img068659.jpg\nimg_name_ok is : train\\img087785.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img087785.jpg\nimg_name_ok is : train\\img040469.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img040469.jpg\nimg_name_ok is : train\\img043975.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img043975.jpg\nimg_name_ok is : train\\img020490.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img020490.jpg\nimg_name_ok is : train\\img080816.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img080816.jpg\nimg_name_ok is : train\\img073756.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img073756.jpg\nimg_name_ok is : train\\img025365.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img025365.jpg\nimg_name_ok is : train\\img031010.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img031010.jpg\nimg_name_ok is : train\\img061777.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img061777.jpg\nimg_name_ok is : train\\img068321.jpg\nImage Path: C:\\Users\\alibe\\Documents\\UPSSITECH3\\ERASMUS cours\\Computer Vision and Image Analysis\\stream-1\\data samples\\train\\img068321.jpg\n\ntensor([[4],\n        [9]])\n0\ntensor([[[[ 32,  32,  32],\n          [ 57,  57,  57],\n          [ 44,  44,  44],\n          ...,\n          [ 90,  89,  87],\n          [ 80,  79,  77],\n          [ 70,  69,  67]],\n\n         [[ 46,  46,  46],\n          [ 52,  52,  52],\n          [ 48,  48,  48],\n          ...,\n          [ 77,  76,  74],\n          [ 88,  87,  85],\n          [116, 115, 113]],\n\n         [[ 47,  47,  47],\n          [ 42,  42,  42],\n          [ 55,  55,  55],\n          ...,\n          [ 59,  58,  56],\n          [142, 141, 139],\n          [135, 134, 132]],\n\n         ...,\n\n         [[ 48,  48,  48],\n          [ 48,  48,  48],\n          [ 39,  39,  39],\n          ...,\n          [ 54,  54,  54],\n          [ 36,  36,  36],\n          [ 52,  52,  52]],\n\n         [[ 53,  53,  53],\n          [ 51,  51,  51],\n          [ 35,  35,  35],\n          ...,\n          [ 47,  47,  47],\n          [ 40,  40,  40],\n          [ 46,  46,  46]],\n\n         [[ 40,  40,  40],\n          [ 53,  53,  53],\n          [ 35,  35,  35],\n          ...,\n          [ 47,  47,  47],\n          [ 53,  53,  53],\n          [ 48,  48,  48]]],\n\n\n        [[[ 42,  42,  42],\n          [ 31,  31,  31],\n          [ 24,  24,  24],\n          ...,\n          [ 31,  31,  31],\n          [ 48,  48,  48],\n          [ 42,  42,  42]],\n\n         [[ 30,  30,  30],\n          [ 25,  25,  25],\n          [ 44,  44,  44],\n          ...,\n          [ 49,  49,  49],\n          [ 34,  34,  34],\n          [ 40,  40,  40]],\n\n         [[ 10,  10,  10],\n          [ 23,  23,  23],\n          [ 19,  19,  19],\n          ...,\n          [ 33,  33,  33],\n          [ 27,  27,  27],\n          [ 29,  29,  29]],\n\n         ...,\n\n         [[ 30,  30,  30],\n          [ 26,  26,  26],\n          [ 34,  34,  34],\n          ...,\n          [ 31,  31,  31],\n          [ 34,  34,  34],\n          [ 31,  31,  31]],\n\n         [[ 43,  43,  43],\n          [ 33,  33,  33],\n          [ 29,  29,  29],\n          ...,\n          [ 32,  32,  32],\n          [ 24,  24,  24],\n          [ 18,  18,  18]],\n\n         [[ 25,  25,  25],\n          [ 17,  17,  17],\n          [ 43,  43,  43],\n          ...,\n          [ 40,  40,  40],\n          [ 29,  29,  29],\n          [ 23,  23,  23]]]], dtype=torch.uint8)\n{'boxes': tensor([[[ 799.,    0., 1024.,   75.]],\n\n        [[  41.,  578.,  259.,  920.]]]), 'labels': tensor([[4],\n        [9]])}\nimages (input) variable type :  &lt;class 'torch.Tensor'&gt;\ntargets (input) variable type :  &lt;class 'dict'&gt;\n2\n&lt;built-in method size of Tensor object at 0x0000028DE60FDF90&gt;\ntorch.Size([2, 1024, 1024, 3])\n\n\n\n&lt;class 'torch.Tensor'&gt;\n\nTARGETS PART\n&lt;class 'dict'&gt;\n{'boxes': tensor([[[ 799.,    0., 1024.,   75.]],\n\n        [[  41.,  578.,  259.,  920.]]]), 'labels': tensor([[4],\n        [9]])}\n\ntensor([[[ 799.,    0., 1024.,   75.]],\n\n        [[  41.,  578.,  259.,  920.]]])\ntensor([[ 799.,    0., 1024.,   75.]])\n\ntensor([[4],\n        [9]])\n\ntensor([[ 799.,    0., 1024.,   75.]])\ntensor([4])\n&lt;class 'torchvision.models.detection.ssd.SSD'&gt;\nGeneralizedRCNNTransform(\n    Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])\n    Resize(min_size=(300,), max_size=300, mode='bilinear')\n)\nImages SHAPE :  torch.Size([2, 3, 1024, 1024])\nTargets_list SHAPE :  torch.Size([1, 4])\nTargets_list SHAPE :  torch.Size([1])\nTargets_list TYPE :  &lt;class 'torch.Tensor'&gt;\nTargets_list TYPE :  &lt;class 'torch.Tensor'&gt;\n[{'boxes': tensor([[ 799.,    0., 1024.,   75.]]), 'labels': tensor([4], dtype=torch.int32)}, {'boxes': tensor([[ 41., 578., 259., 920.]]), 'labels': tensor([9], dtype=torch.int32)}]\ntorch.Size([2, 3, 1024, 1024])\ntensor([[[[0.0005, 0.0009, 0.0007,  ..., 0.0014, 0.0012, 0.0011],\n          [0.0007, 0.0008, 0.0007,  ..., 0.0012, 0.0014, 0.0018],\n          [0.0007, 0.0006, 0.0008,  ..., 0.0009, 0.0022, 0.0021],\n          ...,\n          [0.0007, 0.0007, 0.0006,  ..., 0.0008, 0.0006, 0.0008],\n          [0.0008, 0.0008, 0.0005,  ..., 0.0007, 0.0006, 0.0007],\n          [0.0006, 0.0008, 0.0005,  ..., 0.0007, 0.0008, 0.0007]],\n\n         [[0.0005, 0.0009, 0.0007,  ..., 0.0014, 0.0012, 0.0011],\n          [0.0007, 0.0008, 0.0007,  ..., 0.0012, 0.0013, 0.0018],\n          [0.0007, 0.0006, 0.0008,  ..., 0.0009, 0.0022, 0.0021],\n          ...,\n          [0.0007, 0.0007, 0.0006,  ..., 0.0008, 0.0006, 0.0008],\n          [0.0008, 0.0008, 0.0005,  ..., 0.0007, 0.0006, 0.0007],\n          [0.0006, 0.0008, 0.0005,  ..., 0.0007, 0.0008, 0.0007]],\n\n         [[0.0005, 0.0009, 0.0007,  ..., 0.0013, 0.0012, 0.0010],\n          [0.0007, 0.0008, 0.0007,  ..., 0.0011, 0.0013, 0.0017],\n          [0.0007, 0.0006, 0.0008,  ..., 0.0009, 0.0021, 0.0020],\n          ...,\n          [0.0007, 0.0007, 0.0006,  ..., 0.0008, 0.0006, 0.0008],\n          [0.0008, 0.0008, 0.0005,  ..., 0.0007, 0.0006, 0.0007],\n          [0.0006, 0.0008, 0.0005,  ..., 0.0007, 0.0008, 0.0007]]],\n\n\n        [[[0.0006, 0.0005, 0.0004,  ..., 0.0005, 0.0007, 0.0006],\n          [0.0005, 0.0004, 0.0007,  ..., 0.0008, 0.0005, 0.0006],\n          [0.0002, 0.0004, 0.0003,  ..., 0.0005, 0.0004, 0.0004],\n          ...,\n          [0.0005, 0.0004, 0.0005,  ..., 0.0005, 0.0005, 0.0005],\n          [0.0007, 0.0005, 0.0004,  ..., 0.0005, 0.0004, 0.0003],\n          [0.0004, 0.0003, 0.0007,  ..., 0.0006, 0.0004, 0.0004]],\n\n         [[0.0006, 0.0005, 0.0004,  ..., 0.0005, 0.0007, 0.0006],\n          [0.0005, 0.0004, 0.0007,  ..., 0.0008, 0.0005, 0.0006],\n          [0.0002, 0.0004, 0.0003,  ..., 0.0005, 0.0004, 0.0004],\n          ...,\n          [0.0005, 0.0004, 0.0005,  ..., 0.0005, 0.0005, 0.0005],\n          [0.0007, 0.0005, 0.0004,  ..., 0.0005, 0.0004, 0.0003],\n          [0.0004, 0.0003, 0.0007,  ..., 0.0006, 0.0004, 0.0004]],\n\n         [[0.0006, 0.0005, 0.0004,  ..., 0.0005, 0.0007, 0.0006],\n          [0.0005, 0.0004, 0.0007,  ..., 0.0008, 0.0005, 0.0006],\n          [0.0002, 0.0004, 0.0003,  ..., 0.0005, 0.0004, 0.0004],\n          ...,\n          [0.0005, 0.0004, 0.0005,  ..., 0.0005, 0.0005, 0.0005],\n          [0.0007, 0.0005, 0.0004,  ..., 0.0005, 0.0004, 0.0003],\n          [0.0004, 0.0003, 0.0007,  ..., 0.0006, 0.0004, 0.0004]]]])\n---------------------------------------------------------------------------\nRuntimeError                              Traceback (most recent call last)\nCell In[7], line 96\n     93 print(images.shape)\n     94 print(images)\n---&gt; 96 loss_dict = model(images, targets_list)\n     99 total_loss = sum(loss for loss in loss_dict.values())\n    100 total_loss.backward()\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)\n   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]\n   1517 else:\n-&gt; 1518     return self._call_impl(*args, **kwargs)\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1527, in Module._call_impl(self, *args, **kwargs)\n   1522 # If we don't have any hooks, we want to skip the rest of the logic in\n   1523 # this function, and just call forward.\n   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks\n   1525         or _global_backward_pre_hooks or _global_backward_hooks\n   1526         or _global_forward_hooks or _global_forward_pre_hooks):\n-&gt; 1527     return forward_call(*args, **kwargs)\n   1529 try:\n   1530     result = None\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torchvision\\models\\detection\\ssd.py:378, in SSD.forward(self, images, targets)\n    375 features = list(features.values())\n    377 # compute the ssd heads outputs using the features\n--&gt; 378 head_outputs = self.head(features)\n    380 # create the set of anchors\n    381 anchors = self.anchor_generator(images, features)\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)\n   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]\n   1517 else:\n-&gt; 1518     return self._call_impl(*args, **kwargs)\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1527, in Module._call_impl(self, *args, **kwargs)\n   1522 # If we don't have any hooks, we want to skip the rest of the logic in\n   1523 # this function, and just call forward.\n   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks\n   1525         or _global_backward_pre_hooks or _global_backward_hooks\n   1526         or _global_forward_hooks or _global_forward_pre_hooks):\n-&gt; 1527     return forward_call(*args, **kwargs)\n   1529 try:\n   1530     result = None\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torchvision\\models\\detection\\ssd.py:66, in SSDHead.forward(self, x)\n     64 def forward(self, x: List[Tensor]) -&gt; Dict[str, Tensor]:\n     65     return {\n---&gt; 66         \"bbox_regression\": self.regression_head(x),\n     67         \"cls_logits\": self.classification_head(x),\n     68     }\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)\n   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]\n   1517 else:\n-&gt; 1518     return self._call_impl(*args, **kwargs)\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1527, in Module._call_impl(self, *args, **kwargs)\n   1522 # If we don't have any hooks, we want to skip the rest of the logic in\n   1523 # this function, and just call forward.\n   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks\n   1525         or _global_backward_pre_hooks or _global_backward_hooks\n   1526         or _global_forward_hooks or _global_forward_pre_hooks):\n-&gt; 1527     return forward_call(*args, **kwargs)\n   1529 try:\n   1530     result = None\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torchvision\\models\\detection\\ssd.py:95, in SSDScoringHead.forward(self, x)\n     92 all_results = []\n     94 for i, features in enumerate(x):\n---&gt; 95     results = self._get_result_from_module_list(features, i)\n     97     # Permute output from (N, A * K, H, W) to (N, HWA, K).\n     98     N, _, H, W = results.shape\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torchvision\\models\\detection\\ssd.py:88, in SSDScoringHead._get_result_from_module_list(self, x, idx)\n     86 for i, module in enumerate(self.module_list):\n     87     if i == idx:\n---&gt; 88         out = module(x)\n     89 return out\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1518, in Module._wrapped_call_impl(self, *args, **kwargs)\n   1516     return self._compiled_call_impl(*args, **kwargs)  # type: ignore[misc]\n   1517 else:\n-&gt; 1518     return self._call_impl(*args, **kwargs)\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\module.py:1527, in Module._call_impl(self, *args, **kwargs)\n   1522 # If we don't have any hooks, we want to skip the rest of the logic in\n   1523 # this function, and just call forward.\n   1524 if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks or self._forward_pre_hooks\n   1525         or _global_backward_pre_hooks or _global_backward_hooks\n   1526         or _global_forward_hooks or _global_forward_pre_hooks):\n-&gt; 1527     return forward_call(*args, **kwargs)\n   1529 try:\n   1530     result = None\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\conv.py:460, in Conv2d.forward(self, input)\n    459 def forward(self, input: Tensor) -&gt; Tensor:\n--&gt; 460     return self._conv_forward(input, self.weight, self.bias)\n\nFile ~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python39\\site-packages\\torch\\nn\\modules\\conv.py:456, in Conv2d._conv_forward(self, input, weight, bias)\n    452 if self.padding_mode != 'zeros':\n    453     return F.conv2d(F.pad(input, self._reversed_padding_repeated_twice, mode=self.padding_mode),\n    454                     weight, bias, self.stride,\n    455                     _pair(0), self.dilation, self.groups)\n--&gt; 456 return F.conv2d(input, weight, bias, self.stride,\n    457                 self.padding, self.dilation, self.groups)\n\nRuntimeError: Expected 3D (unbatched) or 4D (batched) input to conv2d, but got input of size: [2, 12]\n</code></pre>\n<p>I know that there are a lot of things and that it does not look good, but i’m a very beginner and I want to learn, so thank you very much for your help on this.</p>",512          "post_number": 1,513          "post_type": 1,514          "posts_count": 1,515          "updated_at": "2023-12-17T14:18:34.330Z",516          "reply_count": 0,517          "reply_to_post_number": null,518          "quote_count": 0,519          "incoming_link_count": 263,520          "reads": 5,521          "readers_count": 4,522          "score": 1316.0,523          "yours": false,524          "topic_id": 193874,525          "topic_slug": "runtimeerror-expected-3d-unbatched-or-4d-batched-input-to-conv2d-but-got-input-of-size-2-12",526          "display_username": "pet shor",527          "primary_group_name": null,528          "flair_name": null,529          "flair_url": null,530          "flair_bg_color": null,531          "flair_color": null,532          "flair_group_id": null,533          "badges_granted": [],534          "version": 1,535          "can_edit": false,536          "can_delete": false,537          "can_recover": false,538          "can_see_hidden_post": false,539          "can_wiki": false,540          "read": true,541          "user_title": null,542          "bookmarked": false,543          "actions_summary": [],544          "moderator": false,545          "admin": false,546          "staff": false,547          "user_id": 71797,548          "hidden": false,549          "trust_level": 0,550          "deleted_at": null,551          "user_deleted": false,552          "edit_reason": null,553          "can_view_edit_history": true,554          "wiki": false,555          "post_url": "/t/runtimeerror-expected-3d-unbatched-or-4d-batched-input-to-conv2d-but-got-input-of-size-2-12/193874/1",556          "can_accept_answer": false,557          "can_unaccept_answer": false,558          "accepted_answer": false,559          "topic_accepted_answer": null,560          "can_vote": false561        }562      ],563      "stream": [564        427465565      ]566    },567    "timeline_lookup": [568      [569        1,570        678571      ]572    ],573    "suggested_topics": [574      {575        "fancy_title": "Semantic Segmentation with Attention based CycleGAN",576        "id": 217647,577        "title": "Semantic Segmentation with Attention based CycleGAN",578        "slug": "semantic-segmentation-with-attention-based-cyclegan",579        "posts_count": 5,580        "reply_count": 1,581        "highest_post_number": 5,582        "image_url": null,583        "created_at": "2025-03-10T06:44:59.887Z",584        "last_posted_at": "2025-03-11T22:57:33.781Z",585        "bumped": true,586        "bumped_at": "2025-03-11T22:57:33.781Z",587        "archetype": "regular",588        "unseen": false,589        "pinned": false,590        "unpinned": null,591        "visible": true,592        "closed": false,593        "archived": false,594        "bookmarked": null,595        "liked": null,596        "tags_descriptions": {},597        "like_count": 0,598        "views": 133,599        "category_id": 5,600        "featured_link": null,601        "has_accepted_answer": false,602        "posters": [603          {604            "extras": null,605            "description": "Original Poster",606            "user": {607              "id": 81422,608              "username": "Idrees11",609              "name": "Idrees Bhat",610              "avatar_template": "/user_avatar/discuss.pytorch.org/idrees11/{size}/74448_2.png",611              "trust_level": 1612            }613          },614          {615            "extras": "latest",616            "description": "Most Recent Poster",617            "user": {618              "id": 18088,619              "username": "KFrank",620              "name": "K. Frank",621              "avatar_template": "/letter_avatar_proxy/v4/letter/k/ecb155/{size}.png",622              "trust_level": 2623            }624          }625        ]626      },627      {628        "fancy_title": "Data not balanced",629        "id": 214375,630        "title": "Data not balanced",631        "slug": "data-not-balanced",632        "posts_count": 6,633        "reply_count": 3,634        "highest_post_number": 6,635        "image_url": "https://discuss.pytorch.org/uploads/default/optimized/3X/d/6/d657e80bcc250c583e5f136f133a110e250f7f2c_2_1024x526.png",636        "created_at": "2024-12-18T22:54:17.331Z",637        "last_posted_at": "2024-12-19T09:57:08.773Z",638        "bumped": true,639        "bumped_at": "2024-12-19T09:57:08.773Z",640        "archetype": "regular",641        "unseen": false,642        "pinned": false,643        "unpinned": null,644        "visible": true,645        "closed": false,646        "archived": false,647        "bookmarked": null,648        "liked": null,649        "tags_descriptions": {},650        "like_count": 2,651        "views": 312,652        "category_id": 5,653        "featured_link": null,654        "has_accepted_answer": false,655        "posters": [656          {657            "extras": "latest",658            "description": "Original Poster, Most Recent Poster",659            "user": {660              "id": 46221,661              "username": "mathwseg",662              "name": "mathwseg",663              "avatar_template": "/user_avatar/discuss.pytorch.org/mathwseg/{size}/39221_2.png",664              "trust_level": 1665            }666          },667          {668            "extras": null,669            "description": "Frequent Poster",670            "user": {671              "id": 41396,672              "username": "soulitzer",673              "name": "",674              "avatar_template": "/letter_avatar_proxy/v4/letter/s/839c29/{size}.png",675              "trust_level": 2676            }677          },678          {679            "extras": null,680            "description": "Frequent Poster",681            "user": {682              "id": 41458,683              "username": "J_Johnson",684              "name": "J Johnson",685              "avatar_template": "/user_avatar/discuss.pytorch.org/j_johnson/{size}/55494_2.png",686              "trust_level": 2687            }688          }689        ]690      },691      {692        "fancy_title": "Significantly Different Results Using cuDNN",693        "id": 214089,694        "title": "Significantly Different Results Using cuDNN",695        "slug": "significantly-different-results-using-cudnn",696        "posts_count": 7,697        "reply_count": 4,698        "highest_post_number": 7,699        "image_url": null,700        "created_at": "2024-12-11T09:09:33.628Z",701        "last_posted_at": "2025-01-16T21:57:08.119Z",702        "bumped": true,703        "bumped_at": "2025-01-16T21:57:08.119Z",704        "archetype": "regular",705        "unseen": false,706        "pinned": false,707        "unpinned": null,708        "visible": true,709        "closed": false,710        "archived": false,711        "bookmarked": null,712        "liked": null,713        "tags_descriptions": {},714        "like_count": 3,715        "views": 213,716        "category_id": 5,717        "featured_link": null,718        "has_accepted_answer": false,719        "posters": [720          {721            "extras": null,722            "description": "Original Poster",723            "user": {724              "id": 81445,725              "username": "al21",726              "name": "",727              "avatar_template": "/letter_avatar_proxy/v4/letter/a/90db22/{size}.png",728              "trust_level": 0729            }730          },731          {732            "extras": "latest",733            "description": "Most Recent Poster",734            "user": {735              "id": 1,736              "username": "smth",737              "name": "",738              "avatar_template": "/user_avatar/discuss.pytorch.org/smth/{size}/13_2.png",739              "admin": true,740              "moderator": true,741              "trust_level": 2742            }743          }744        ]745      },746      {747        "fancy_title": "Image classification with PyTorch",748        "id": 213930,749        "title": "Image classification with PyTorch",750        "slug": "image-classification-with-pytorch",751        "posts_count": 3,752        "reply_count": 0,753        "highest_post_number": 3,754        "image_url": "https://discuss.pytorch.org/uploads/default/optimized/3X/1/3/1381695a6060aefe405ffb28aebaae5a42069aa6_2_1024x635.jpeg",755        "created_at": "2024-12-06T22:46:10.375Z",756        "last_posted_at": "2024-12-09T16:57:34.885Z",757        "bumped": true,758        "bumped_at": "2024-12-09T16:57:34.885Z",759        "archetype": "regular",760        "unseen": false,761        "pinned": false,762        "unpinned": null,763        "visible": true,764        "closed": false,765        "archived": false,766        "bookmarked": null,767        "liked": null,768        "tags_descriptions": {},769        "like_count": 0,770        "views": 291,771        "category_id": 5,772        "featured_link": null,773        "has_accepted_answer": false,774        "posters": [775          {776            "extras": null,777            "description": "Original Poster",778            "user": {779              "id": 81369,780              "username": "Arek",781              "name": "Arek",782              "avatar_template": "/letter_avatar_proxy/v4/letter/a/46a35a/{size}.png",783              "trust_level": 0784            }785          },786          {787            "extras": null,788            "description": "Frequent Poster",789            "user": {790              "id": 3534,791              "username": "ptrblck",792              "name": "",793              "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",794              "admin": true,795              "moderator": true,796              "trust_level": 2797            }798          },799          {800            "extras": "latest",801            "description": "Most Recent Poster",802            "user": {803              "id": 64498,804              "username": "nickums",805              "name": "Nickums",806              "avatar_template": "/user_avatar/discuss.pytorch.org/nickums/{size}/58652_2.png",807              "trust_level": 1808            }809          }810        ]811      },812      {813        "fancy_title": "Finnetuning problems on googlenet architecture",814        "id": 218083,815        "title": "Finnetuning problems on googlenet architecture",816        "slug": "finnetuning-problems-on-googlenet-architecture",817        "posts_count": 2,818        "reply_count": 0,819        "highest_post_number": 2,820        "image_url": null,821        "created_at": "2025-03-20T17:21:53.117Z",822        "last_posted_at": "2025-03-21T19:04:52.661Z",823        "bumped": true,824        "bumped_at": "2025-03-21T19:04:52.661Z",825        "archetype": "regular",826        "unseen": false,827        "pinned": false,828        "unpinned": null,829        "visible": true,830        "closed": false,831        "archived": false,832        "bookmarked": null,833        "liked": null,834        "tags_descriptions": {},835        "like_count": 0,836        "views": 40,837        "category_id": 5,838        "featured_link": null,839        "has_accepted_answer": false,840        "posters": [841          {842            "extras": null,843            "description": "Original Poster",844            "user": {845              "id": 83388,846              "username": "Gabriel_Duran",847              "name": "Gabriel Duran",848              "avatar_template": "/user_avatar/discuss.pytorch.org/gabriel_duran/{size}/76266_2.png",849              "trust_level": 1850            }851          },852          {853            "extras": "latest",854            "description": "Most Recent Poster",855            "user": {856              "id": 3534,857              "username": "ptrblck",858              "name": "",859              "avatar_template": "/user_avatar/discuss.pytorch.org/ptrblck/{size}/1823_2.png",860              "admin": true,861              "moderator": true,862              "trust_level": 2863            }864          }865        ]866      }867    ],868    "tags_descriptions": {},869    "fancy_title": "RuntimeError: Expected 3D (unbatched) or 4D (batched) input to conv2d, but got input of size: [2, 12]",870    "id": 193874,871    "title": "RuntimeError: Expected 3D (unbatched) or 4D (batched) input to conv2d, but got input of size: [2, 12]",872    "posts_count": 1,873    "created_at": "2023-12-17T14:18:34.176Z",874    "views": 695,875    "reply_count": 0,876    "like_count": 0,877    "last_posted_at": "2023-12-17T14:18:34.330Z",878    "visible": true,879    "closed": false,880    "archived": false,881    "has_summary": false,882    "archetype": "regular",883    "slug": "runtimeerror-expected-3d-unbatched-or-4d-batched-input-to-conv2d-but-got-input-of-size-2-12",884    "category_id": 5,885    "word_count": 3968,886    "deleted_at": null,887    "user_id": 71797,888    "featured_link": null,889    "pinned_globally": false,890    "pinned_at": null,891    "pinned_until": null,892    "image_url": null,893    "slow_mode_seconds": 0,894    "draft": null,895    "draft_key": "topic_193874",896    "draft_sequence": null,897    "unpinned": null,898    "pinned": false,899    "current_post_number": 1,900    "highest_post_number": 1,901    "deleted_by": null,902    "actions_summary": [903      {904        "id": 4,905        "count": 0,906        "hidden": false,907        "can_act": false908      },909      {910        "id": 8,911        "count": 0,912        "hidden": false,913        "can_act": false914      },915      {916        "id": 10,917        "count": 0,918        "hidden": false,919        "can_act": false920      },921      {922        "id": 7,923        "count": 0,924        "hidden": false,925        "can_act": false926      }927    ],928    "chunk_size": 20,929    "bookmarked": false,930    "topic_timer": null,931    "message_bus_last_id": 0,932    "participant_count": 1,933    "show_read_indicator": false,934    "thumbnails": null,935    "slow_mode_enabled_until": null,936    "can_vote": false,937    "vote_count": 0,938    "user_voted": false,939    "discourse_zendesk_plugin_zendesk_id": null,940    "discourse_zendesk_plugin_zendesk_url": "https://your-url.zendesk.com/agent/tickets/",941    "details": {942      "can_edit": false,943      "notification_level": 1,944      "participants": [945        {946          "id": 71797,947          "username": "pet_shor",948          "name": "pet shor",949          "avatar_template": "/user_avatar/discuss.pytorch.org/pet_shor/{size}/66322_2.png",950          "post_count": 1,951          "primary_group_name": null,952          "flair_name": null,953          "flair_url": null,954          "flair_color": null,955          "flair_bg_color": null,956          "flair_group_id": null,957          "trust_level": 0958        }959      ],960      "created_by": {961        "id": 71797,962        "username": "pet_shor",963        "name": "pet shor",964        "avatar_template": "/user_avatar/discuss.pytorch.org/pet_shor/{size}/66322_2.png"965      },966      "last_poster": {967        "id": 71797,968        "username": "pet_shor",969        "name": "pet shor",970        "avatar_template": "/user_avatar/discuss.pytorch.org/pet_shor/{size}/66322_2.png"971      }972    },973    "bookmarks": []974  },975  {976    "post_stream": {977      "posts": [978        {979          "id": 409405,980          "name": "Joshua Kwon",981          "username": "kwijibohan",982          "avatar_template": "/user_avatar/discuss.pytorch.org/kwijibohan/{size}/55990_2.png",983          "created_at": "2023-07-11T21:29:37.752Z",984          "cooked": "<p>Torch version <code>2.1.0.dev20230702+cu121</code></p>\n<pre><code class=\"lang-python\">import torch\nfrom torch.utils import data\n\ntorch.set_default_device('cuda')\n\nclass NullDataset(data.Dataset):\n    def __len__(self) -&gt; int:\n        return 100\n\ndataloader = data.DataLoader(NullDataset(), batch_size=64, shuffle=True, generator=torch.Generator(device='cuda'))\n\nfor data in dataloader:\n    print(data)\n</code></pre>\n<p>gives errors at <code>for data in dataloader:</code> with</p>\n<pre><code class=\"lang-auto\">Traceback (most recent call last):\n  File \"&lt;stdin&gt;\", line 1, in &lt;module&gt;\n  File \"blabla\\venv\\Lib\\site-packages\\torch\\utils\\data\\dataloader.py\", line 633, in __next__\n    data = self._next_data()\n           ^^^^^^^^^^^^^^^^^\n  File \"blabla\\venv\\Lib\\site-packages\\torch\\utils\\data\\dataloader.py\", line 676, in _next_data\n    index = self._next_index()  # may raise StopIteration\n            ^^^^^^^^^^^^^^^^^^\n  File \"blabla\\venv\\Lib\\site-packages\\torch\\utils\\data\\dataloader.py\", line 623, in _next_index\n    return next(self._sampler_iter)  # may raise StopIteration\n           ^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"blabla\\venv\\Lib\\site-packages\\torch\\utils\\data\\sampler.py\", line 289, in __iter__\n    for idx in self.sampler:\n  File \"blabla\\venv\\Lib\\site-packages\\torch\\utils\\data\\sampler.py\", line 167, in __iter__\n    yield from map(int, torch.randperm(n, generator=generator).numpy())\n                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n  File \"blabla\\venv\\Lib\\site-packages\\torch\\utils\\_device.py\", line 76, in __torch_function__\n    return func(*args, **kwargs)\n           ^^^^^^^^^^^^^^^^^^^^^\nTypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.\n</code></pre>\n<p>I deliberately omitted the definition of <code>__getitem__</code> for <code>NullDataSet</code> to show that it isn’t the cause of the error. How should I fix this? This error seems to be introduced by commit <code>Do not materialize entire randperm in RandomSampler (#103339)</code>, calling <code>.numpy()</code> on a cuda tensor. Previously there was <code>torch.randperm(n, generator=generator).tolist()</code> instead of <code>map(int, torch.randperm(n, generator=generator).numpy())</code></p>",985          "post_number": 1,986          "post_type": 1,987          "posts_count": 2,988          "updated_at": "2023-07-11T21:38:21.951Z",989          "reply_count": 0,990          "reply_to_post_number": null,991          "quote_count": 0,992          "incoming_link_count": 107,993          "reads": 12,994          "readers_count": 11,995          "score": 567.4,996          "yours": false,997          "topic_id": 183993,998          "topic_slug": "device-error-with-dataloaders",999          "display_username": "Joshua Kwon",1000          "primary_group_name": null,1001          "flair_name": null,1002          "flair_url": null,1003          "flair_bg_color": null,1004          "flair_color": null,1005          "flair_group_id": null,1006          "badges_granted": [],1007          "version": 2,1008          "can_edit": false,1009          "can_delete": false,1010          "can_recover": false,1011          "can_see_hidden_post": false,1012          "can_wiki": false,1013          "read": true,1014          "user_title": null,1015          "bookmarked": false,1016          "actions_summary": [1017            {1018              "id": 2,1019              "count": 21020            }1021          ],1022          "moderator": false,1023          "admin": false,1024          "staff": false,1025          "user_id": 62085,1026          "hidden": false,1027          "trust_level": 1,1028          "deleted_at": null,1029          "user_deleted": false,1030          "edit_reason": null,1031          "can_view_edit_history": true,1032          "wiki": false,1033          "post_url": "/t/device-error-with-dataloaders/183993/1",1034          "can_accept_answer": false,1035          "can_unaccept_answer": false,1036          "accepted_answer": false,1037          "topic_accepted_answer": null,1038          "can_vote": false1039        },1040        {1041          "id": 427459,1042          "name": "",1043          "username": "Krayaty",1044          "avatar_template": "/letter_avatar_proxy/v4/letter/k/57b2e6/{size}.png",1045          "created_at": "2023-12-17T13:24:26.168Z",1046          "cooked": "<p>Hi Joshua,</p>\n<p>I got the same Error with my setup last week. I’m using conda and I had the latest CUDA driver installed for my RTX 3090. I had Pytorch in some Version of 2.1 installed. I can’t recall the exact Versions for CUDA driver and Pytorch. But I’m absolutely sure that I didn’t have the latest Pytorch Version.<br>\nI tracked the problem down to the same thing you suggest. At first I didn’t know how to fix it with coding so I just updated Pytorch to the latest stable version  2.1.2 and voila it was running again! I don’t know why and I can not reproduce it.<br>\nLater on I got the problem again when running my project on a slurm cluster with the latest stable Image from <a href=\"https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch\" class=\"inline-onebox\" rel=\"noopener nofollow ugc\">PyTorch | NVIDIA NGC</a>. So I went on searching for a proper solution. In the end I just used a custom sampler for my dataloader. This fixed the problem for me.</p>",1047          "post_number": 2,1048          "post_type": 1,1049          "posts_count": 2,1050          "updated_at": "2023-12-17T13:24:26.168Z",1051          "reply_count": 0,1052          "reply_to_post_number": null,1053          "quote_count": 0,1054          "incoming_link_count": 0,1055          "reads": 6,1056          "readers_count": 5,1057          "score": 1.2,1058          "yours": false,1059          "topic_id": 183993,1060          "topic_slug": "device-error-with-dataloaders",1061          "display_username": "",1062          "primary_group_name": null,1063          "flair_name": null,1064          "flair_url": null,1065          "flair_bg_color": null,1066          "flair_color": null,1067          "flair_group_id": null,1068          "badges_granted": [],1069          "version": 1,1070          "can_edit": false,1071          "can_delete": false,1072          "can_recover": false,1073          "can_see_hidden_post": false,1074          "can_wiki": false,1075          "link_counts": [1076            {1077              "url": "https://catalog.ngc.nvidia.com/orgs/nvidia/containers/pytorch",1078              "internal": false,1079              "reflection": false,1080              "title": "PyTorch | NVIDIA NGC",1081              "clicks": 11082            }1083          ],1084          "read": true,1085          "user_title": null,1086          "bookmarked": false,1087          "actions_summary": [],1088          "moderator": false,1089          "admin": false,1090          "staff": false,1091          "user_id": 71782,1092          "hidden": false,1093          "trust_level": 1,1094          "deleted_at": null,1095          "user_deleted": false,1096          "edit_reason": null,1097          "can_view_edit_history": true,1098          "wiki": false,1099          "post_url": "/t/device-error-with-dataloaders/183993/2",1100          "can_accept_answer": false,1101          "can_unaccept_answer": false,1102          "accepted_answer": false,1103          "topic_accepted_answer": null1104        }1105      ],1106      "stream": [1107        409405,1108        4274591109      ]1110    },1111    "timeline_lookup": [1112      [1113        1,1114        8371115      ],1116      [1117        2,1118        6781119      ]1120    ],1121    "suggested_topics": [1122      {1123        "fancy_title": ".item() blocks cpu thread until D2H operations in offload stream finish",1124        "id": 218855,1125        "title": ".item() blocks cpu thread until D2H operations in offload stream finish",1126        "slug": "item-blocks-cpu-thread-until-d2h-operations-in-offload-stream-finish",1127        "posts_count": 1,1128        "reply_count": 0,1129        "highest_post_number": 1,1130        "image_url": "https://discuss.pytorch.org/uploads/default/optimized/3X/9/6/96c3048070329d6d38775dbb7b6e623ec88390eb_2_1024x573.png",1131        "created_at": "2025-04-08T04:49:47.444Z",1132        "last_posted_at": "2025-04-08T04:49:47.486Z",1133        "bumped": true,1134        "bumped_at": "2025-04-08T05:17:28.094Z",1135        "archetype": "regular",1136        "unseen": false,1137        "pinned": false,1138        "unpinned": null,1139        "visible": true,1140        "closed": false,1141        "archived": false,1142        "bookmarked": null,1143        "liked": null,1144        "tags_descriptions": {},1145        "like_count": 0,1146        "views": 21,1147        "category_id": 1,1148        "featured_link": null,1149        "has_accepted_answer": false,1150        "posters": [1151          {1152            "extras": "latest single",1153            "description": "Original Poster, Most Recent Poster",1154            "user": {1155              "id": 83695,1156              "username": "zhr2001",1157              "name": "Zhr2001",1158              "avatar_template": "/user_avatar/discuss.pytorch.org/zhr2001/{size}/76533_2.png",1159              "trust_level": 11160            }1161          }1162        ]1163      },1164      {1165        "fancy_title": "Pytorch cuda missing",1166        "id": 214925,1167        "title": "Pytorch cuda missing",1168        "slug": "pytorch-cuda-missing",1169        "posts_count": 2,1170        "reply_count": 0,1171        "highest_post_number": 2,1172        "image_url": null,1173        "created_at": "2025-01-03T09:51:58.343Z",1174        "last_posted_at": "2025-01-03T14:18:18.911Z",1175        "bumped": true,1176        "bumped_at": "2025-01-03T14:18:18.911Z",1177        "archetype": "regular",1178        "unseen": false,1179        "pinned": false,1180        "unpinned": null,1181        "visible": true,1182        "closed": false,1183        "archived": false,1184        "bookmarked": null,1185        "liked": null,1186        "tags_descriptions": {},1187        "like_count": 0,1188        "views": 188,1189        "category_id": 1,1190        "featured_link": null,1191        "has_accepted_answer": false,1192        "posters": [1193          {1194            "extras": null,1195            "description": "Original Poster",1196            "user": {1197              "id": 81852,1198              "username": "sarathi",1199              "name": "",1200              "avatar_template": "/letter_avatar_proxy/v4/letter/s/c67d28/{size}.png",

Showing the first 1,200 of 61735 lines. Download the file for the rest.