Press enter or space to select a node.You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.
Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
'''
---BlockAI/DarkNet53 Auto Generate Code---
Author : BlockAI
Project Name: DarkNet53
Project Link: https://blockai.kr/BlockAI/DarkNet53 (BlockAI)
Create Date : 2024-10-05
---Requirements---
# 사용자의 환경(OS, CUDA 등)에 따라 라이브러리 버전을 맞춰주세요
pip install torch==2.0 torchvision==0.15.2 torchtext==0.15.2 torchaudio==2.0.2
pip install pytorch-lightning==2.0.4
pip install tqdm
pip install pandas
pip install scikit-learn
pip install transformers
pip install timm
---Folder Structure---
--📂 data
|--📂 train
|--📁 LABEL_NAME_1
|--🖼️ IMAGE_FILE
|--🖼️ IMAGE_FILE
|--🖼️ ...
|--📁 LABEL_NAME_2
|--🖼️ IMAGE_FILE
|--🖼️ IMAGE_FILE
|--🖼️ ...
|--📁 ...
|--📂 test
|--📁 LABEL_NAME_1
|--🖼️ IMAGE_FILE
|--🖼️ IMAGE_FILE
|--🖼️ ...
|--📁 LABEL_NAME_2
|--🖼️ IMAGE_FILE
|--🖼️ IMAGE_FILE
|--🖼️ ...
|--📁 ...
--📄 DarkNet53.py
--📄 DarkNet53.ipynb
--📄 requirements.txt
'''
import os
import argparse
import copy
from glob import glob
from tqdm import tqdm
import numpy as np
import pandas as pd
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from PIL import Image
import torch
import pytorch_lightning as pl
import torchvision
path_sep = os.sep
# https://pytorch.org/tutorials/beginner/basics/data_tutorial.html#creating-a-custom-dataset-for-your-files
class Dataset(torch.utils.data.Dataset):
def __init__(self, inputs, targets=[], input_transform=None):
self.inputs = inputs
self.targets = targets
self.input_transform = input_transform
# 학습 및 추론 과정에서 데이터를 1개씩 꺼내오는 곳
def __getitem__(self, idx):
# 정답이 있다면 if문을, 없다면 else문을 수행합니다
if len(self.targets) == 0:
return self.input_transform(Image.open(self.inputs[idx]))
else:
return self.input_transform(Image.open(self.inputs[idx])), torch.tensor(self.targets[idx])
# 입력하는 개수만큼 데이터를 사용합니다
# 'return 100'이면 1에폭에 100개의 데이터만 사용합니다
def __len__(self):
return len(self.inputs)
# https://pytorch-lightning.readthedocs.io/en/stable/extensions/datamodules.html
class Dataloader(pl.LightningDataModule):
# 데이터의 종류에 따라 코드 수정이 필요할 수 있습니다
def __init__(self, data_folder, batch_size, train_ratio, shuffle):
super().__init__()
self.data_folder = data_folder
self.batch_size = batch_size
self.train_ratio = train_ratio
self.shuffle = shuffle
self.train_dataset = None
self.test_dataset = None
self.predict_dataset = None
def get_inputs_targets(self, data):
inputs = []
targets = []
for data_path in data:
# 이미지 경로를 저장합니다
inputs.append(data_path)
# 이미지 경로에서 타겟 값을 분리하여 저장합니다
targets.append(data_path.split(path_sep)[-2])
return inputs, targets
def setup(self, stage='fit'):
# train 폴더에 있는 모든 이미지 경로를 받아와서 데이터셋을 만듭니다
train_data = sorted(glob(os.path.join(self.data_folder, 'train', '*', '*')))
train_inputs, train_targets = self.get_inputs_targets(train_data)
# test 폴더에 있는 모든 이미지 경로를 받아와서 데이터셋을 만듭니다
test_data = sorted(glob(os.path.join(self.data_folder, 'test', '*', '*')))
test_inputs, test_targets = self.get_inputs_targets(test_data)
# target 값을 encoding 해줍니다
self.target_encoder = preprocessing.LabelEncoder()
train_targets = self.target_encoder.fit_transform(train_targets)
test_targets = self.target_encoder.transform(test_targets)
train_transform = torchvision.transforms.Compose([
])
test_transform = torchvision.transforms.Compose([
])
self.train_dataset = Dataset(train_inputs, train_targets, train_transform)
self.test_dataset = Dataset(test_inputs, test_targets, test_transform)
self.predict_dataset = Dataset(test_inputs, [], test_transform)
def train_dataloader(self):
return torch.utils.data.DataLoader(self.train_dataset, batch_size=self.batch_size, shuffle=args.shuffle)
def test_dataloader(self):
return torch.utils.data.DataLoader(self.test_dataset, batch_size=self.batch_size)
def predict_dataloader(self):
return torch.utils.data.DataLoader(self.predict_dataset, batch_size=self.batch_size)
# https://pytorch-lightning.readthedocs.io/en/stable/common/lightning_module.html
class Model(pl.LightningModule):
def __init__(self):
super().__init__()
self.save_hyperparameters()
self.conv2d_1 = torch.nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, padding=1)
self.batchnorm2d_1 = torch.nn.BatchNorm2d(num_features=32)
self.conv2d_2 = torch.nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_2 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_3 = torch.nn.Conv2d(in_channels=64, out_channels=32, kernel_size=1, padding=0)
self.batchnorm2d_3 = torch.nn.BatchNorm2d(num_features=32)
self.conv2d_4 = torch.nn.Conv2d(in_channels=32, out_channels=64, kernel_size=3, padding=1)
self.batchnorm2d_4 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_5 = torch.nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_5 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_6 = torch.nn.Conv2d(in_channels=128, out_channels=64, kernel_size=1, padding=0)
self.batchnorm2d_6 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_7 = torch.nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, padding=1)
self.batchnorm2d_7 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_8 = torch.nn.Conv2d(in_channels=128, out_channels=64, kernel_size=1, padding=0)
self.batchnorm2d_8 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_9 = torch.nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, padding=1)
self.batchnorm2d_9 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_10 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_10 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_11 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_11 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_12 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_12 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_13 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_13 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_14 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_14 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_15 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_15 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_16 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_16 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_17 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_17 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_18 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_18 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_19 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_19 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_20 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_20 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_21 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_21 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_22 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_22 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_23 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_23 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_24 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_24 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_25 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, padding=0)
self.batchnorm2d_25 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_26 = torch.nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, padding=1)
self.batchnorm2d_26 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_27 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_27 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_28 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_28 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_29 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_29 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_30 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_30 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_31 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_31 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_32 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_32 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_33 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_33 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_34 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_34 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_35 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_35 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_36 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_36 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_37 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_37 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_38 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_38 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_39 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_39 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_40 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_40 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_41 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_41 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_42 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, padding=0)
self.batchnorm2d_42 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_43 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, padding=1)
self.batchnorm2d_43 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_44 = torch.nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_44 = torch.nn.BatchNorm2d(num_features=1024)
self.conv2d_45 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, padding=0)
self.batchnorm2d_45 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_46 = torch.nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, padding=1)
self.batchnorm2d_46 = torch.nn.BatchNorm2d(num_features=1024)
self.conv2d_47 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, padding=0)
self.batchnorm2d_47 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_48 = torch.nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, padding=1)
self.batchnorm2d_48 = torch.nn.BatchNorm2d(num_features=1024)
self.conv2d_49 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, padding=0)
self.batchnorm2d_49 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_50 = torch.nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, padding=1)
self.batchnorm2d_50 = torch.nn.BatchNorm2d(num_features=1024)
self.conv2d_51 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, padding=0)
self.batchnorm2d_51 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_52 = torch.nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, padding=1)
self.batchnorm2d_52 = torch.nn.BatchNorm2d(num_features=1024)
self.avgpool2d_1 = torch.nn.AvgPool2d(kernel_size=8, stride=1)
self.linear_1 = torch.nn.Linear(in_features=1024, out_features=1000)
self.leakyrelu_1 = torch.nn.LeakyReLU(negative_slope=0.1, inplace=True)
self.softmax_1 = torch.nn.Softmax()
def forward(self, x_emptyimage):
x_0 = self.conv2d_1(x_emptyimage)
x_0 = self.batchnorm2d_1(x_0)
x_0 = self.leakyrelu_1(x_0)
x_0 = self.conv2d_2(x_0)
x_0 = self.batchnorm2d_2(x_0)
x_0 = self.leakyrelu_1(x_0)
x_0 = self.conv2d_3(x_0)
x_0 = self.batchnorm2d_3(x_0)
x_0 = self.leakyrelu_1(x_0)
x_0 = self.conv2d_4(x_0)
x_0 = self.batchnorm2d_4(x_0)
x_0 = self.leakyrelu_1(x_0)
x_1 = torch.add((x_0, x_0), other=0)
x_1 = self.conv2d_5(x_1)
x_1 = self.batchnorm2d_5(x_1)
x_1 = self.leakyrelu_1(x_1)
x_1 = self.conv2d_6(x_1)
x_1 = self.batchnorm2d_6(x_1)
x_1 = self.leakyrelu_1(x_1)
x_1 = self.conv2d_7(x_1)
x_1 = self.batchnorm2d_7(x_1)
x_1 = self.leakyrelu_1(x_1)
x_2 = torch.add((x_1, x_1))
x_2 = self.conv2d_8(x_2)
x_2 = self.batchnorm2d_8(x_2)
x_2 = self.leakyrelu_1(x_2)
x_2 = self.conv2d_9(x_2)
x_2 = self.batchnorm2d_9(x_2)
x_2 = self.leakyrelu_1(x_2)
x_3 = torch.add((x_2, x_2))
x_3 = self.conv2d_10(x_3)
x_3 = self.batchnorm2d_10(x_3)
x_3 = self.leakyrelu_1(x_3)
x_3 = self.conv2d_11(x_3)
x_3 = self.batchnorm2d_11(x_3)
x_3 = self.leakyrelu_1(x_3)
x_3 = self.conv2d_12(x_3)
x_3 = self.batchnorm2d_12(x_3)
x_3 = self.leakyrelu_1(x_3)
x_3 = torch.add(x_3)
x_3 = self.conv2d_13(x_3)
x_3 = self.batchnorm2d_13(x_3)
x_3 = self.leakyrelu_1(x_3)
x_3 = self.conv2d_14(x_3)
x_3 = self.batchnorm2d_14(x_3)
x_3 = self.leakyrelu_1(x_3)
x_4 = torch.add((x_3, x_3))
x_4 = self.conv2d_15(x_4)
x_4 = self.batchnorm2d_15(x_4)
x_4 = self.leakyrelu_1(x_4)
x_4 = self.conv2d_16(x_4)
x_4 = self.batchnorm2d_16(x_4)
x_4 = self.leakyrelu_1(x_4)
x_5 = torch.add((x_4, x_4))
x_5 = self.conv2d_17(x_5)
x_5 = self.batchnorm2d_17(x_5)
x_5 = self.leakyrelu_1(x_5)
x_5 = self.conv2d_18(x_5)
x_5 = self.batchnorm2d_18(x_5)
x_5 = self.leakyrelu_1(x_5)
x_6 = torch.add((x_5, x_5))
x_6 = self.conv2d_19(x_6)
x_6 = self.batchnorm2d_19(x_6)
x_6 = self.leakyrelu_1(x_6)
x_6 = self.conv2d_20(x_6)
x_6 = self.batchnorm2d_20(x_6)
x_6 = self.leakyrelu_1(x_6)
x_7 = torch.add((x_6, x_6))
x_7 = self.conv2d_21(x_7)
x_7 = self.batchnorm2d_21(x_7)
x_7 = self.leakyrelu_1(x_7)
x_7 = self.conv2d_22(x_7)
x_7 = self.batchnorm2d_22(x_7)
x_7 = self.leakyrelu_1(x_7)
x_8 = torch.add((x_7, x_7))
x_8 = self.conv2d_23(x_8)
x_8 = self.batchnorm2d_23(x_8)
x_8 = self.leakyrelu_1(x_8)
x_8 = self.conv2d_24(x_8)
x_8 = self.batchnorm2d_24(x_8)
x_8 = self.leakyrelu_1(x_8)
x_9 = torch.add((x_8, x_8))
x_9 = self.conv2d_25(x_9)
x_9 = self.batchnorm2d_25(x_9)
x_9 = self.leakyrelu_1(x_9)
x_9 = self.conv2d_26(x_9)
x_9 = self.batchnorm2d_26(x_9)
x_9 = self.leakyrelu_1(x_9)
x_10 = torch.add((x_9, x_9))
x_10 = self.conv2d_27(x_10)
x_10 = self.batchnorm2d_27(x_10)
x_10 = self.leakyrelu_1(x_10)
x_10 = self.conv2d_28(x_10)
x_10 = self.batchnorm2d_28(x_10)
x_10 = self.leakyrelu_1(x_10)
x_10 = self.conv2d_29(x_10)
x_10 = self.batchnorm2d_29(x_10)
x_10 = self.leakyrelu_1(x_10)
x_11 = torch.add((x_10, x_10))
x_11 = self.conv2d_30(x_11)
x_11 = self.batchnorm2d_30(x_11)
x_11 = self.leakyrelu_1(x_11)
x_11 = self.conv2d_31(x_11)
x_11 = self.batchnorm2d_31(x_11)
x_11 = self.leakyrelu_1(x_11)
x_12 = torch.add((x_11, x_11))
x_12 = self.conv2d_32(x_12)
x_12 = self.batchnorm2d_32(x_12)
x_12 = self.leakyrelu_1(x_12)
x_12 = self.conv2d_33(x_12)
x_12 = self.batchnorm2d_33(x_12)
x_12 = self.leakyrelu_1(x_12)
x_13 = torch.add((x_12, x_12))
x_13 = self.conv2d_34(x_13)
x_13 = self.batchnorm2d_34(x_13)
x_13 = self.leakyrelu_1(x_13)
x_13 = self.conv2d_35(x_13)
x_13 = self.batchnorm2d_35(x_13)
x_13 = self.leakyrelu_1(x_13)
x_14 = torch.add((x_13, x_13))
x_14 = self.conv2d_36(x_14)
x_14 = self.batchnorm2d_36(x_14)
x_14 = self.leakyrelu_1(x_14)
x_14 = self.conv2d_37(x_14)
x_14 = self.batchnorm2d_37(x_14)
x_14 = self.leakyrelu_1(x_14)
x_15 = torch.add((x_14, x_14))
x_15 = self.conv2d_38(x_15)
x_15 = self.batchnorm2d_38(x_15)
x_15 = self.leakyrelu_1(x_15)
x_15 = self.conv2d_39(x_15)
x_15 = self.batchnorm2d_39(x_15)
x_15 = self.leakyrelu_1(x_15)
x_16 = torch.add((x_15, x_15))
x_16 = self.conv2d_40(x_16)
x_16 = self.batchnorm2d_40(x_16)
x_16 = self.leakyrelu_1(x_16)
x_16 = self.conv2d_41(x_16)
x_16 = self.batchnorm2d_41(x_16)
x_16 = self.leakyrelu_1(x_16)
x_17 = torch.add((x_16, x_16))
x_17 = self.conv2d_42(x_17)
x_17 = self.batchnorm2d_42(x_17)
x_17 = self.leakyrelu_1(x_17)
x_17 = self.conv2d_43(x_17)
x_17 = self.batchnorm2d_43(x_17)
x_17 = self.leakyrelu_1(x_17)
x_18 = torch.add((x_17, x_17))
x_18 = self.conv2d_44(x_18)
x_18 = self.batchnorm2d_44(x_18)
x_18 = self.leakyrelu_1(x_18)
x_18 = self.conv2d_45(x_18)
x_18 = self.batchnorm2d_45(x_18)
x_18 = self.leakyrelu_1(x_18)
x_18 = self.conv2d_46(x_18)
x_18 = self.batchnorm2d_46(x_18)
x_18 = self.leakyrelu_1(x_18)
x_18 = torch.add(x_18)
x_18 = self.conv2d_47(x_18)
x_18 = self.batchnorm2d_47(x_18)
x_18 = self.leakyrelu_1(x_18)
x_18 = self.conv2d_48(x_18)
x_18 = self.batchnorm2d_48(x_18)
x_18 = self.leakyrelu_1(x_18)
x_19 = torch.add((x_18, x_18))
x_19 = self.conv2d_49(x_19)
x_19 = self.batchnorm2d_49(x_19)
x_19 = self.leakyrelu_1(x_19)
x_19 = self.conv2d_50(x_19)
x_19 = self.batchnorm2d_50(x_19)
x_19 = self.leakyrelu_1(x_19)
x_20 = torch.add((x_19, x_19))
x_20 = self.conv2d_51(x_20)
x_20 = self.batchnorm2d_51(x_20)
x_20 = self.leakyrelu_1(x_20)
x_20 = self.conv2d_52(x_20)
x_20 = self.batchnorm2d_52(x_20)
x_20 = self.leakyrelu_1(x_20)
x_21 = torch.add((x_20, x_20))
x_21 = self.avgpool2d_1(x_21)
x_21 = torch.flatten(x_21)
x_21 = self.linear_1(x_21)
x_21 = self.softmax_1(x_21)
return
def training_step(self, batch, batch_idx):
x_emptyimage, y = batch
logits = self(x_emptyimage)
self.log("train_loss", loss)
return loss
def validation_step(self, batch, batch_idx):
x_emptyimage, y = batch
logits = self(x_emptyimage)
self.log("val_loss", loss)
return loss
def test_step(self, batch, batch_idx):
x_emptyimage, y = batch
logits = self(x_emptyimage)
self.log("test_loss", loss)
return loss
def predict_step(self, batch, batch_idx):
x_emptyimage = batch
logits = self(x_emptyimage)
return logits
def configure_optimizers(self):
pass
if __name__ == '__main__':
# https://docs.python.org/ko/3/library/argparse.html
# 하이퍼 파라미터 등 각종 설정값을 입력받습니다
# 터미널 실행 예시 : python3 run.py --batch_size=64 ...
# 실행 시 '--batch_size=64' 같은 인자를 입력하지 않으면 default 값이 기본으로 실행됩니다
parser = argparse.ArgumentParser()
parser.add_argument('--data_folder', default='./data')
parser.add_argument('--batch_size', default=0)
parser.add_argument('--max_epoch', default=0)
parser.add_argument('--shuffle', default=False)
parser.add_argument('--train_ratio', default=1.0)
args = parser.parse_args()
dataloader = Dataloader(args.data_folder, args.batch_size, args.train_ratio, args.shuffle)
model = Model()
# https://pytorch-lightning.readthedocs.io/en/stable/common/trainer.html
# 학습 및 추론을 위한 Trainer 설정
trainer = pl.Trainer(accelerator='gpu', devices=1, max_epochs=args.max_epoch)
trainer.fit(model=model, datamodule=dataloader)
# trainer.test(model=model, datamodule=dataloader)
# predictions = trainer.predict(model=model, datamodule=dataloader)