File size: 768 Bytes
924a4d4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import *
import matplotlib.pyplot as plt

### Data Loader
path = Path('Spectrogram_Images')

dls = ImageDataLoaders.from_folder(
    path,
    train = '.',
     valid_pct=0.2,  # 20% of data for validation
    item_tfms = Resize(224), # Resize images to 224x224 pixels for CNN
    batch_tfms=aug_transforms(mult=1.0)  # Apply basic augmentations
)

# Show a batch of images to verify data loading
dls.show_batch(max_n=9, figsize=(8, 8))

### CNN

learn = vision_learner(dls, resnet34, metrics=accuracy)

print(learn.model)

learn.fine_tune(5)

# Plot training and validation loss curves
learn.recorder.plot_loss()

# Use the learning rate finder to identify the best learning rate
learn.lr_find()

# Plot the suggested learning rates
plt.show()