{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":113558,"databundleVersionId":14174843,"sourceType":"competition"},{"sourceId":270092713,"sourceType":"kernelVersion"}],"dockerImageVersionId":31192,"isInternetEnabled":false,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport os","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:27:08.127007Z","iopub.execute_input":"2025-11-08T18:27:08.127377Z","iopub.status.idle":"2025-11-08T18:27:08.458624Z","shell.execute_reply.started":"2025-11-08T18:27:08.127353Z","shell.execute_reply":"2025-11-08T18:27:08.457816Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"src_pth = '/kaggle/input/recodai-luc-scientific-image-forgery-detection/train_masks/'\nmasks = os.listdir(src_pth)\nmasks[:5]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:27:08.460295Z","iopub.execute_input":"2025-11-08T18:27:08.460791Z","iopub.status.idle":"2025-11-08T18:27:08.490122Z","shell.execute_reply.started":"2025-11-08T18:27:08.460767Z","shell.execute_reply":"2025-11-08T18:27:08.489304Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"npy = np.load(src_pth + masks[np.random.randint(len(masks))])\nprint(npy.shape) # The shape of train masks is NxHxW, one HxW binary mask per object copied/pasted\nnpy = np.argmax(\n    np.concatenate([\n        np.zeros_like(npy[:1]),\n        npy\n    ]),\n    0\n)\nplt.imshow(npy)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:27:08.490949Z","iopub.execute_input":"2025-11-08T18:27:08.491174Z","iopub.status.idle":"2025-11-08T18:27:08.904121Z","shell.execute_reply.started":"2025-11-08T18:27:08.491156Z","shell.execute_reply":"2025-11-08T18:27:08.903179Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import sys\nsys.path.append('/kaggle/usr/lib/recodai-f1/')\n\nfrom metric import rle_encode","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:27:08.905301Z","iopub.execute_input":"2025-11-08T18:27:08.905578Z","iopub.status.idle":"2025-11-08T18:27:10.638347Z","shell.execute_reply.started":"2025-11-08T18:27:08.905551Z","shell.execute_reply":"2025-11-08T18:27:10.637276Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"npy = np.load(src_pth + masks[np.random.randint(len(masks))])\nprint(npy.shape) # The shape of train masks is NxHxW, one HxW binary mask per object copied/pasted\nrle_encode(list(npy))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:27:10.640783Z","iopub.execute_input":"2025-11-08T18:27:10.641180Z","iopub.status.idle":"2025-11-08T18:27:12.838267Z","shell.execute_reply.started":"2025-11-08T18:27:10.641155Z","shell.execute_reply":"2025-11-08T18:27:12.837317Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"samples = os.listdir('/kaggle/input/recodai-luc-scientific-image-forgery-detection/test_images/')\nsamples[:5]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:27:12.839233Z","iopub.execute_input":"2025-11-08T18:27:12.839603Z","iopub.status.idle":"2025-11-08T18:27:12.849595Z","shell.execute_reply.started":"2025-11-08T18:27:12.839570Z","shell.execute_reply":"2025-11-08T18:27:12.848769Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"case_id = []\nannotation = []\nfor sample in samples:\n    case_id.append(sample.split('.')[0])\n    if 1:#np.random.rand() < .125:\n        annotation.append('authentic')\n    else:\n        annotation.append(\n            rle_encode(\n                list((np.random.rand(*np.load(src_pth + masks[np.random.randint(len(masks))]).shape) < .5).astype(np.uint8))\n            )\n        )","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:34:05.512185Z","iopub.execute_input":"2025-11-08T18:34:05.512519Z","iopub.status.idle":"2025-11-08T18:34:05.721590Z","shell.execute_reply.started":"2025-11-08T18:34:05.512494Z","shell.execute_reply":"2025-11-08T18:34:05.720650Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.DataFrame({\n    'case_id':case_id,\n    'annotation':annotation\n})\nsubmission.head(5)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:34:17.197409Z","iopub.execute_input":"2025-11-08T18:34:17.197833Z","iopub.status.idle":"2025-11-08T18:34:17.238284Z","shell.execute_reply.started":"2025-11-08T18:34:17.197806Z","shell.execute_reply":"2025-11-08T18:34:17.237312Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission.to_csv('submission.csv',index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-11-08T18:34:25.103927Z","iopub.execute_input":"2025-11-08T18:34:25.104237Z","iopub.status.idle":"2025-11-08T18:34:25.231091Z","shell.execute_reply.started":"2025-11-08T18:34:25.104214Z","shell.execute_reply":"2025-11-08T18:34:25.230184Z"}},"outputs":[],"execution_count":null}]}