{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"colab":{"provenance":[]},"accelerator":"GPU","gpuClass":"standard","kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"sourceId":10236849,"sourceType":"datasetVersion","datasetId":6330106}],"dockerImageVersionId":30805,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!nvidia-smi","metadata":{"id":"Y8cDtxLIBHgQ","outputId":"e7eac777-db93-4dae-b0bb-c32efbdd062c","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:17.126707Z","iopub.execute_input":"2024-12-18T15:17:17.127153Z","iopub.status.idle":"2024-12-18T15:17:18.342376Z","shell.execute_reply.started":"2024-12-18T15:17:17.127081Z","shell.execute_reply":"2024-12-18T15:17:18.341007Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import os\nHOME = os.getcwd()\nprint(HOME)","metadata":{"id":"CjpPg4mGKc1v","outputId":"3563b6c4-bdde-4ad3-d5a0-190b2577cf5b","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:18.344705Z","iopub.execute_input":"2024-12-18T15:17:18.345150Z","iopub.status.idle":"2024-12-18T15:17:18.351704Z","shell.execute_reply.started":"2024-12-18T15:17:18.345085Z","shell.execute_reply":"2024-12-18T15:17:18.350751Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Pip install method (recommended)\n\n!pip install ultralytics\n\nfrom IPython import display\n\nimport ultralytics\n","metadata":{"id":"tdSMcABDNKW-","outputId":"5b726bbd-4021-44cd-db78-ac63d638a8d1","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:18.352823Z","iopub.execute_input":"2024-12-18T15:17:18.353067Z","iopub.status.idle":"2024-12-18T15:17:37.426326Z","shell.execute_reply.started":"2024-12-18T15:17:18.353045Z","shell.execute_reply":"2024-12-18T15:17:37.425499Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"from ultralytics import YOLO\n\nfrom IPython.display import display, Image","metadata":{"id":"VOEYrlBoP9-E","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:37.429065Z","iopub.execute_input":"2024-12-18T15:17:37.429884Z","iopub.status.idle":"2024-12-18T15:17:37.433772Z","shell.execute_reply.started":"2024-12-18T15:17:37.429837Z","shell.execute_reply":"2024-12-18T15:17:37.432948Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\n!yolo task=segment mode=predict model=yolov8l-seg.pt conf=0.5 source='/kaggle/input/image-to-test/istockphoto-1364054930-612x612.jpg'","metadata":{"id":"FDbMt_M6PiXb","outputId":"a41d88a9-0cc2-412d-b12d-7b66378289e6","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:37.434921Z","iopub.execute_input":"2024-12-18T15:17:37.435485Z","iopub.status.idle":"2024-12-18T15:17:48.937690Z","shell.execute_reply.started":"2024-12-18T15:17:37.435444Z","shell.execute_reply":"2024-12-18T15:17:48.936806Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\nImage(filename='/kaggle/input/image-to-test/istockphoto-1364054930-612x612.jpg', height=600)","metadata":{"id":"LyopYpK1TQrB","outputId":"dee5b3e7-538f-4796-9700-b380dad57eab","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:48.939211Z","iopub.execute_input":"2024-12-18T15:17:48.939538Z","iopub.status.idle":"2024-12-18T15:17:48.962886Z","shell.execute_reply.started":"2024-12-18T15:17:48.939510Z","shell.execute_reply":"2024-12-18T15:17:48.962045Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#results[0].boxes.xyxy","metadata":{"id":"kAi4PvrItTCf","outputId":"3d204d68-b4de-4c64-e05b-db7d2fee1f01","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:48.963876Z","iopub.execute_input":"2024-12-18T15:17:48.964152Z","iopub.status.idle":"2024-12-18T15:17:48.967988Z","shell.execute_reply.started":"2024-12-18T15:17:48.964110Z","shell.execute_reply":"2024-12-18T15:17:48.967080Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#results[0].boxes.conf","metadata":{"id":"HqT2M01K1LUb","outputId":"5cbd81fe-0b0d-4643-d4c2-2baf7a0a3b08","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:16:51.712343Z","iopub.execute_input":"2024-12-18T15:16:51.712590Z","iopub.status.idle":"2024-12-18T15:16:51.722146Z","shell.execute_reply.started":"2024-12-18T15:16:51.712558Z","shell.execute_reply":"2024-12-18T15:16:51.721238Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"#results[0].boxes.cls","metadata":{"id":"gKIwJ5yw1PMb","outputId":"d0574f9d-3c7e-4b70-f7b4-954dc5bd4e4b","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:16:51.723252Z","iopub.execute_input":"2024-12-18T15:16:51.723499Z","iopub.status.idle":"2024-12-18T15:16:51.730922Z","shell.execute_reply.started":"2024-12-18T15:16:51.723475Z","shell.execute_reply":"2024-12-18T15:16:51.729943Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install roboflow\n\nfrom roboflow import Roboflow\nrf = Roboflow(api_key=\"trcYUAB2od1nqMYI2SVr\")\nproject = rf.workspace(\"personal-zyrbe\").project(\"fracture-detection-jmsjv\")\nversion = project.version(1)\ndataset = version.download(\"yolov8\")","metadata":{"id":"BSd93ZJzZZKt","outputId":"827f861c-89ec-4ed4-ec71-3068639fb902","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:17:48.971817Z","iopub.execute_input":"2024-12-18T15:17:48.972055Z","iopub.status.idle":"2024-12-18T15:18:00.127838Z","shell.execute_reply.started":"2024-12-18T15:17:48.972031Z","shell.execute_reply":"2024-12-18T15:18:00.126852Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Custom Training","metadata":{"id":"YUjFBKKqXa-u"}},{"cell_type":"code","source":"pwd\n","metadata":{"id":"19rbI5ePoZuo","outputId":"30a32aff-386b-4039-a2f4-f4d3c59bd753","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:22:49.798969Z","iopub.execute_input":"2024-12-18T15:22:49.799233Z","iopub.status.idle":"2024-12-18T15:22:49.810542Z","shell.execute_reply.started":"2024-12-18T15:22:49.799208Z","shell.execute_reply":"2024-12-18T15:22:49.809725Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\n\n!yolo task=segment mode=train model=yolov8n-seg.pt data={dataset.location}/data.yaml epochs=25 imgsz=640","metadata":{"id":"D2YkphuiaE7_","outputId":"69e0c947-6036-4ca0-874c-9bde39d54cfd","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:18:24.936276Z","iopub.execute_input":"2024-12-18T15:18:24.936648Z","iopub.status.idle":"2024-12-18T15:22:48.739012Z","shell.execute_reply.started":"2024-12-18T15:18:24.936591Z","shell.execute_reply":"2024-12-18T15:22:48.737824Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls {HOME}/runs/segment/train2/","metadata":{"id":"1MScstfHhArr","outputId":"de3adc0c-c8b9-4b4c-8946-485b0ffbc0d3","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:22:52.783769Z","iopub.execute_input":"2024-12-18T15:22:52.784175Z","iopub.status.idle":"2024-12-18T15:22:53.838204Z","shell.execute_reply.started":"2024-12-18T15:22:52.784142Z","shell.execute_reply":"2024-12-18T15:22:53.837171Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\nImage(filename=f'{HOME}/runs/segment/train2/confusion_matrix.png', width=600)","metadata":{"id":"_J35i8Ofhjxa","outputId":"7bc3f175-2f5b-48c5-9e1e-11b6b562acf1","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:22:56.993860Z","iopub.execute_input":"2024-12-18T15:22:56.994955Z","iopub.status.idle":"2024-12-18T15:22:57.006334Z","shell.execute_reply.started":"2024-12-18T15:22:56.994899Z","shell.execute_reply":"2024-12-18T15:22:57.005304Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\nImage(filename=f'{HOME}/runs/segment/train2/results.png', width=600)","metadata":{"id":"A-urTWUkhRmn","outputId":"473a8ccf-fad9-4bb8-8202-4d5b6aa6a33c","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:23:01.029649Z","iopub.execute_input":"2024-12-18T15:23:01.029991Z","iopub.status.idle":"2024-12-18T15:23:01.047151Z","shell.execute_reply.started":"2024-12-18T15:23:01.029961Z","shell.execute_reply":"2024-12-18T15:23:01.046249Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Validate Custom Model","metadata":{"id":"6ODk1VTlevxn"}},{"cell_type":"code","source":"%cd {HOME}\n\n!yolo task=segment mode=val model={HOME}/runs/segment/train2/weights/best.pt data={dataset.location}/data.yaml","metadata":{"id":"YpyuwrNlXc1P","outputId":"8525bfda-ffa4-4634-9179-724eb1b12a11","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:23:07.363194Z","iopub.execute_input":"2024-12-18T15:23:07.363559Z","iopub.status.idle":"2024-12-18T15:23:22.833305Z","shell.execute_reply.started":"2024-12-18T15:23:07.363528Z","shell.execute_reply":"2024-12-18T15:23:22.832187Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"## Inference with Custom Model","metadata":{"id":"i4eASbcWkQBq"}},{"cell_type":"code","source":"%cd {HOME}\n!yolo task=segment mode=predict model={HOME}/runs/segment/train2/weights/best.pt conf=0.25 source={dataset.location}/test/images","metadata":{"id":"Wjc1ctZykYuf","outputId":"b694cf18-b83c-4937-e942-029a8f640d92","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:23:22.835670Z","iopub.execute_input":"2024-12-18T15:23:22.836049Z","iopub.status.idle":"2024-12-18T15:23:29.410846Z","shell.execute_reply.started":"2024-12-18T15:23:22.836010Z","shell.execute_reply":"2024-12-18T15:23:29.409853Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"**NOTE:** Let's take a look at few results.","metadata":{"id":"mEYIo95n-I0S"}},{"cell_type":"code","source":"import glob\nfrom IPython.display import Image, display\n\nfor image_path in glob.glob(f'{HOME}/runs/segment/predict2/*.jpg')[:20]:\n      display(Image(filename=image_path, width=600))\n      print(\"\\n\")","metadata":{"id":"jbVjEtPAkz3j","outputId":"a1ba61ed-f6d5-4385-89eb-4381c3dc808e","trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:23:43.572876Z","iopub.execute_input":"2024-12-18T15:23:43.573954Z","iopub.status.idle":"2024-12-18T15:23:43.640252Z","shell.execute_reply.started":"2024-12-18T15:23:43.573898Z","shell.execute_reply":"2024-12-18T15:23:43.639386Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!pip install roboflow\n\nfrom roboflow import Roboflow\nrf = Roboflow(api_key=\"trcYUAB2od1nqMYI2SVr\")\nproject = rf.workspace(\"projects-gnolw\").project(\"amiloidose-completo\")\nversion = project.version(3)\ndataset = version.download(\"yolov8\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:23:58.267388Z","iopub.execute_input":"2024-12-18T15:23:58.267751Z","iopub.status.idle":"2024-12-18T15:24:10.378036Z","shell.execute_reply.started":"2024-12-18T15:23:58.267719Z","shell.execute_reply":"2024-12-18T15:24:10.377008Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pwd","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:24:10.379796Z","iopub.execute_input":"2024-12-18T15:24:10.380085Z","iopub.status.idle":"2024-12-18T15:24:10.386231Z","shell.execute_reply.started":"2024-12-18T15:24:10.380057Z","shell.execute_reply":"2024-12-18T15:24:10.385281Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\n\n!yolo task=segment mode=train model=yolov8n-seg.pt data={dataset.location}/data.yaml epochs=25 imgsz=640","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:24:10.387355Z","iopub.execute_input":"2024-12-18T15:24:10.387618Z","iopub.status.idle":"2024-12-18T15:41:31.716640Z","shell.execute_reply.started":"2024-12-18T15:24:10.387593Z","shell.execute_reply":"2024-12-18T15:41:31.715275Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"!ls {HOME}/runs/segment/train3/","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:41:58.680865Z","iopub.execute_input":"2024-12-18T15:41:58.681397Z","iopub.status.idle":"2024-12-18T15:41:59.690555Z","shell.execute_reply.started":"2024-12-18T15:41:58.681361Z","shell.execute_reply":"2024-12-18T15:41:59.689389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\nImage(filename=f'{HOME}/runs/segment/train3/confusion_matrix.png', width=600)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:42:02.465994Z","iopub.execute_input":"2024-12-18T15:42:02.466385Z","iopub.status.idle":"2024-12-18T15:42:02.479617Z","shell.execute_reply.started":"2024-12-18T15:42:02.466354Z","shell.execute_reply":"2024-12-18T15:42:02.478718Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%cd {HOME}\nImage(filename=f'{HOME}/runs/segment/train3/results.png', width=600)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:42:06.513460Z","iopub.execute_input":"2024-12-18T15:42:06.514348Z","iopub.status.idle":"2024-12-18T15:42:06.531266Z","shell.execute_reply.started":"2024-12-18T15:42:06.514312Z","shell.execute_reply":"2024-12-18T15:42:06.530341Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# valid","metadata":{}},{"cell_type":"code","source":"%cd {HOME}\n\n!yolo task=segment mode=val model={HOME}/runs/segment/train3/weights/best.pt data={dataset.location}/data.yaml","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:42:11.755084Z","iopub.execute_input":"2024-12-18T15:42:11.755830Z","iopub.status.idle":"2024-12-18T15:42:26.614831Z","shell.execute_reply.started":"2024-12-18T15:42:11.755798Z","shell.execute_reply":"2024-12-18T15:42:26.613933Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"# Test","metadata":{}},{"cell_type":"code","source":"%cd {HOME}\n!yolo task=segment mode=predict model={HOME}/runs/segment/train3/weights/best.pt conf=0.25 source={dataset.location}/test/images","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:42:28.815213Z","iopub.execute_input":"2024-12-18T15:42:28.816012Z","iopub.status.idle":"2024-12-18T15:42:37.072887Z","shell.execute_reply.started":"2024-12-18T15:42:28.815974Z","shell.execute_reply":"2024-12-18T15:42:37.071757Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"import glob\nfrom IPython.display import Image, display\n\nfor image_path in glob.glob(f'{HOME}/runs/segment/predict3/*.jpg')[:20]:\n      display(Image(filename=image_path, width=600))\n      print(\"\\n\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-12-18T15:42:44.852716Z","iopub.execute_input":"2024-12-18T15:42:44.853499Z","iopub.status.idle":"2024-12-18T15:42:44.929463Z","shell.execute_reply.started":"2024-12-18T15:42:44.853460Z","shell.execute_reply":"2024-12-18T15:42:44.928685Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}