File size: 3,651 Bytes
8da91c9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "d6299e4c-f1ba-4be4-ac89-63c05287387c",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/admin/home-devforfu/realfake\n"
]
}
],
"source": [
"%cd .."
]
},
{
"cell_type": "code",
"execution_count": 20,
"id": "8729a815-81b7-4667-bb97-c85456ad86e8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"from pathlib import Path\n",
"import numpy as np\n",
"import pandas as pd\n",
"from sklearn.model_selection import train_test_split\n",
"from realfake.utils import list_files, write_jsonl"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "82fa1fee-3ea0-415e-8a6a-8622bc55fabd",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"root = Path(\"/fsx/home-devforfu/data\")\n",
"laion = list_files(root/\"laionimages\", [\"jpg\"])\n",
"movie = list_files(root/\"shotcafe\", [\"jpg\"])"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "58d79304-bdf0-445d-b5dd-46bd2a7bf1ec",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"(5133, 7526)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(laion), len(movie)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "f78ced08-3a5a-48f8-a635-6d93e82856c1",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"n_test = 0.1"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "7a89dac3-cc8f-46cf-b60a-9118121ff69a",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"tst = set(train_test_split(np.arange(len(laion)), test_size=n_test)[1])\n",
"metadata = [{\"path\": str(fn), \"label\": \"real\", \"valid\": i in tst} for i, fn in enumerate(laion)]\n",
"tst = set(train_test_split(np.arange(len(movie)), test_size=n_test)[1])\n",
"metadata += [{\"path\": str(fn), \"label\": \"fake\", \"valid\": i in tst} for i, fn in enumerate(movie)]"
]
},
{
"cell_type": "code",
"execution_count": 25,
"id": "b0da02f5-eec6-4114-81fa-901aef933d72",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False 11392\n",
"True 1267\n",
"Name: valid, dtype: int64\n",
"fake 7526\n",
"real 5133\n",
"Name: label, dtype: int64\n"
]
}
],
"source": [
"df = pd.DataFrame(metadata)\n",
"print(df.valid.value_counts())\n",
"print(df.label.value_counts())"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "bdad7b5a-17de-424b-8bfb-d13fe197552b",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"write_jsonl(\"metadata/movies.jsonl\", metadata)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "428dda09-77b8-4f6c-b14e-059e9d281f9a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|