Batch size in CNN

username: akshay_23
cooked: <p>import time</p>
<p>start_time = time.time()</p>
<p>epochs = 1</p>
<p>train_losses = []</p>
<p>test_losses = []</p>
<p>train_correct = []</p>
<p>test_correct = []</p>
<p>for i in range(epochs):</p>
<pre><code>trn_corr = 0

tst_corr = 0



# Run the training batches

for b, batch in enumerate(train_loader):

    b+=1

    print(b)

    X_train = batch['image']

    y_train = batch['landmarks']

    X_train =X_train.to('cuda',dtype=torch.float)

    y_train = y_train.to('cuda',dtype=torch.float32).squeeze()

    # Apply the model

    

    y_pred = model(X_train)

    y_pred = y_pred.to('cuda',dtype=torch.float32).squeeze()

    loss = criterion(y_pred, y_train)

    print(b,loss.item())

    # Tally the number of correct predictions

    #predicted = torch.max(y_pred.data,1)[0][0]

    #predicted = predicted.to('cuda',dtype=torch.float32).squeeze()

   # batch_corr = (predicted == y_train).sum()

    #trn_corr += batch_corr

    

    # Update parameters

    optimizer.zero_grad()

    loss.backward()

    optimizer.step()

    

    # Print interim results

    if b%100 == 0:

        print(f'epoch: {i:2}  batch: {b:4} [{10*b:6}/50000]  loss: {loss.item():10.8f}')

                

train_losses.append(loss)
</code></pre>
<p>print(f’\nDuration: {time.time() - start_time:.0f} seconds’) # print the time elapsed</p>
<p>so when i run it goes till epoch:  0  batch:  700 [  7000/50000]  loss: 835.97753906<br>
701<br>
701 834.0040893554688<br>
702<br>
702 798.3275756835938<br>
703<br>
703 679.1052856445312<br>
704<br>
704 744.6819458007812<br>
705<br>
705 633.1027221679688<br>
706<br>
706 860.9313354492188<br>
707<br>
707 653.2901611328125<br>
708<br>
708 839.19677734375<br>
709<br>
709 762.4442749023438<br>
710<br>
710 733.4808349609375<br>
711<br>
711 831.7756958007812<br>
712<br>
712 768.0433349609375<br>
713<br>
713 533.0064086914062<br>
714<br>
714 744.097900390625<br>
715<br>
715 621.6771240234375<br>
716<br>
716 677.7670288085938<br>
717<br>
717 631.5947265625<br>
718<br>
718 632.5914306640625<br>
719<br>
719 727.1867065429688<br>
720<br>
720 472.8675231933594<br>
721<br>
721 777.7984619140625<br>
722<br>
722 553.052734375<br>
723<br>
723 762.1932983398438<br>
724<br>
724 622.1517944335938<br>
725<br>
725 637.0252075195312<br>
726<br>
726 677.1328125<br>
727<br>
727 926.3015747070312<br>
728<br>
728 671.0360107421875<br>
729<br>
729 1127.0623779296875<br>
730<br>
730 777.3078002929688<br>
731<br>
731 527.7666015625<br>
732<br>
732 576.8959350585938<br>
733<br>
733 821.3842163085938<br>
734<br>
734 571.5703125<br>
735<br>
735 539.9409790039062<br>
736<br>
736 673.8453369140625<br>
737<br>
737 636.5660400390625<br>
738<br>
738 692.1788940429688<br>
739<br>
739 672.10595703125<br>
740<br>
740 914.494140625<br>
741<br>
741 783.8777465820312<br>
742<br>
742 793.4269409179688<br>
743<br>
743 858.7411499023438<br>
744<br>
744 886.5870361328125<br>
745<br>
745 526.9144897460938<br>
746<br>
746 862.1968994140625<br>
747<br>
747 772.9779663085938<br>
748<br>
748 503.57421875<br>
749<br>
749 744.8223876953125<br>
750<br>
750 839.1438598632812<br>
751<br>
751 544.6222534179688<br>
752<br>
752 824.1895751953125<br>
753<br>
753 826.6942749023438<br>
754<br>
754 623.4790649414062<br>
755<br>
755 761.2865600585938<br>
756<br>
756 593.4060668945312<br>
757<br>
757 785.65478515625<br>
758<br>
758 594.8136596679688<br>
759<br>
759 881.4382934570312<br>
760<br>
760 843.9218139648438<br>
761<br>
761 744.2888793945312<br>
762<br>
762 1100.8704833984375<br>
763<br>
763 950.7271728515625<br>
764<br>
764 1016.8292846679688<br>
765<br>
765 752.9169311523438<br>
766<br>
766 848.7357788085938<br>
767<br>
767 692.6583862304688<br>
768<br>
768 564.8028564453125<br>
769<br>
769 151689.140625<br>
770<br>
770 618.965576171875<br>
771<br>
771 443.89501953125<br>
772<br>
772 707.8801879882812<br>
773<br>
773 975.7994384765625<br>
774<br>
774 1512.253173828125<br>
775<br>
775 905.3583374023438<br>
776<br>
776 540.3995361328125<br>
777<br>
777 926.8759765625<br>
778<br>
778 816.6861572265625<br>
779<br>
779 727.527587890625<br>
780<br>
780 1009.4464721679688<br>
781<br>
781 736.8145751953125<br>
782<br>
782 852.1244506835938<br>
783<br>
783 792.7083129882812<br>
784<br>
784 710.3810424804688<br>
785<br>
785 537.8117065429688<br>
786<br>
786 790.4335327148438<br>
787<br>
787 669.735595703125<br>
788<br>
788 746.8652954101562<br>
789<br>
789 817.0357666015625<br>
790<br>
790 601.0955200195312</p>
<p>Duration: 56 seconds<br>
and then it stops why isnt it going further than that</p>

username: ptrblck
cooked: <p>If I understand your code correctly, the duration print statement is used after the training is done.<br>
If that’s the case, the code seems to work fine.</p>
<p>PS: you can add code snippets by wrapping them in three backticks ```, which would make debugging a lot easier. <img src="https://discuss.pytorch.org/images/emoji/apple/wink.png?v=9" title=":wink:" class="emoji" alt=":wink:"></p>

username: akshay_23
cooked: <p>thanks for the quick reply ,</p>