{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Install efficientnet","metadata":{}},{"cell_type":"code","source":"!pip install efficientnet","metadata":{"execution":{"iopub.status.busy":"2023-01-26T09:57:06.776331Z","iopub.execute_input":"2023-01-26T09:57:06.7774Z","iopub.status.idle":"2023-01-26T09:57:20.594384Z","shell.execute_reply.started":"2023-01-26T09:57:06.777293Z","shell.execute_reply":"2023-01-26T09:57:20.592809Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Check for available GPU","metadata":{}},{"cell_type":"code","source":"import tensorflow as tf\n\nprint(tf.__version__) \ndevice_name = tf.test.gpu_device_name()\nif \"GPU\" not in device_name:\n    print(\"GPU device not found\")\nprint('Found GPU at: {}'.format(device_name))","metadata":{"execution":{"iopub.status.busy":"2023-01-26T09:57:20.597127Z","iopub.execute_input":"2023-01-26T09:57:20.597876Z","iopub.status.idle":"2023-01-26T09:57:29.381399Z","shell.execute_reply.started":"2023-01-26T09:57:20.597812Z","shell.execute_reply":"2023-01-26T09:57:29.380388Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Log in Weights and Biases","metadata":{}},{"cell_type":"code","source":"from kaggle_secrets import UserSecretsClient\nimport wandb\n\nuser_secrets = UserSecretsClient()\napi_key = user_secrets.get_secret(\"WANDB\")\nwandb.login(key=api_key)","metadata":{"execution":{"iopub.status.busy":"2023-01-26T09:57:29.382913Z","iopub.execute_input":"2023-01-26T09:57:29.384181Z","iopub.status.idle":"2023-01-26T09:57:31.245451Z","shell.execute_reply.started":"2023-01-26T09:57:29.384143Z","shell.execute_reply":"2023-01-26T09:57:31.24448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Navigate to training script","metadata":{}},{"cell_type":"code","source":"cd ../input/Kaggle-RSNA-Screening-Mammography-code/src","metadata":{"execution":{"iopub.status.busy":"2023-01-26T09:57:31.249623Z","iopub.execute_input":"2023-01-26T09:57:31.249918Z","iopub.status.idle":"2023-01-26T09:57:31.267455Z","shell.execute_reply.started":"2023-01-26T09:57:31.24989Z","shell.execute_reply":"2023-01-26T09:57:31.266435Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Print Hyperparameters","metadata":{}},{"cell_type":"code","source":"import yaml\n\n        \ndef print_hyperparameters(path='../config/config.yaml'):\n    config = yaml.load(open(path), Loader=yaml.FullLoader)\n    for parameter in sorted(config['hyperparams']):\n        print(f'{parameter} = {config[\"hyperparams\"][parameter]}')\n        \nprint_hyperparameters()","metadata":{"execution":{"iopub.status.busy":"2023-01-26T09:57:31.268832Z","iopub.execute_input":"2023-01-26T09:57:31.269151Z","iopub.status.idle":"2023-01-26T09:57:31.287745Z","shell.execute_reply.started":"2023-01-26T09:57:31.269126Z","shell.execute_reply":"2023-01-26T09:57:31.286639Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Optional**: change hyperparameter","metadata":{}},{"cell_type":"code","source":"# Changes\nconfig = yaml.load(open('../config/config.yaml'), Loader=yaml.FullLoader)\nconfig['hyperparams']['oversampling_factor'] = 10\nconfig['hyperparams']['input_size'] = 512\nconfig['hyperparams']['target_crop_size'] = [256,512]\nconfig['hyperparams']['batch_size'] = 8\nconfig['hyperparams']['data_ratio'] = 1\nconfig['hyperparams']['learning_rate'] = 1e-4\nconfig['hyperparams']['augmentations']['random_hflip']=True\nconfig['hyperparams']['augmentations']['random_brightness_max_delta']=0.2\n\n# Update yaml\npath_working = '../../../working/config.yaml'\nwith open(path_working, 'w') as outfile:\n    yaml.dump(config, outfile, default_flow_style=False)\n\nprint_hyperparameters(path_working)","metadata":{"execution":{"iopub.status.busy":"2023-01-26T09:57:31.289384Z","iopub.execute_input":"2023-01-26T09:57:31.28974Z","iopub.status.idle":"2023-01-26T09:57:31.313815Z","shell.execute_reply.started":"2023-01-26T09:57:31.289706Z","shell.execute_reply":"2023-01-26T09:57:31.312818Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Train Model","metadata":{}},{"cell_type":"code","source":" !python train_model.py --kaggle --config ../../../working/config.yaml","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}