Skip to content

Natalie branch#10

Open
natalie-y-kim wants to merge 9 commits intomainfrom
natalie-branch
Open

Natalie branch#10
natalie-y-kim wants to merge 9 commits intomainfrom
natalie-branch

Conversation

@natalie-y-kim
Copy link
Copy Markdown
Collaborator

adding trained ResNet model weight

Comment thread resnet_train.py
param.requires_grad = True

model.fc = nn.Linear(model.fc.in_features, 2) # 2 classes (real, fake)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You unfreeze the old fc layer, then immediately overwrite it with a new nn.Linear layer.
That means the requires_grad settings you applied are lost.

Comment thread resnet_train.py
optimizer.step()

train_loss += loss.item()
correct += (outputs.argmax(1) == labels).sum().item()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

train_loss += loss.item()
This sums the loss per batch. When you print it, the scale depends on the number of batches.

Usually, you report average loss per batch or per sample.

Comment thread resnet_train.py


# save model
torch.save(model, 'resnet18_full_model.pth')
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This saves the entire model object, which can break if you load it in a different PyTorch version.
Safer approach is to save only state_dict().

Comment thread resnet_train.py
if img.mode == 'P' or img.mode == 'LA':
img = img.convert('RGBA')
return img

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You convert some images to RGBA, but ResNet18 expects 3 channels (RGB).
After .convert("RGBA"), your ToTensor() will return 4 channels → mismatch with ResNet.

Comment thread resnet_train.py
optimizer.step()

train_loss += loss.item()
correct += (outputs.argmax(1) == labels).sum().item()
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are only tracking train accuracy. Add a test loop accuracy to monitor overfitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants