Gabor Cselle commited on
Commit
b245442
1 Parent(s): 2e58968

Adding visualize.ipynb, data_transform>RandomCrop

Browse files
Files changed (3) hide show
  1. .gitignore +1 -0
  2. train_font_identifier.py +6 -5
  3. visualize.ipynb +0 -0
.gitignore CHANGED
@@ -1,3 +1,4 @@
1
  font_images
2
  train_test_images
3
  .DS_Store
 
 
1
  font_images
2
  train_test_images
3
  .DS_Store
4
+ .ipynb_checkpoints/visualize-checkpoint.ipynb
train_font_identifier.py CHANGED
@@ -14,7 +14,7 @@ data_dir = './train_test_images'
14
  # Transformations for the image data
15
  data_transforms = transforms.Compose([
16
  transforms.Grayscale(num_output_channels=3), # Convert images to grayscale with 3 channels
17
- transforms.Resize((224, 224)), # Resize images to the expected input size of the model
18
  transforms.ToTensor(), # Convert images to PyTorch tensors
19
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # Normalize with ImageNet stats
20
  ])
@@ -45,9 +45,6 @@ criterion = torch.nn.CrossEntropyLoss()
45
  criterion = nn.CrossEntropyLoss()
46
  optimizer = optim.Adam(model.parameters())
47
 
48
- # Number of epochs to train for
49
- num_epochs = 25
50
-
51
  # Function to perform a training step with progress bar
52
  def train_step(model, data_loader, criterion, optimizer):
53
  model.train()
@@ -81,8 +78,12 @@ def validate(model, data_loader, criterion):
81
  progress_bar.close()
82
  return total_loss / len(data_loader), correct / len(data_loader.dataset)
83
 
 
 
 
 
84
  # Training loop with progress bar for epochs
85
- num_epochs = 25 # Replace with the number of epochs you'd like to train for
86
  for epoch in range(num_epochs):
87
  print(f"Epoch {epoch+1}/{num_epochs}")
88
  train_loss = train_step(model, dataloaders["train"], criterion, optimizer)
 
14
  # Transformations for the image data
15
  data_transforms = transforms.Compose([
16
  transforms.Grayscale(num_output_channels=3), # Convert images to grayscale with 3 channels
17
+ transforms.RandomCrop((224, 224)), # Resize images to the expected input size of the model
18
  transforms.ToTensor(), # Convert images to PyTorch tensors
19
  transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) # Normalize with ImageNet stats
20
  ])
 
45
  criterion = nn.CrossEntropyLoss()
46
  optimizer = optim.Adam(model.parameters())
47
 
 
 
 
48
  # Function to perform a training step with progress bar
49
  def train_step(model, data_loader, criterion, optimizer):
50
  model.train()
 
78
  progress_bar.close()
79
  return total_loss / len(data_loader), correct / len(data_loader.dataset)
80
 
81
+
82
+ print(image_datasets['train'].classes)
83
+
84
+
85
  # Training loop with progress bar for epochs
86
+ num_epochs = 10 # Replace with the number of epochs you'd like to train for
87
  for epoch in range(num_epochs):
88
  print(f"Epoch {epoch+1}/{num_epochs}")
89
  train_loss = train_step(model, dataloaders["train"], criterion, optimizer)
visualize.ipynb ADDED
The diff for this file is too large to render. See raw diff