{
  "id": 414918,
  "title": "It was written by my submission code is there a problem?",
  "url": "/competitions/image-matching-challenge-2023/discussion/414918",
  "author_name": "",
  "post_date": "2023-06-04T04:18:30.997530Z",
  "votes": null,
  "comment_count": 2,
  "views": 0,
  "content": "<p>Why did my code submit a 0.001 score and run in 3 minutes<br>\nIt was written by my submission  is there a problem?</p>\n<p>`import gc</p>\n<p>gc.collect()<br>\ndatasets = []</p>\n<p>for dataset in data_dict:<br>\n    datasets.append(dataset)</p>\n<p>for dataset in datasets:<br>\n    print(dataset)<br>\n    if dataset not in out_results:<br>\n        out_results[dataset] = {}<br>\n    for scene in data_dict[dataset]:<br>\n        print(scene)<br>\n        # Fail gently if the notebook has not been submitted and the test data is not populated.<br>\n        # You may want to run this on the training data in that case?<br>\n        img_dir = f'{src}/test/{dataset}/{scene}/images'<br>\n        if not os.path.exists(img_dir):<br>\n            continue<br>\n        # Wrap the meaty part in a try-except block.<br>\n        try:<br>\n            out_results[dataset][scene] = {}<br>\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]<br>\n            print (f\"Got {len(img_fnames)} images\")<br>\n            n = 16<br>\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]<br>\n            if len(new_fnames[-1]) &lt; n:<br>\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]<br>\n            M_world = []<br>\n            for index,item in enumerate(new_fnames):</p>\n<pre><code>            img_tensor,camera = (item)\n            model = ()\n            checkpoint = torch()\n            model(checkpoint)\n            model()\n            heatmap_pred,desc_pred, = (img_tensor)\n            temp = (heatmap_pred, desc_pred,,camera)\n            M_world =M_world + temp\n         index,name  (data_dict):\n            key1 = f\n            out_results = {}\n            out_results = M_world\n            out_results = M_world\n        (f)\n        (f)\n        (out_results, data_dict)\n        ()\n        gc()\n    except:\n        pass\n</code></pre>\n<p><code>\n</code>create_submission(out_results, data_dict)`</p>",
  "messages": [
    {
      "id": "2287026",
      "postDate": "06/04/2023 04:18:30",
      "content": "<p>Why did my code submit a 0.001 score and run in 3 minutes<br>\nIt was written by my submission  is there a problem?</p>\n<p>`import gc</p>\n<p>gc.collect()<br>\ndatasets = []</p>\n<p>for dataset in data_dict:<br>\n    datasets.append(dataset)</p>\n<p>for dataset in datasets:<br>\n    print(dataset)<br>\n    if dataset not in out_results:<br>\n        out_results[dataset] = {}<br>\n    for scene in data_dict[dataset]:<br>\n        print(scene)<br>\n        # Fail gently if the notebook has not been submitted and the test data is not populated.<br>\n        # You may want to run this on the training data in that case?<br>\n        img_dir = f'{src}/test/{dataset}/{scene}/images'<br>\n        if not os.path.exists(img_dir):<br>\n            continue<br>\n        # Wrap the meaty part in a try-except block.<br>\n        try:<br>\n            out_results[dataset][scene] = {}<br>\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]<br>\n            print (f\"Got {len(img_fnames)} images\")<br>\n            n = 16<br>\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]<br>\n            if len(new_fnames[-1]) &lt; n:<br>\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]<br>\n            M_world = []<br>\n            for index,item in enumerate(new_fnames):</p>\n<pre><code>            img_tensor,camera = (item)\n            model = ()\n            checkpoint = torch()\n            model(checkpoint)\n            model()\n            heatmap_pred,desc_pred, = (img_tensor)\n            temp = (heatmap_pred, desc_pred,,camera)\n            M_world =M_world + temp\n         index,name  (data_dict):\n            key1 = f\n            out_results = {}\n            out_results = M_world\n            out_results = M_world\n        (f)\n        (f)\n        (out_results, data_dict)\n        ()\n        gc()\n    except:\n        pass\n</code></pre>\n<p><code>\n</code>create_submission(out_results, data_dict)`</p>",
      "rawMarkdown": "Why did my code submit a 0.001 score and run in 3 minutes\nIt was written by my submission  is there a problem?\n\n`import gc\n\n\n\ngc.collect()\ndatasets = []\n\n\nfor dataset in data_dict:\n    datasets.append(dataset)\n\nfor dataset in datasets:\n    print(dataset)\n    if dataset not in out_results:\n        out_results[dataset] = {}\n    for scene in data_dict[dataset]:\n        print(scene)\n        # Fail gently if the notebook has not been submitted and the test data is not populated.\n        # You may want to run this on the training data in that case?\n        img_dir = f'{src}/test/{dataset}/{scene}/images'\n        if not os.path.exists(img_dir):\n            continue\n        # Wrap the meaty part in a try-except block.\n        try:\n            out_results[dataset][scene] = {}\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]\n            print (f\"Got {len(img_fnames)} images\")\n            n = 16\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]\n            if len(new_fnames[-1]) < n:\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]\n            M_world = []\n            for index,item in enumerate(new_fnames):\n\n\n                img_tensor,camera = collate_img(item)\n                model = make_model()\n                checkpoint = torch.load(\"/kaggle/input/params/params.pth\")\n                model.load_state_dict(checkpoint)\n                model.eval()\n                heatmap_pred,desc_pred,img = model(img_tensor)\n                temp = compute(heatmap_pred, desc_pred,img,camera)\n                M_world =M_world + temp\n            for index,name in enumerate(data_dict[dataset][scene]):\n                key1 = f'{name}'\n                out_results[dataset][scene][key1] = {}\n                out_results[dataset][scene][key1][\"R\"] = M_world[index][0]\n                out_results[dataset][scene][key1][\"t\"] = M_world[index][1]\n            print(f'Registered: {dataset} / {scene} -> {len(out_results[dataset][scene])} images')\n            print(f'Total: {dataset} / {scene} -> {len(data_dict[dataset][scene])} images')\n            create_submission(out_results, data_dict)\n            print(\"create_submission成功\")\n            gc.collect()\n        except:\n            pass\n            \n`\n`create_submission(out_results, data_dict)`",
      "votes": null
    },
    {
      "id": "2287036",
      "postDate": "06/04/2023 04:53:56",
      "content": "<p>fyi: you may try placing all of your code in a codeblock in your question; it will make it easier for others to read (and the whitespace is important)</p>",
      "rawMarkdown": "fyi: you may try placing all of your code in a codeblock in your question; it will make it easier for others to read (and the whitespace is important)",
      "votes": null
    },
    {
      "id": "2287074",
      "postDate": "06/04/2023 05:44:08",
      "content": "<p>`def compute(heatmap_pred, desc_pred,img, camera, alpha=0.2, eps=1e-6):</p>\n<pre><code>matches,match_list = feature\nM_world = cameraworld(matches,camera,match_list)\n\n\nreturn M_world`\n</code></pre>\n<p>`import albumentations as A<br>\nfrom PIL import Image</p>\n<p>transform_4 = A.Compose([<br>\n    A.Resize(height=256, width=256, p=1.0)<br>\n])</p>\n<p>def collate_img(img_list):<br>\n    newimages = []</p>\n<pre><code>newcamera = \n index,item  (img_list):\n\n    image = cv2(item,cv2.IMREAD_COLOR)\n\n    camera_id = \n     item() != -:\n        camera_id = \n    elif item() != -:\n        camera_id = \n\n\n     = torch((image=image))\n    newimages(img)\n\n\n\n    newcamera(camera_id)\nimages = torch(torch(newimages),dtype=torch.float32)\n\nimages = images(,,,)\n\n\n\nreturn images,newcamera`\n</code></pre>\n<p><code>src = '/kaggle/input/image-matching-challenge-2023'</code><br>\n<code>data_dict = {}\nwith open(f'{src}/sample_submission.csv', 'r') as f:\n    for i, l in enumerate(f):\n        # Skip header.\n        if l and i &gt; 0:\n            image, dataset, scene, _, _ = l.strip().split(',')\n            if dataset not in data_dict:\n                data_dict[dataset] = {}\n            if scene not in data_dict[dataset]:\n                data_dict[dataset][scene] = []\n            data_dict[dataset][scene].append(image)</code><br>\n<code>for dataset in data_dict:\n    for scene in data_dict[dataset]:\n        print(f'{dataset} / {scene} -&gt; {len(data_dict[dataset][scene])} images')</code><br>\n`out_results = {}<br>\ntimings = {\"shortlisting\":[],<br>\n           \"feature_detection\": [],<br>\n           \"feature_matching\":[],<br>\n           \"RANSAC\": [],<br>\n           \"Reconstruction\": []}<br>\ndef arr_to_str(a):<br>\n    return ';'.join([str(x) for x in a.reshape(-1)])<br>\nimport gc</p>\n<p>gc.collect()<br>\ndatasets = []</p>\n<p>for dataset in data_dict:<br>\n    datasets.append(dataset)</p>\n<p>for dataset in datasets:<br>\n    print(dataset)<br>\n    if dataset not in out_results:<br>\n        out_results[dataset] = {}<br>\n    for scene in data_dict[dataset]:<br>\n        print(scene)<br>\n        # Fail gently if the notebook has not been submitted and the test data is not populated.<br>\n        # You may want to run this on the training data in that case?<br>\n        img_dir = f'{src}/test/{dataset}/{scene}/images'<br>\n        if not os.path.exists(img_dir):<br>\n            continue<br>\n        # Wrap the meaty part in a try-except block.<br>\n        try:<br>\n            out_results[dataset][scene] = {}<br>\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]<br>\n            print (f\"Got {len(img_fnames)} images\")<br>\n            n = 16<br>\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]<br>\n            if len(new_fnames[-1]) &lt; n:<br>\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]<br>\n            M_world = []<br>\n            for index,item in enumerate(new_fnames):</p>\n<pre><code>            img_tensor,camera = (item)\n            model = ()\n            checkpoint = torch()\n            model(checkpoint)\n            model()\n            heatmap_pred,desc_pred, = (img_tensor)\n            temp = (heatmap_pred, desc_pred,,camera)\n            M_world =M_world + temp\n         index,name  (data_dict):\n            key1 = f\n            out_results = {}\n            out_results = M_world\n            out_results = M_world\n        (f)\n        (f)\n        (out_results, data_dict)\n        ()\n        gc()\n    except:\n        pass\n\n\n        `\n</code></pre>\n<p><code>create_submission(out_results, data_dict)</code><br>\nThis is all my code except the model</p>",
      "rawMarkdown": "`def compute(heatmap_pred, desc_pred,img, camera, alpha=0.2, eps=1e-6):\n    \n    \n    matches,match_list = feature_matching(heatmap_pred,desc_pred,img)\n    M_world = cameraworld(matches,camera,match_list)\n    \n    \n    return M_world`\n`import albumentations as A\nfrom PIL import Image\n\n\ntransform_4 = A.Compose([\n    A.Resize(height=256, width=256, p=1.0)\n])\n\ndef collate_img(img_list):\n    newimages = []\n    \n    newcamera = []\n    for index,item in enumerate(img_list):\n        \n        image = cv2.imread(item,cv2.IMREAD_COLOR)\n        \n        camera_id = 2\n        if item[0].find(\"dioscuri\") != -1:\n            camera_id = 54\n        elif item[0].find(\"kyiv-puppet-theater\") != -1:\n            camera_id = 2\n        \n        \n        img = torch.from_numpy(transform_4(image=image)['image'])\n        newimages.append(img)\n        \n        \n        \n        newcamera.append(camera_id)\n    images = torch.tensor(torch.stack(newimages),dtype=torch.float32)\n    print(\"images:\",images.shape)\n    images = images.permute(0,3,1,2)\n    print(\"images:\",images.shape)\n    \n        \n    return images,newcamera`\n`src = '/kaggle/input/image-matching-challenge-2023'`\n`data_dict = {}\nwith open(f'{src}/sample_submission.csv', 'r') as f:\n    for i, l in enumerate(f):\n        # Skip header.\n        if l and i > 0:\n            image, dataset, scene, _, _ = l.strip().split(',')\n            if dataset not in data_dict:\n                data_dict[dataset] = {}\n            if scene not in data_dict[dataset]:\n                data_dict[dataset][scene] = []\n            data_dict[dataset][scene].append(image)`\n`for dataset in data_dict:\n    for scene in data_dict[dataset]:\n        print(f'{dataset} / {scene} -> {len(data_dict[dataset][scene])} images')`\n`out_results = {}\ntimings = {\"shortlisting\":[],\n           \"feature_detection\": [],\n           \"feature_matching\":[],\n           \"RANSAC\": [],\n           \"Reconstruction\": []}\ndef arr_to_str(a):\n    return ';'.join([str(x) for x in a.reshape(-1)])\nimport gc\n\n\n\ngc.collect()\ndatasets = []\n\n\nfor dataset in data_dict:\n    datasets.append(dataset)\n\nfor dataset in datasets:\n    print(dataset)\n    if dataset not in out_results:\n        out_results[dataset] = {}\n    for scene in data_dict[dataset]:\n        print(scene)\n        # Fail gently if the notebook has not been submitted and the test data is not populated.\n        # You may want to run this on the training data in that case?\n        img_dir = f'{src}/test/{dataset}/{scene}/images'\n        if not os.path.exists(img_dir):\n            continue\n        # Wrap the meaty part in a try-except block.\n        try:\n            out_results[dataset][scene] = {}\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]\n            print (f\"Got {len(img_fnames)} images\")\n            n = 16\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]\n            if len(new_fnames[-1]) < n:\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]\n            M_world = []\n            for index,item in enumerate(new_fnames):\n\n\n                img_tensor,camera = collate_img(item)\n                model = make_model()\n                checkpoint = torch.load(\"/kaggle/input/params/DCNV3_4_params.pth\")\n                model.load_state_dict(checkpoint)\n                model.eval()\n                heatmap_pred,desc_pred,img = model(img_tensor)\n                temp = compute(heatmap_pred, desc_pred,img,camera)\n                M_world =M_world + temp\n            for index,name in enumerate(data_dict[dataset][scene]):\n                key1 = f'{name}'\n                out_results[dataset][scene][key1] = {}\n                out_results[dataset][scene][key1][\"R\"] = M_world[index][0]\n                out_results[dataset][scene][key1][\"t\"] = M_world[index][1]\n            print(f'Registered: {dataset} / {scene} -> {len(out_results[dataset][scene])} images')\n            print(f'Total: {dataset} / {scene} -> {len(data_dict[dataset][scene])} images')\n            create_submission(out_results, data_dict)\n            print(\"create_submission成功\")\n            gc.collect()\n        except:\n            pass\n            \n\n            `\n`create_submission(out_results, data_dict)`\nThis is all my code except the model",
      "votes": null
    }
  ],
  "comments": [
    {
      "id": 2287036,
      "author_name": "joshuabruning",
      "author_url": "",
      "post_date": "06/04/2023 04:53:56",
      "content": "<p>fyi: you may try placing all of your code in a codeblock in your question; it will make it easier for others to read (and the whitespace is important)</p>",
      "votes": null,
      "replies": []
    },
    {
      "id": 2287074,
      "author_name": "lanshank",
      "author_url": "",
      "post_date": "06/04/2023 05:44:08",
      "content": "<p>`def compute(heatmap_pred, desc_pred,img, camera, alpha=0.2, eps=1e-6):</p>\n<pre><code>matches,match_list = feature\nM_world = cameraworld(matches,camera,match_list)\n\n\nreturn M_world`\n</code></pre>\n<p>`import albumentations as A<br>\nfrom PIL import Image</p>\n<p>transform_4 = A.Compose([<br>\n    A.Resize(height=256, width=256, p=1.0)<br>\n])</p>\n<p>def collate_img(img_list):<br>\n    newimages = []</p>\n<pre><code>newcamera = \n index,item  (img_list):\n\n    image = cv2(item,cv2.IMREAD_COLOR)\n\n    camera_id = \n     item() != -:\n        camera_id = \n    elif item() != -:\n        camera_id = \n\n\n     = torch((image=image))\n    newimages(img)\n\n\n\n    newcamera(camera_id)\nimages = torch(torch(newimages),dtype=torch.float32)\n\nimages = images(,,,)\n\n\n\nreturn images,newcamera`\n</code></pre>\n<p><code>src = '/kaggle/input/image-matching-challenge-2023'</code><br>\n<code>data_dict = {}\nwith open(f'{src}/sample_submission.csv', 'r') as f:\n    for i, l in enumerate(f):\n        # Skip header.\n        if l and i &gt; 0:\n            image, dataset, scene, _, _ = l.strip().split(',')\n            if dataset not in data_dict:\n                data_dict[dataset] = {}\n            if scene not in data_dict[dataset]:\n                data_dict[dataset][scene] = []\n            data_dict[dataset][scene].append(image)</code><br>\n<code>for dataset in data_dict:\n    for scene in data_dict[dataset]:\n        print(f'{dataset} / {scene} -&gt; {len(data_dict[dataset][scene])} images')</code><br>\n`out_results = {}<br>\ntimings = {\"shortlisting\":[],<br>\n           \"feature_detection\": [],<br>\n           \"feature_matching\":[],<br>\n           \"RANSAC\": [],<br>\n           \"Reconstruction\": []}<br>\ndef arr_to_str(a):<br>\n    return ';'.join([str(x) for x in a.reshape(-1)])<br>\nimport gc</p>\n<p>gc.collect()<br>\ndatasets = []</p>\n<p>for dataset in data_dict:<br>\n    datasets.append(dataset)</p>\n<p>for dataset in datasets:<br>\n    print(dataset)<br>\n    if dataset not in out_results:<br>\n        out_results[dataset] = {}<br>\n    for scene in data_dict[dataset]:<br>\n        print(scene)<br>\n        # Fail gently if the notebook has not been submitted and the test data is not populated.<br>\n        # You may want to run this on the training data in that case?<br>\n        img_dir = f'{src}/test/{dataset}/{scene}/images'<br>\n        if not os.path.exists(img_dir):<br>\n            continue<br>\n        # Wrap the meaty part in a try-except block.<br>\n        try:<br>\n            out_results[dataset][scene] = {}<br>\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]<br>\n            print (f\"Got {len(img_fnames)} images\")<br>\n            n = 16<br>\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]<br>\n            if len(new_fnames[-1]) &lt; n:<br>\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]<br>\n            M_world = []<br>\n            for index,item in enumerate(new_fnames):</p>\n<pre><code>            img_tensor,camera = (item)\n            model = ()\n            checkpoint = torch()\n            model(checkpoint)\n            model()\n            heatmap_pred,desc_pred, = (img_tensor)\n            temp = (heatmap_pred, desc_pred,,camera)\n            M_world =M_world + temp\n         index,name  (data_dict):\n            key1 = f\n            out_results = {}\n            out_results = M_world\n            out_results = M_world\n        (f)\n        (f)\n        (out_results, data_dict)\n        ()\n        gc()\n    except:\n        pass\n\n\n        `\n</code></pre>\n<p><code>create_submission(out_results, data_dict)</code><br>\nThis is all my code except the model</p>",
      "votes": null,
      "replies": []
    }
  ],
  "raw_markdown_by_id": {
    "2287026": "Why did my code submit a 0.001 score and run in 3 minutes\nIt was written by my submission  is there a problem?\n\n`import gc\n\n\n\ngc.collect()\ndatasets = []\n\n\nfor dataset in data_dict:\n    datasets.append(dataset)\n\nfor dataset in datasets:\n    print(dataset)\n    if dataset not in out_results:\n        out_results[dataset] = {}\n    for scene in data_dict[dataset]:\n        print(scene)\n        # Fail gently if the notebook has not been submitted and the test data is not populated.\n        # You may want to run this on the training data in that case?\n        img_dir = f'{src}/test/{dataset}/{scene}/images'\n        if not os.path.exists(img_dir):\n            continue\n        # Wrap the meaty part in a try-except block.\n        try:\n            out_results[dataset][scene] = {}\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]\n            print (f\"Got {len(img_fnames)} images\")\n            n = 16\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]\n            if len(new_fnames[-1]) < n:\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]\n            M_world = []\n            for index,item in enumerate(new_fnames):\n\n\n                img_tensor,camera = collate_img(item)\n                model = make_model()\n                checkpoint = torch.load(\"/kaggle/input/params/params.pth\")\n                model.load_state_dict(checkpoint)\n                model.eval()\n                heatmap_pred,desc_pred,img = model(img_tensor)\n                temp = compute(heatmap_pred, desc_pred,img,camera)\n                M_world =M_world + temp\n            for index,name in enumerate(data_dict[dataset][scene]):\n                key1 = f'{name}'\n                out_results[dataset][scene][key1] = {}\n                out_results[dataset][scene][key1][\"R\"] = M_world[index][0]\n                out_results[dataset][scene][key1][\"t\"] = M_world[index][1]\n            print(f'Registered: {dataset} / {scene} -> {len(out_results[dataset][scene])} images')\n            print(f'Total: {dataset} / {scene} -> {len(data_dict[dataset][scene])} images')\n            create_submission(out_results, data_dict)\n            print(\"create_submission成功\")\n            gc.collect()\n        except:\n            pass\n            \n`\n`create_submission(out_results, data_dict)`",
    "2287036": "fyi: you may try placing all of your code in a codeblock in your question; it will make it easier for others to read (and the whitespace is important)",
    "2287074": "`def compute(heatmap_pred, desc_pred,img, camera, alpha=0.2, eps=1e-6):\n    \n    \n    matches,match_list = feature_matching(heatmap_pred,desc_pred,img)\n    M_world = cameraworld(matches,camera,match_list)\n    \n    \n    return M_world`\n`import albumentations as A\nfrom PIL import Image\n\n\ntransform_4 = A.Compose([\n    A.Resize(height=256, width=256, p=1.0)\n])\n\ndef collate_img(img_list):\n    newimages = []\n    \n    newcamera = []\n    for index,item in enumerate(img_list):\n        \n        image = cv2.imread(item,cv2.IMREAD_COLOR)\n        \n        camera_id = 2\n        if item[0].find(\"dioscuri\") != -1:\n            camera_id = 54\n        elif item[0].find(\"kyiv-puppet-theater\") != -1:\n            camera_id = 2\n        \n        \n        img = torch.from_numpy(transform_4(image=image)['image'])\n        newimages.append(img)\n        \n        \n        \n        newcamera.append(camera_id)\n    images = torch.tensor(torch.stack(newimages),dtype=torch.float32)\n    print(\"images:\",images.shape)\n    images = images.permute(0,3,1,2)\n    print(\"images:\",images.shape)\n    \n        \n    return images,newcamera`\n`src = '/kaggle/input/image-matching-challenge-2023'`\n`data_dict = {}\nwith open(f'{src}/sample_submission.csv', 'r') as f:\n    for i, l in enumerate(f):\n        # Skip header.\n        if l and i > 0:\n            image, dataset, scene, _, _ = l.strip().split(',')\n            if dataset not in data_dict:\n                data_dict[dataset] = {}\n            if scene not in data_dict[dataset]:\n                data_dict[dataset][scene] = []\n            data_dict[dataset][scene].append(image)`\n`for dataset in data_dict:\n    for scene in data_dict[dataset]:\n        print(f'{dataset} / {scene} -> {len(data_dict[dataset][scene])} images')`\n`out_results = {}\ntimings = {\"shortlisting\":[],\n           \"feature_detection\": [],\n           \"feature_matching\":[],\n           \"RANSAC\": [],\n           \"Reconstruction\": []}\ndef arr_to_str(a):\n    return ';'.join([str(x) for x in a.reshape(-1)])\nimport gc\n\n\n\ngc.collect()\ndatasets = []\n\n\nfor dataset in data_dict:\n    datasets.append(dataset)\n\nfor dataset in datasets:\n    print(dataset)\n    if dataset not in out_results:\n        out_results[dataset] = {}\n    for scene in data_dict[dataset]:\n        print(scene)\n        # Fail gently if the notebook has not been submitted and the test data is not populated.\n        # You may want to run this on the training data in that case?\n        img_dir = f'{src}/test/{dataset}/{scene}/images'\n        if not os.path.exists(img_dir):\n            continue\n        # Wrap the meaty part in a try-except block.\n        try:\n            out_results[dataset][scene] = {}\n            img_fnames = [f'{src}/test/{x}' for x in data_dict[dataset][scene]]\n            print (f\"Got {len(img_fnames)} images\")\n            n = 16\n            new_fnames = [img_fnames[i:i+n] for i in range(0, len(img_fnames), n)]\n            if len(new_fnames[-1]) < n:\n                new_fnames[-2:] = [new_fnames[-2] + new_fnames[-1]]\n            M_world = []\n            for index,item in enumerate(new_fnames):\n\n\n                img_tensor,camera = collate_img(item)\n                model = make_model()\n                checkpoint = torch.load(\"/kaggle/input/params/DCNV3_4_params.pth\")\n                model.load_state_dict(checkpoint)\n                model.eval()\n                heatmap_pred,desc_pred,img = model(img_tensor)\n                temp = compute(heatmap_pred, desc_pred,img,camera)\n                M_world =M_world + temp\n            for index,name in enumerate(data_dict[dataset][scene]):\n                key1 = f'{name}'\n                out_results[dataset][scene][key1] = {}\n                out_results[dataset][scene][key1][\"R\"] = M_world[index][0]\n                out_results[dataset][scene][key1][\"t\"] = M_world[index][1]\n            print(f'Registered: {dataset} / {scene} -> {len(out_results[dataset][scene])} images')\n            print(f'Total: {dataset} / {scene} -> {len(data_dict[dataset][scene])} images')\n            create_submission(out_results, data_dict)\n            print(\"create_submission成功\")\n            gc.collect()\n        except:\n            pass\n            \n\n            `\n`create_submission(out_results, data_dict)`\nThis is all my code except the model"
  },
  "source": "meta"
}