{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"from kaggle_datasets import KaggleDatasets\nimport tensorflow as tf","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"try:\n    tpu = tf.distribute.cluster_resolver.TPUClusterResolver()\n    print('Running on TPU ', tpu.master())\nexcept ValueError:\n    tpu = None\n\nif tpu:\n    tf.config.experimental_connect_to_cluster(tpu)\n    tf.tpu.experimental.initialize_tpu_system(tpu)\n    strategy = tf.distribute.experimental.TPUStrategy(tpu)\nelse:\n    # Default distribution strategy in Tensorflow. Works on CPU and single GPU.\n    strategy = tf.distribute.get_strategy()\n\nprint(\"REPLICAS: \", strategy.num_replicas_in_sync)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# For tf.dataset\nAUTO = tf.data.experimental.AUTOTUNE\n\n# Data access\nGCS_DS_PATH = KaggleDatasets().get_gcs_path()\n\n# Configuration\nEPOCHS = 10\nBATCH_SIZE = 16 * strategy.num_replicas_in_sync","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def append_path(pre):\n    return np.vectorize(lambda file: os.path.join(GCS_DS_PATH, pre, file))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import numpy as np\nimport os\n\nfor folder in os.listdir(\"../input/alaska2-image-steganalysis/\"):\n    if os.path.isfile(\"../input/alaska2-image-steganalysis/\"+folder):\n        continue\n        \n    train_filenames = np.array(os.listdir(f\"/kaggle/input/alaska2-image-steganalysis/{folder}\"))\n    paths = append_path(f\"{folder}\")(train_filenames)\n    np.save(f\"{folder}.npy\",paths)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from tqdm.notebook import tqdm\nimport pandas as pd\nimport gc","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"path = \"../input/alaska2-image-steganalysis/\"\n\nclasses_index = {\n    \"Cover\":0,\n    \"JMiPOD\":1,\n    \"JUNIWARD\":2,\n    \"UERD\":3\n}\n\ndata = []\n\nfor folder in os.listdir(path):\n    if folder == \"Test\" or os.path.isfile(os.path.join(path,folder)):\n        continue\n    folder_path = os.path.join(path,folder)\n    class_ = classes_index[folder] \n    print(f\"working on {folder}\")\n    \n    for image in tqdm(os.listdir(folder_path)):\n        image_path = os.path.join(folder_path,image)\n        data.append([image_path,class_])\n    print(f\"Completed Class {folder} \\n\")\n    \ntrain = pd.DataFrame(data,columns=['image','class'])\ndel data\ngc.collect()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"train.to_csv(\"train_data.csv\",index=None)","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}