4888cb7a5299f7eed9214ddc70871dc05ea0f4d2,model/ft_ResNet50/train.py,,train_model,#,151

Before Change


                else:
                    inputs, labels = Variable(inputs), Variable(labels)
                // if we use low precision, input also need to be fp16
                if fp16:
                    inputs = inputs.half()
 
                // zero the parameter gradients
                optimizer.zero_grad()

                // forward
                if phase == "val":
                    with torch.no_grad():
                        outputs = model(inputs)
                else:
                    outputs = model(inputs)

                if not opt.PCB:
                    _, preds = torch.max(outputs.data, 1)
                    loss = criterion(outputs, labels)
                else:
                    part = {}
                    sm = nn.Softmax(dim=1)
                    num_part = 6
                    for i in range(num_part):
                        part[i] = outputs[i]

                    score = sm(part[0]) + sm(part[1]) +sm(part[2]) + sm(part[3]) +sm(part[4]) +sm(part[5])
                    _, preds = torch.max(score.data, 1)

                    loss = criterion(part[0], labels)
                    for i in range(num_part-1):
                        loss += criterion(part[i+1], labels)

                // backward + optimize only if in training phase
                if phase == "train":
                    if fp16: // we use optimier to backward loss
                        optimizer.backward(loss)
                    else:
                        loss.backward()
                    optimizer.step()

After Change


                // backward + optimize only if in training phase
                if phase == "train":
                    if fp16: // we use optimier to backward loss
                        with amp.scale_loss(loss, optimizer) as scaled_loss:
                            scaled_loss.backward()
                    else:
                        loss.backward()
                    optimizer.step()
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 10

Instances


Project Name: layumi/Person_reID_baseline_pytorch
Commit Name: 4888cb7a5299f7eed9214ddc70871dc05ea0f4d2
Time: 2019-03-20
Author: zdzheng12@gmail.com
File Name: model/ft_ResNet50/train.py
Class Name:
Method Name: train_model


Project Name: layumi/Person_reID_baseline_pytorch
Commit Name: f51bfb537448ababe532baa81149261937a654fc
Time: 2019-03-09
Author: zdzheng12@gmail.com
File Name: model/ft_ResNet50/train.py
Class Name:
Method Name: train_model


Project Name: layumi/Person_reID_baseline_pytorch
Commit Name: 8d57309574a957dd56e14bd9ed961542d34f1d04
Time: 2019-03-09
Author: zdzheng12@gmail.com
File Name: train.py
Class Name:
Method Name: train_model