|
67 | 67 | "cell_type": "code",
|
68 | 68 | "execution_count": 5,
|
69 | 69 | "metadata": {},
|
70 |
| - "outputs": [ |
71 |
| - { |
72 |
| - "name": "stdout", |
73 |
| - "output_type": "stream", |
74 |
| - "text": [ |
75 |
| - "t\n", |
76 |
| - "t_unit\n", |
77 |
| - "readings\n", |
78 |
| - "idx_anomaly\n", |
79 |
| - "idx_split\n", |
80 |
| - "training\n", |
81 |
| - "test\n", |
82 |
| - "train_m\n", |
83 |
| - "train_std\n", |
84 |
| - "t_train\n", |
85 |
| - "t_test\n", |
86 |
| - "idx_anomaly_test\n" |
87 |
| - ] |
88 |
| - }, |
89 |
| - { |
90 |
| - "name": "stderr", |
91 |
| - "output_type": "stream", |
92 |
| - "text": [ |
93 |
| - "/home/gg/.local/share/virtualenvs/ts_vae-lstm-hz-Oy2CQ/lib/python3.9/site-packages/torch/cuda/__init__.py:107: UserWarning: CUDA initialization: CUDA unknown error - this may be due to an incorrectly set up environment, e.g. changing env variable CUDA_VISIBLE_DEVICES after program start. Setting the available devices to be zero. (Triggered internally at ../c10/cuda/CUDAFunctions.cpp:109.)\n", |
94 |
| - " return torch._C._cuda_getDeviceCount() > 0\n" |
95 |
| - ] |
96 |
| - } |
97 |
| - ], |
| 70 | + "outputs": [], |
98 | 71 | "source": [
|
99 | 72 | "# | export\n",
|
100 | 73 | "from ts_vae_lstm.vae import VAE, Encoder, Decoder, StochasticSampler\n",
|
|
108 | 81 | "cell_type": "code",
|
109 | 82 | "execution_count": 6,
|
110 | 83 | "metadata": {},
|
| 84 | + "outputs": [], |
| 85 | + "source": [ |
| 86 | + "# for configs\n", |
| 87 | + "from hydra import compose, initialize\n", |
| 88 | + "from omegaconf import OmegaConf\n", |
| 89 | + "from fastcore.xtras import Path\n", |
| 90 | + "import os\n", |
| 91 | + "import glob" |
| 92 | + ] |
| 93 | + }, |
| 94 | + { |
| 95 | + "cell_type": "code", |
| 96 | + "execution_count": 7, |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "# run only once\n", |
| 101 | + "try:\n", |
| 102 | + " initialize(config_path=\"../config\", version_base=\"1.2\")\n", |
| 103 | + " cfg = compose(config_name=\"config.yaml\")\n", |
| 104 | + " cfg = OmegaConf.to_object(cfg) # perform interpolation of the variables also\n", |
| 105 | + " cfg = OmegaConf.create(cfg) # so that dot-notation works?\n", |
| 106 | + " cfg.base_dir = \"..\" # to make it work in the notebook\n", |
| 107 | + "except Exception as e:\n", |
| 108 | + " print(f\"Got Exception while reading config:\\n{e}\")" |
| 109 | + ] |
| 110 | + }, |
| 111 | + { |
| 112 | + "cell_type": "code", |
| 113 | + "execution_count": 8, |
| 114 | + "metadata": {}, |
111 | 115 | "outputs": [
|
112 | 116 | {
|
113 | 117 | "name": "stdout",
|
114 | 118 | "output_type": "stream",
|
115 | 119 | "text": [
|
116 |
| - "LSTM model: /run/media/data2/ts_vae-lstm/models/lstm_100_val0.81.pth\n", |
117 |
| - "VAE model: /run/media/data2/ts_vae-lstm/models/vae_100_z24.pth\n" |
| 120 | + "Number of workers: 4\n" |
118 | 121 | ]
|
119 | 122 | }
|
120 | 123 | ],
|
121 | 124 | "source": [
|
122 |
| - "load_dotenv()\n", |
123 |
| - "\n", |
124 |
| - "BASEDIR = os.getenv(\"BASEDIR\")\n", |
125 |
| - "MODELDIR = os.getenv(\"MODELDIR\")\n", |
126 |
| - "VAE_MODEL = os.getenv(\"VAE_MODEL\")\n", |
127 |
| - "LSTM_MODEL = os.getenv(\"LSTM_MODEL\")\n", |
128 |
| - "\n", |
129 |
| - "print(f\"LSTM model: {LSTM_MODEL}\\nVAE model: {VAE_MODEL}\")" |
| 125 | + "num_workers = cfg.num_workers if cfg.get(\"num_workers\", None) else os.cpu_count()\n", |
| 126 | + "print(f\"Number of workers: {num_workers}\")" |
130 | 127 | ]
|
131 | 128 | },
|
132 | 129 | {
|
133 | 130 | "cell_type": "code",
|
134 |
| - "execution_count": 7, |
| 131 | + "execution_count": 9, |
135 | 132 | "metadata": {},
|
136 | 133 | "outputs": [
|
137 | 134 | {
|
138 | 135 | "data": {
|
139 | 136 | "text/plain": [
|
140 |
| - "(4, 'cpu')" |
| 137 | + "'cuda'" |
141 | 138 | ]
|
142 | 139 | },
|
143 |
| - "execution_count": 7, |
| 140 | + "execution_count": 9, |
144 | 141 | "metadata": {},
|
145 | 142 | "output_type": "execute_result"
|
146 | 143 | }
|
147 | 144 | ],
|
148 | 145 | "source": [
|
149 |
| - "num_workers = os.cpu_count()\n", |
150 |
| - "device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n", |
151 |
| - "num_workers, device" |
| 146 | + "device = cfg.device if cfg.device else (\"cuda\" if torch.cuda.is_available() else \"cpu\")\n", |
| 147 | + "device" |
| 148 | + ] |
| 149 | + }, |
| 150 | + { |
| 151 | + "cell_type": "code", |
| 152 | + "execution_count": 10, |
| 153 | + "metadata": {}, |
| 154 | + "outputs": [ |
| 155 | + { |
| 156 | + "data": { |
| 157 | + "text/plain": [ |
| 158 | + "'..'" |
| 159 | + ] |
| 160 | + }, |
| 161 | + "execution_count": 10, |
| 162 | + "metadata": {}, |
| 163 | + "output_type": "execute_result" |
| 164 | + } |
| 165 | + ], |
| 166 | + "source": [ |
| 167 | + "cfg.base_dir" |
| 168 | + ] |
| 169 | + }, |
| 170 | + { |
| 171 | + "cell_type": "code", |
| 172 | + "execution_count": 11, |
| 173 | + "metadata": {}, |
| 174 | + "outputs": [ |
| 175 | + { |
| 176 | + "name": "stdout", |
| 177 | + "output_type": "stream", |
| 178 | + "text": [ |
| 179 | + "Base directory: /run/media/data2/ts_vae-lstm\n", |
| 180 | + "Model directory: /run/media/data2/ts_vae-lstm/models\n", |
| 181 | + "Dataset is /run/media/data2/ts_vae-lstm/sample_data/nyc_taxi.npz\n", |
| 182 | + "VAE model: /run/media/data2/ts_vae-lstm/models/best_vae_*_z24_*.pth\n", |
| 183 | + "LSTM model: /run/media/data2/ts_vae-lstm/models/best_lstm_*_z24_*.pth\n" |
| 184 | + ] |
| 185 | + } |
| 186 | + ], |
| 187 | + "source": [ |
| 188 | + "BASEDIR = Path(cfg.base_dir).resolve()\n", |
| 189 | + "MODELDIR = Path(\".\" + cfg.model_dir).resolve() # to move to project root\n", |
| 190 | + "DATAPATH = Path(\".\" + cfg.dataset.path).resolve() # to move to project root\n", |
| 191 | + "VAE_MODEL = Path(\".\" + cfg.vae_path).resolve() # to move to project root\n", |
| 192 | + "LSTM_MODEL = Path(\".\" + cfg.lstm_path).resolve()\n", |
| 193 | + "print(f\"Base directory: {BASEDIR}\")\n", |
| 194 | + "print(f\"Model directory: {MODELDIR}\")\n", |
| 195 | + "print(f\"Dataset is {DATAPATH}\")\n", |
| 196 | + "print(f\"VAE model: {VAE_MODEL}\")\n", |
| 197 | + "print(f\"LSTM model: {LSTM_MODEL}\")\n" |
| 198 | + ] |
| 199 | + }, |
| 200 | + { |
| 201 | + "cell_type": "code", |
| 202 | + "execution_count": 12, |
| 203 | + "metadata": {}, |
| 204 | + "outputs": [ |
| 205 | + { |
| 206 | + "name": "stdout", |
| 207 | + "output_type": "stream", |
| 208 | + "text": [ |
| 209 | + "/run/media/data2/ts_vae-lstm/models/best_vae_100_z24_1733051559.pth\n" |
| 210 | + ] |
| 211 | + } |
| 212 | + ], |
| 213 | + "source": [ |
| 214 | + "if cfg.pattern:\n", |
| 215 | + " paths = glob.glob(f\"{VAE_MODEL}\")\n", |
| 216 | + " latest_path = paths[0]\n", |
| 217 | + " latest_time = 0\n", |
| 218 | + " for path in paths:\n", |
| 219 | + " if os.path.getmtime(path) > latest_time:\n", |
| 220 | + " latest_path = path\n", |
| 221 | + " latest_time = os.path.getmtime(path)\n", |
| 222 | + " VAE_MODEL = latest_path\n", |
| 223 | + " print(VAE_MODEL)" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": 13, |
| 229 | + "metadata": {}, |
| 230 | + "outputs": [ |
| 231 | + { |
| 232 | + "name": "stdout", |
| 233 | + "output_type": "stream", |
| 234 | + "text": [ |
| 235 | + "/run/media/data2/ts_vae-lstm/models/best_lstm_100_z24_1733058653.pth\n" |
| 236 | + ] |
| 237 | + } |
| 238 | + ], |
| 239 | + "source": [ |
| 240 | + "if cfg.pattern:\n", |
| 241 | + " paths = glob.glob(f\"{LSTM_MODEL}\")\n", |
| 242 | + " latest_path = paths[0]\n", |
| 243 | + " latest_time = 0\n", |
| 244 | + " for path in paths:\n", |
| 245 | + " if os.path.getmtime(path) > latest_time:\n", |
| 246 | + " latest_path = path\n", |
| 247 | + " latest_time = os.path.getmtime(path)\n", |
| 248 | + " LSTM_MODEL = latest_path\n", |
| 249 | + " print(LSTM_MODEL)" |
152 | 250 | ]
|
153 | 251 | },
|
154 | 252 | {
|
|
0 commit comments