{
  "id": 335433,
  "title": "How to use this notebook?",
  "url": "/competitions/hubmap-organ-segmentation/discussion/335433",
  "author_name": "DudiFrid",
  "post_date": "2022-07-06T05:48:13.149000",
  "votes": 2,
  "comment_count": 0,
  "views": 0,
  "content": "<p>I came across <a href=\"https://www.kaggle.com/code/abebe9849/swin-v2-unet-upernet\" target=\"_blank\">this</a> notebook. It runs in about a minute and uses SWIN-V2 model, so it seems pretty cool.<br>\nThe problem is that I don't understand how to use it…<br>\nIn the last few cells, it infers on <strong>random</strong> tensors. I guess it should be replaced with images from the competition, but he wrote at the beginning of the notebook that he got some problem with different sizes other than 256x256. So, what should I do? Could you show me please how to use it?</p>\n<p><strong>Edit:</strong><br>\nFor example, I tried the following instead of (or, in addition to) the last cell:</p>\n<pre><code>URL = \"https://raw.githubusercontent.com/SharanSMenon/swin-transformer-hub/main/imagenet_labels.json\" # Imagenet labels\n!wget https://www.allaboutbirds.org/guide/assets/photo/306327661-480px.jpg -O house_finch.jpg\nfrom PIL import Image\nfrom torchvision import transforms\nimage = Image.open(\"house_finch.jpg\")\nprint(type(image))\ntransform = transforms.Compose([transforms.PILToTensor()])\ntensor = transform(image)\ns = time.time()\nS = 256\ninp = torch.randn((4,3,S,S))\n# print(inp)\nmodel = UperNet_swin(img_size=S,size=\"swinv2_small_window16_256\")\n\nout = model(tensor)\n\n# print(out.shape,time.time()-s)\nprint(out)\ndel model,out\n</code></pre>",
  "messages": [
    {
      "id": 1845172,
      "postDate": "2022-07-06T05:48:13.150Z",
      "content": "<p>I came across <a href=\"https://www.kaggle.com/code/abebe9849/swin-v2-unet-upernet\" target=\"_blank\">this</a> notebook. It runs in about a minute and uses SWIN-V2 model, so it seems pretty cool.<br>\nThe problem is that I don't understand how to use it…<br>\nIn the last few cells, it infers on <strong>random</strong> tensors. I guess it should be replaced with images from the competition, but he wrote at the beginning of the notebook that he got some problem with different sizes other than 256x256. So, what should I do? Could you show me please how to use it?</p>\n<p><strong>Edit:</strong><br>\nFor example, I tried the following instead of (or, in addition to) the last cell:</p>\n<pre><code>URL = \"https://raw.githubusercontent.com/SharanSMenon/swin-transformer-hub/main/imagenet_labels.json\" # Imagenet labels\n!wget https://www.allaboutbirds.org/guide/assets/photo/306327661-480px.jpg -O house_finch.jpg\nfrom PIL import Image\nfrom torchvision import transforms\nimage = Image.open(\"house_finch.jpg\")\nprint(type(image))\ntransform = transforms.Compose([transforms.PILToTensor()])\ntensor = transform(image)\ns = time.time()\nS = 256\ninp = torch.randn((4,3,S,S))\n# print(inp)\nmodel = UperNet_swin(img_size=S,size=\"swinv2_small_window16_256\")\n\nout = model(tensor)\n\n# print(out.shape,time.time()-s)\nprint(out)\ndel model,out\n</code></pre>",
      "rawMarkdown": "I came across [this](https://www.kaggle.com/code/abebe9849/swin-v2-unet-upernet) notebook. It runs in about a minute and uses SWIN-V2 model, so it seems pretty cool.\nThe problem is that I don't understand how to use it...\nIn the last few cells, it infers on **random** tensors. I guess it should be replaced with images from the competition, but he wrote at the beginning of the notebook that he got some problem with different sizes other than 256x256. So, what should I do? Could you show me please how to use it?\n\n**Edit:**\nFor example, I tried the following instead of (or, in addition to) the last cell:\n```\nURL = \"https://raw.githubusercontent.com/SharanSMenon/swin-transformer-hub/main/imagenet_labels.json\" # Imagenet labels\n!wget https://www.allaboutbirds.org/guide/assets/photo/306327661-480px.jpg -O house_finch.jpg\nfrom PIL import Image\nfrom torchvision import transforms\nimage = Image.open(\"house_finch.jpg\")\nprint(type(image))\ntransform = transforms.Compose([transforms.PILToTensor()])\ntensor = transform(image)\ns = time.time()\nS = 256\ninp = torch.randn((4,3,S,S))\n# print(inp)\nmodel = UperNet_swin(img_size=S,size=\"swinv2_small_window16_256\")\n\nout = model(tensor)\n\n# print(out.shape,time.time()-s)\nprint(out)\ndel model,out\n```",
      "votes": 2
    }
  ],
  "comments": [],
  "raw_markdown_by_id": {
    "1845172": "I came across [this](https://www.kaggle.com/code/abebe9849/swin-v2-unet-upernet) notebook. It runs in about a minute and uses SWIN-V2 model, so it seems pretty cool.\nThe problem is that I don't understand how to use it...\nIn the last few cells, it infers on **random** tensors. I guess it should be replaced with images from the competition, but he wrote at the beginning of the notebook that he got some problem with different sizes other than 256x256. So, what should I do? Could you show me please how to use it?\n\n**Edit:**\nFor example, I tried the following instead of (or, in addition to) the last cell:\n```\nURL = \"https://raw.githubusercontent.com/SharanSMenon/swin-transformer-hub/main/imagenet_labels.json\" # Imagenet labels\n!wget https://www.allaboutbirds.org/guide/assets/photo/306327661-480px.jpg -O house_finch.jpg\nfrom PIL import Image\nfrom torchvision import transforms\nimage = Image.open(\"house_finch.jpg\")\nprint(type(image))\ntransform = transforms.Compose([transforms.PILToTensor()])\ntensor = transform(image)\ns = time.time()\nS = 256\ninp = torch.randn((4,3,S,S))\n# print(inp)\nmodel = UperNet_swin(img_size=S,size=\"swinv2_small_window16_256\")\n\nout = model(tensor)\n\n# print(out.shape,time.time()-s)\nprint(out)\ndel model,out\n```"
  }
}