当我向输出层添加2个神经元时,学习速度太慢

2024-04-20 12:17:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在从头开始实施一个神经网络,以识别是否有一只猫,这是工作得很好

Architecture of neural net is:
Image shape = (64,64,3)
Train images = 100 ==> reshaped too (12288, 100)
Test images = 25 ==> reshaped too (12288, 25)


Layers are as:
[12288, 32, 64, 128, 256, 1024, 1]
Learning rate = 0.01

Cost I get on this is:
Cost after iteration 0: 0.6931489297046624
Cost after iteration 100: 0.4883935590415581
Cost after iteration 200: 0.36081001955698583
Cost after iteration 300: 0.27667037518359366
Cost after iteration 400: 0.21814954139135215
Cost after iteration 500: 0.17566035067079316
Cost after iteration 600: 0.14379510198340753
Cost after iteration 700: 0.11931953624412495
Cost after iteration 800: 0.1001804918888681
Cost after iteration 900: 0.08500294953949178
Cost after iteration 1000: 0.0728255235455732
Cost after iteration 1100: 0.06295421630851546
Cost after iteration 1200: 0.05487653264581672
Cost after iteration 1300: 0.048207823668081726
Cost after iteration 1400: 0.04265587452224586
Cost after iteration 1500: 0.03799651492130658
Cost after iteration 1600: 0.03405630846956158
Cost after iteration 1700: 0.030700016432453042
Cost after iteration 1800: 0.02782139326988321
Cost after iteration 1900: 0.025336361142384353
Cost after iteration 2000: 0.023177909431575435
Cost after iteration 2100: 0.021292256317487622
Cost after iteration 2200: 0.019635942647950454
Cost after iteration 2300: 0.01817361697739766
Cost after iteration 2400: 0.01687633799342948
Cost after iteration 2499: 0.015731194121508994

成本在降低,因此网络正在学习,但当我修改此网络以区分猫与狗时,成本降低非常小。我将输出层替换为2个神经元,因为我需要预测猫或狗的状态,如下所示

Architecture of neural net is:
Image shape = (64,64,3)
Train images = 100 ==> reshaped too (12288, 100)
50 images are of cats, 50 are of dogs.
Test images = 25 ==> reshaped too (12288, 25)

Layers are as:
[12288, 32, 64, 128, 256, 1024, 2]
Learning rate = 0.01

Cost I get on this is:
Cost after iteration 0: 1.3862942626917214
Cost after iteration 100: 1.3862936877441023
Cost after iteration 200: 1.3862936382959834
Cost after iteration 300: 1.3862936088999924
Cost after iteration 400: 1.3862935723383438
Cost after iteration 500: 1.3862935546779653
Cost after iteration 600: 1.3862935413933175
Cost after iteration 700: 1.386293531419176
Cost after iteration 800: 1.3862935241175995
Cost after iteration 900: 1.386293501361619
Cost after iteration 1000: 1.3862934905311062
Cost after iteration 1100: 1.386293484867794
Cost after iteration 1200: 1.386293473659006
Cost after iteration 1300: 1.3862934660150443
Cost after iteration 1400: 1.3862934500384458
Cost after iteration 1500: 1.386293442026514
Cost after iteration 1600: 1.3862934342382442
Cost after iteration 1700: 1.3862934290588118
Cost after iteration 1800: 1.3862934193689949
Cost after iteration 1900: 1.3862934103850098
Cost after iteration 2000: 1.3862934054327474
Cost after iteration 2100: 1.386293398123051
Cost after iteration 2200: 1.3862933780745346
Cost after iteration 2300: 1.3862933699459277
Cost after iteration 2400: 1.3862933608537853
Cost after iteration 2499: 1.3862933546832072

降低成本太慢了,有什么原因吗