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
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
'''
---BlockAI/YoLoV5L Auto Generate Code---
Author : BlockAI
Project Name: YoLoV5L
Project Link: https://blockai.kr/BlockAI/YoLoV5L (BlockAI)
Create Date : 2024-10-14
---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
|--🖼️ ...
|--📁 ...
--📄 YoLoV5L.py
--📄 YoLoV5L.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=64, kernel_size=6, stride=2, padding=2)
self.batchnorm2d_1 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_2 = torch.nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_2 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_3 = torch.nn.Conv2d(in_channels=128, out_channels=64, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_3 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_4 = torch.nn.Conv2d(in_channels=128, out_channels=64, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_4 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_5 = torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_5 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_6 = torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_6 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_7 = torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_7 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_8 = torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_8 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_9 = torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_9 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_10 = torch.nn.Conv2d(in_channels=64, out_channels=64, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_10 = torch.nn.BatchNorm2d(num_features=64)
self.conv2d_11 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=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, stride=2, 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, stride=1, padding=0)
self.batchnorm2d_13 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_14 = torch.nn.Conv2d(in_channels=256, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_14 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_15 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_15 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_16 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_16 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_17 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_17 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_18 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_18 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_19 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_19 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_20 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_20 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_21 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_21 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_22 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_22 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_23 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_23 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_24 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_24 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_25 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_25 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_26 = torch.nn.Conv2d(in_channels=128, out_channels=128, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_26 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_27 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_27 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_28 = torch.nn.Conv2d(in_channels=256, out_channels=512, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_28 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_29 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_29 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_30 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_30 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_31 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_31 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_32 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_32 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_33 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_33 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_34 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_34 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_35 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_35 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_36 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_36 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_37 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_37 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_38 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_38 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_39 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_39 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_40 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_40 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_41 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_41 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_42 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_42 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_43 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_43 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_44 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_44 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_45 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_45 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_46 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_46 = torch.nn.BatchNorm2d(num_features=128)
self.conv2d_47 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_47 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_48 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_48 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_49 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_49 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_50 = torch.nn.Conv2d(in_channels=512, out_channels=1024, kernel_size=3, stride=2, 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, stride=1, padding=0)
self.batchnorm2d_51 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_52 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_52 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_53 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_53 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_54 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_54 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_55 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_55 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_56 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_56 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_57 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_57 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_58 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_58 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_59 = torch.nn.Conv2d(in_channels=1024, out_channels=1024, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_59 = torch.nn.BatchNorm2d(num_features=1024)
self.maxpool2d_1 = torch.nn.MaxPool2d(kernel_size=5, stride=1, padding=2)
self.maxpool2d_2 = torch.nn.MaxPool2d(kernel_size=5, stride=1, padding=2)
self.maxpool2d_3 = torch.nn.MaxPool2d(kernel_size=5, stride=1, padding=2)
self.maxpool2d_4 = torch.nn.MaxPool2d(kernel_size=5, stride=1, padding=2)
self.conv2d_60 = torch.nn.Conv2d(in_channels=4048, out_channels=1024, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_60 = torch.nn.BatchNorm2d(num_features=1024)
self.conv2d_61 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_61 = torch.nn.BatchNorm2d(num_features=512)
self.upsample_1 = torch.nn.Upsample(scale_factor=2)
self.conv2d_62 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_62 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_63 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_63 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_64 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_64 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_65 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_65 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_66 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_66 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_67 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_67 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_68 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_68 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_69 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_69 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_70 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_70 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_71 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_71 = torch.nn.BatchNorm2d(num_features=512)
self.upsample_2 = torch.nn.Upsample(scale_factor=2)
self.conv2d_72 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_72 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_73 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_73 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_74 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_74 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_75 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_75 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_76 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_76 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_77 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_77 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_78 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_78 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_79 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_79 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_80 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_80 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_81 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_81 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_82 = torch.nn.Conv2d(in_channels=256, out_channels=255, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_82 = torch.nn.BatchNorm2d(num_features=255)
self.conv2d_83 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_83 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_84 = torch.nn.Conv2d(in_channels=512, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_84 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_85 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_85 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_86 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_86 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_87 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_87 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_88 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_88 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_89 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_89 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_90 = torch.nn.Conv2d(in_channels=256, out_channels=256, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_90 = torch.nn.BatchNorm2d(num_features=256)
self.conv2d_91 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_91 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_92 = torch.nn.Conv2d(in_channels=512, out_channels=255, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_92 = torch.nn.BatchNorm2d(num_features=255)
self.conv2d_93 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=2, padding=1)
self.batchnorm2d_93 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_94 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_94 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_95 = torch.nn.Conv2d(in_channels=1024, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_95 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_96 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_96 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_97 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_97 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_98 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_98 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_99 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_99 = torch.nn.BatchNorm2d(num_features=51256)
self.conv2d_100 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_100 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_101 = torch.nn.Conv2d(in_channels=512, out_channels=512, kernel_size=3, stride=1, padding=1)
self.batchnorm2d_101 = torch.nn.BatchNorm2d(num_features=512)
self.conv2d_102 = torch.nn.Conv2d(in_channels=1024, out_channels=1024, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_102 = torch.nn.BatchNorm2d(num_features=1024)
self.conv2d_103 = torch.nn.Conv2d(in_channels=1024, out_channels=255, kernel_size=1, stride=1, padding=0)
self.batchnorm2d_103 = torch.nn.BatchNorm2d(num_features=255)
self.group_1 = torch.nn.Sequential(
)
self.group_2 = torch.nn.Sequential(
)
self.silu_1 = torch.nn.SiLU()
def forward(self, x_emptyimage):
x_0 = self.group_2(x_emptyimage)
x_0 = self.group_1(x_0)
x_0 = self.conv2d_3(x_0)
x_0 = self.batchnorm2d_3(x_0)
x_0 = self.silu_1(x_0)
x_0 = self.conv2d_5(x_0)
x_0 = self.batchnorm2d_5(x_0)
x_0 = self.silu_1(x_0)
x_0 = self.conv2d_6(x_0)
x_0 = self.batchnorm2d_6(x_0)
x_0 = self.silu_1(x_0)
x_1 = torch.add((x_0, x_0))
x_1 = self.conv2d_7(x_1)
x_1 = self.batchnorm2d_7(x_1)
x_1 = self.silu_1(x_1)
x_1 = self.conv2d_8(x_1)
x_1 = self.batchnorm2d_8(x_1)
x_1 = self.silu_1(x_1)
x_2 = torch.add((x_1, x_1))
x_2 = self.conv2d_9(x_2)
x_2 = self.batchnorm2d_9(x_2)
x_2 = self.silu_1(x_2)
x_2 = self.conv2d_10(x_2)
x_2 = self.batchnorm2d_10(x_2)
x_2 = self.silu_1(x_2)
x_3 = torch.add((x_2, x_2))
x_1 = torch.concat((x_1, x_3))
x_1 = self.conv2d_11(x_1)
x_1 = self.batchnorm2d_11(x_1)
x_1 = self.silu_1(x_1)
x_1 = self.conv2d_12(x_1)
x_1 = self.batchnorm2d_12(x_1)
x_1 = self.silu_1(x_1)
x_1 = self.conv2d_13(x_1)
x_1 = self.batchnorm2d_13(x_1)
x_1 = self.silu_1(x_1)
x_1 = self.conv2d_15(x_1)
x_1 = self.batchnorm2d_15(x_1)
x_1 = self.silu_1(x_1)
x_1 = self.conv2d_16(x_1)
x_1 = self.batchnorm2d_16(x_1)
x_1 = self.silu_1(x_1)
x_2 = torch.add((x_1, x_1))
x_2 = self.conv2d_17(x_2)
x_2 = self.batchnorm2d_17(x_2)
x_2 = self.silu_1(x_2)
x_2 = self.conv2d_18(x_2)
x_2 = self.batchnorm2d_18(x_2)
x_2 = self.silu_1(x_2)
x_3 = torch.add((x_2, x_2))
x_3 = self.conv2d_19(x_3)
x_3 = self.batchnorm2d_19(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_20(x_3)
x_3 = self.batchnorm2d_20(x_3)
x_3 = self.silu_1(x_3)
x_4 = torch.add((x_3, x_3))
x_4 = self.conv2d_21(x_4)
x_4 = self.batchnorm2d_21(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_22(x_4)
x_4 = self.batchnorm2d_22(x_4)
x_4 = self.silu_1(x_4)
x_5 = torch.add((x_4, x_4))
x_5 = self.conv2d_23(x_5)
x_5 = self.batchnorm2d_23(x_5)
x_5 = self.silu_1(x_5)
x_5 = self.conv2d_24(x_5)
x_5 = self.batchnorm2d_24(x_5)
x_5 = self.silu_1(x_5)
x_6 = torch.add((x_5, x_5))
x_6 = self.conv2d_25(x_6)
x_6 = self.batchnorm2d_25(x_6)
x_6 = self.silu_1(x_6)
x_6 = self.conv2d_26(x_6)
x_6 = self.batchnorm2d_26(x_6)
x_6 = self.silu_1(x_6)
x_7 = torch.add((x_6, x_6))
x_2 = torch.concat((x_2, x_7))
x_2 = self.conv2d_27(x_2)
x_2 = self.batchnorm2d_27(x_2)
x_2 = self.silu_1(x_2)
x_2 = self.conv2d_28(x_2)
x_2 = self.batchnorm2d_28(x_2)
x_2 = self.silu_1(x_2)
x_2 = self.conv2d_29(x_2)
x_2 = self.batchnorm2d_29(x_2)
x_2 = self.silu_1(x_2)
x_2 = self.conv2d_31(x_2)
x_2 = self.batchnorm2d_31(x_2)
x_2 = self.silu_1(x_2)
x_2 = self.conv2d_32(x_2)
x_2 = self.batchnorm2d_32(x_2)
x_2 = self.silu_1(x_2)
x_3 = torch.add((x_2, x_2))
x_3 = self.conv2d_33(x_3)
x_3 = self.batchnorm2d_33(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_34(x_3)
x_3 = self.batchnorm2d_34(x_3)
x_3 = self.silu_1(x_3)
x_4 = torch.add((x_3, x_3))
x_4 = self.conv2d_35(x_4)
x_4 = self.batchnorm2d_35(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_36(x_4)
x_4 = self.batchnorm2d_36(x_4)
x_4 = self.silu_1(x_4)
x_5 = torch.add((x_4, x_4))
x_5 = self.conv2d_37(x_5)
x_5 = self.batchnorm2d_37(x_5)
x_5 = self.silu_1(x_5)
x_5 = self.conv2d_38(x_5)
x_5 = self.batchnorm2d_38(x_5)
x_5 = self.silu_1(x_5)
x_6 = torch.add((x_5, x_5))
x_6 = self.conv2d_39(x_6)
x_6 = self.batchnorm2d_39(x_6)
x_6 = self.silu_1(x_6)
x_6 = self.conv2d_40(x_6)
x_6 = self.batchnorm2d_40(x_6)
x_6 = self.silu_1(x_6)
x_7 = torch.add((x_6, x_6))
x_7 = self.conv2d_41(x_7)
x_7 = self.batchnorm2d_41(x_7)
x_7 = self.silu_1(x_7)
x_7 = self.conv2d_42(x_7)
x_7 = self.batchnorm2d_42(x_7)
x_7 = self.silu_1(x_7)
x_8 = torch.add((x_7, x_7))
x_8 = self.conv2d_44(x_8)
x_8 = self.batchnorm2d_44(x_8)
x_8 = self.silu_1(x_8)
x_8 = self.conv2d_45(x_8)
x_8 = self.batchnorm2d_45(x_8)
x_8 = self.silu_1(x_8)
x_9 = torch.add((x_8, x_8))
x_9 = self.conv2d_46(x_9)
x_9 = self.batchnorm2d_46(x_9)
x_9 = self.silu_1(x_9)
x_9 = self.conv2d_47(x_9)
x_9 = self.batchnorm2d_47(x_9)
x_9 = self.silu_1(x_9)
x_10 = torch.add((x_9, x_9))
x_10 = self.conv2d_48(x_10)
x_10 = self.batchnorm2d_48(x_10)
x_10 = self.silu_1(x_10)
x_10 = self.conv2d_49(x_10)
x_10 = self.batchnorm2d_49(x_10)
x_10 = self.silu_1(x_10)
x_11 = torch.add((x_10, x_10))
x_3 = torch.concat((x_3, x_11))
x_3 = self.conv2d_43(x_3)
x_3 = self.batchnorm2d_43(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_50(x_3)
x_3 = self.batchnorm2d_50(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_51(x_3)
x_3 = self.batchnorm2d_51(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_53(x_3)
x_3 = self.batchnorm2d_53(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_54(x_3)
x_3 = self.batchnorm2d_54(x_3)
x_3 = self.silu_1(x_3)
x_4 = torch.add((x_3, x_3))
x_4 = self.conv2d_55(x_4)
x_4 = self.batchnorm2d_55(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_56(x_4)
x_4 = self.batchnorm2d_56(x_4)
x_4 = self.silu_1(x_4)
x_5 = torch.add((x_4, x_4))
x_5 = self.conv2d_57(x_5)
x_5 = self.batchnorm2d_57(x_5)
x_5 = self.silu_1(x_5)
x_5 = self.conv2d_58(x_5)
x_5 = self.batchnorm2d_58(x_5)
x_5 = self.silu_1(x_5)
x_6 = torch.add((x_5, x_5))
x_4 = torch.concat((x_4, x_6))
x_4 = self.conv2d_59(x_4)
x_4 = self.batchnorm2d_59(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.maxpool2d_1(x_4)
x_8 = torch.concat((x_4, x_4, x_5, x_6, x_7))
x_8 = self.conv2d_60(x_8)
x_8 = self.batchnorm2d_60(x_8)
x_8 = self.silu_1(x_8)
x_8 = self.conv2d_61(x_8)
x_8 = self.batchnorm2d_61(x_8)
x_8 = self.silu_1(x_8)
x_8 = self.upsample_1(x_8)
x_4 = torch.concat((x_8, x_3))
x_4 = self.conv2d_62(x_4)
x_4 = self.batchnorm2d_62(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_64(x_4)
x_4 = self.batchnorm2d_64(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_65(x_4)
x_4 = self.batchnorm2d_65(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_66(x_4)
x_4 = self.batchnorm2d_66(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_67(x_4)
x_4 = self.batchnorm2d_67(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_68(x_4)
x_4 = self.batchnorm2d_68(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_69(x_4)
x_4 = self.batchnorm2d_69(x_4)
x_4 = self.silu_1(x_4)
x_5 = torch.concat((x_5, x_4))
x_5 = self.conv2d_70(x_5)
x_5 = self.batchnorm2d_70(x_5)
x_5 = self.silu_1(x_5)
x_5 = self.conv2d_71(x_5)
x_5 = self.batchnorm2d_71(x_5)
x_5 = self.silu_1(x_5)
x_5 = self.upsample_2(x_5)
x_3 = torch.concat((x_5, x_2))
x_3 = self.conv2d_72(x_3)
x_3 = self.batchnorm2d_72(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_74(x_3)
x_3 = self.batchnorm2d_74(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_75(x_3)
x_3 = self.batchnorm2d_75(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_76(x_3)
x_3 = self.batchnorm2d_76(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_77(x_3)
x_3 = self.batchnorm2d_77(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_78(x_3)
x_3 = self.batchnorm2d_78(x_3)
x_3 = self.silu_1(x_3)
x_3 = self.conv2d_79(x_3)
x_3 = self.batchnorm2d_79(x_3)
x_3 = self.silu_1(x_3)
x_4 = torch.concat((x_4, x_3))
x_4 = self.conv2d_80(x_4)
x_4 = self.batchnorm2d_80(x_4)
x_4 = self.silu_1(x_4)
x_4 = self.conv2d_81(x_4)
x_4 = self.batchnorm2d_81(x_4)
x_4 = self.silu_1(x_4)
x_4 = torch.concat((x_5, x_4))
x_4 = self.conv2d_84(x_4)
x_4 = self.batchnorm2d_84(x_4)
x_4 = self.silu_1(x_4)
x_5 = torch.concat((x_4, x_5))
x_5 = self.conv2d_91(x_5)
x_5 = self.batchnorm2d_91(x_5)
x_5 = self.silu_1(x_5)
x_5 = self.conv2d_92(x_5)
x_5 = self.batchnorm2d_92(x_5)
x_5 = self.silu_1(x_5)
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)