{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"gpu","dataSources":[{"sourceId":8417849,"sourceType":"datasetVersion","datasetId":5010909},{"sourceId":8417969,"sourceType":"datasetVersion","datasetId":5011008},{"sourceId":8728639,"sourceType":"datasetVersion","datasetId":5238805},{"sourceId":8435757,"sourceType":"datasetVersion","datasetId":5024483},{"sourceId":8728762,"sourceType":"datasetVersion","datasetId":5238901},{"sourceId":8762514,"sourceType":"datasetVersion","datasetId":5264761},{"sourceId":8765681,"sourceType":"datasetVersion","datasetId":5267060},{"sourceId":8767466,"sourceType":"datasetVersion","datasetId":5268362},{"sourceId":8784728,"sourceType":"datasetVersion","datasetId":5281012}],"dockerImageVersionId":30017,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":true}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!python --version","metadata":{"execution":{"iopub.status.busy":"2024-05-19T08:44:37.692374Z","iopub.execute_input":"2024-05-19T08:44:37.692745Z","iopub.status.idle":"2024-05-19T08:44:38.680932Z","shell.execute_reply.started":"2024-05-19T08:44:37.692712Z","shell.execute_reply":"2024-05-19T08:44:38.680074Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import shutil\nimport os\n# shutil.rmtree('/kaggle/working/data')\n# shutil.rmtree('/kaggle/working/hijackgan')","metadata":{"execution":{"iopub.status.busy":"2024-05-19T04:50:03.420793Z","iopub.execute_input":"2024-05-19T04:50:03.421393Z","iopub.status.idle":"2024-05-19T04:50:03.427040Z","shell.execute_reply.started":"2024-05-19T04:50:03.421332Z","shell.execute_reply":"2024-05-19T04:50:03.425811Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!mkdir /kaggle/working/data\nshutil.copytree('/kaggle/input/celebahq-test','/kaggle/working/data/celebahq_test')\n!cp /kaggle/input/celebahq-test-dataset/* /kaggle/working/data","metadata":{"execution":{"iopub.status.busy":"2024-05-19T04:50:04.577287Z","iopub.execute_input":"2024-05-19T04:50:04.577742Z","iopub.status.idle":"2024-05-19T04:50:06.611093Z","shell.execute_reply.started":"2024-05-19T04:50:04.577703Z","shell.execute_reply":"2024-05-19T04:50:06.609632Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.copytree('/kaggle/input/hijackgan', '/kaggle/working/hijackgan')\n!mkdir /kaggle/working/hijackgan/models/resnet50_celebahq\n!cp /kaggle/input/resnet50-celebahq/* /kaggle/working/hijackgan/models/resnet50_celebahq\n# shutil.copytree('/kaggle/input/generated-data-celeba', '/kaggle/working/hijackgan/generated_data_celeba')","metadata":{"execution":{"iopub.status.busy":"2024-05-19T04:50:13.612971Z","iopub.execute_input":"2024-05-19T04:50:13.613683Z","iopub.status.idle":"2024-05-19T04:51:35.711307Z","shell.execute_reply.started":"2024-05-19T04:50:13.613615Z","shell.execute_reply":"2024-05-19T04:51:35.710325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !cp /kaggle/input/test-dataset/* /kaggle/working/data\n# !cp /kaggle/input/test-images/Training/female/* /kaggle/working/data/gender_clf_dataset\n# !cp /kaggle/input/test-images/Training/male/* /kaggle/working/data/gender_clf_dataset\n# !cp /kaggle/input/test-images/Validation/female/* /kaggle/working/data/gender_clf_dataset\n# !cp /kaggle/input/test-images/Validation/male/* /kaggle/working/data/gender_clf_dataset","metadata":{"execution":{"iopub.status.busy":"2024-05-19T04:52:55.993271Z","iopub.execute_input":"2024-05-19T04:52:55.994975Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"shutil.rmtree('/kaggle/working/hijackgan/generated_data')\n!rm /kaggle/working/hijackgan/test_features.hdf5","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%pwd","metadata":{"execution":{"iopub.status.busy":"2024-05-17T02:29:21.353257Z","iopub.execute_input":"2024-05-17T02:29:21.353586Z","iopub.status.idle":"2024-05-17T02:29:21.360649Z","shell.execute_reply.started":"2024-05-17T02:29:21.353551Z","shell.execute_reply":"2024-05-17T02:29:21.359731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%cd hijackgan","metadata":{"execution":{"iopub.status.busy":"2024-05-17T06:26:38.020954Z","iopub.execute_input":"2024-05-17T06:26:38.021339Z","iopub.status.idle":"2024-05-17T06:26:38.028203Z","shell.execute_reply.started":"2024-05-17T06:26:38.021301Z","shell.execute_reply":"2024-05-17T06:26:38.027276Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!rm /kaggle/working/hijackgan/models/pseudo_classifier.py\n!rm /kaggle/working/hijackgan/models/model_settings.py\n!rm /kaggle/working/hijackgan/utils/logger.py\n!rm /kaggle/working/hijackgan/models/base_generator.py\n!cp /kaggle/input/model-files-celeba/pseudo_clf_train_data_celeba.py /kaggle/working/hijackgan\n!cp /kaggle/input/model-files-celeba/pseudo_clf_train_celeba.py /kaggle/working/hijackgan\n!cp /kaggle/input/model-files-celeba/generate_balanced_data_celeba.py /kaggle/working/hijackgan\n!cp /kaggle/input/model-files-celeba/pseudo_classifier.py /kaggle/working/hijackgan/models\n!cp /kaggle/input/model-files-celeba/model_settings.py /kaggle/working/hijackgan/models\n!cp /kaggle/input/model-files-celeba/base_generator.py /kaggle/working/hijackgan/models\n!cp /kaggle/input/logger/logger.py /kaggle/working/hijackgan/utils","metadata":{"execution":{"iopub.status.busy":"2024-05-17T04:16:26.950868Z","iopub.execute_input":"2024-05-17T04:16:26.951215Z","iopub.status.idle":"2024-05-17T04:16:28.866504Z","shell.execute_reply.started":"2024-05-17T04:16:26.951185Z","shell.execute_reply":"2024-05-17T04:16:28.865395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install tensorflow==1.14.0 torch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 opencv-python==3.4.2.17 scikit-learn==0.23.2 transformers==4.30.2 tqdm","metadata":{"execution":{"iopub.status.busy":"2024-05-17T06:23:01.337225Z","iopub.execute_input":"2024-05-17T06:23:01.337616Z","iopub.status.idle":"2024-05-17T06:25:05.053465Z","shell.execute_reply.started":"2024-05-17T06:23:01.337583Z","shell.execute_reply":"2024-05-17T06:25:05.052555Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install git+https://github.com/lukemelas/pytorch-pretrained-gans","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!set CUDA_VISIBLE_DEVICES=0 & python pseudo_clf_train_data_celeba.py -m  pggan_celebahq -o ./generated_data_celeba -i ./generated_data_celeba/latent_codes_celeba_60.npy -n 50000 -t ../data/celebahq_60_test.csv -d ../data/celebahq_test -tf ./generated_data_celeba/test_features_celeba_60.hdf5 -clf ./models/resnet50_celebahq -fb 8 -gf --batch_size 8 --clf_outputs_path ./generated_data_celeba/clf_outputs_celeba_60.pkl ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!set CUDA_VISIBLE_DEVICES=0 & python pseudo_clf_train_celeba.py -tf ./generated_data_celeba/test_features_celeba_60.hdf5 --clf_outputs_path ./generated_data_celeba/clf_outputs_celeba_60.pkl --num_classes 2","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!set CUDA_VISIBLE_DEVICES=0 & python generate_balanced_data_celeba.py -m  pggan_celebahq -o ./generated_data_celeba -K ./generated_data_celeba/indices_celeba_60.pkl -sc ./generated_data_celeba/scores_celeba_60.pkl -i ./generated_data_celeba/z_celeba_60.npy -sl ./generated_data_celeba/soft_labels_celeba_60.npz --threshold 0.1 -n 20000 -SI 0 -t ../data/celebahq_60_test.csv -d ../data/celebahq_test -tf ./generated_data_celeba/test_features_celeba_60.hdf5 -clf ./models/resnet50_celebahq --clf_outputs_path ./generated_data_celeba/clf_outputs_celeba_60.pkl --batch_size 8 --samples_dir sample_images  ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !set CUDA_VISIBLE_DEVICES=0 & python pseudo_clf_train_data.py -m  pggan_celebahq -o ./generated_data -n 50000 -t ../data/gender_clf_smaller_test.csv -d ../data/gender_clf_dataset -tf test_features1.hdf5 -clf ./models/pretrain/face_gender_classification_transfer_learning_with_ResNet50_resolution_224.pth -fb 16 -gf","metadata":{"execution":{"iopub.status.busy":"2024-05-17T04:16:30.264608Z","iopub.execute_input":"2024-05-17T04:16:30.265003Z","iopub.status.idle":"2024-05-17T04:54:53.167479Z","shell.execute_reply.started":"2024-05-17T04:16:30.264965Z","shell.execute_reply":"2024-05-17T04:54:53.166269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !python pseudo_clf_train.py -tf test_features1.hdf5","metadata":{"execution":{"iopub.status.busy":"2024-05-17T06:52:15.621697Z","iopub.execute_input":"2024-05-17T06:52:15.622074Z","iopub.status.idle":"2024-05-17T06:52:19.393798Z","shell.execute_reply.started":"2024-05-17T06:52:15.622042Z","shell.execute_reply":"2024-05-17T06:52:19.392691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !set CUDA_VISIBLE_DEVICES=0 & python generate_balanced_data.py -m pggan_celebahq -o ./generated_data -K ./generated_data/indices.pkl -sc ./generated_data/scores.pkl --threshold 0.1 -n 50000 -SI 0 -t ../data/gender_clf_smaller_test.csv -d ../data/gender_clf_dataset -tf test_features1.hdf5 -clf ./models/pretrain/face_gender_classification_transfer_learning_with_ResNet50_resolution_224.pth","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# !set CUDA_VISIBLE_DEVICES=0 & python evaluation.py --model_name pggan_celebahq -o ./evaluation_data -c ./generated_data1/z.npy -s ./generated_data1/scores.pkl -i ./generated_data1/indices.pkl -tf test_features1.hdf5 -sl ./generated_data1/soft_labels.npy -t ../data/gender_clf_50_test.csv -d ../data/gender_clf_dataset -co clf_outputs1.pkl -m 1000 --delta 0.5 --save_path generator_loss.csv -clf ./models/pretrain/face_gender_classification_transfer_learning_with_ResNet50_resolution_224.pth -ll ./models/pretrain/face_gender_classification_transfer_learning_with_pretrained_ResNet50_resolution_224.pth -mi chosen_indices.pkl","metadata":{},"execution_count":null,"outputs":[]}]}