初识 Jupyter

深度学习笔记(一)

Posted by Nino Lau on February 28, 2019

Activation Functions

Complete the activation functions below:

import numpy as np

class Activation:
    
    def sigmoid(self,x):
        y = 1.0 / (1.0 + np.exp(-x))
        return y
    
    def tanh(self,x):
        y = (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))
        return y
    
    def relu(self,x):
        if x >= 0:
            y = x
        else:
            y = 0
        return y
    
    def leaky_relu(self,alpha,x):
        if x >= 0:
            y = x
        else:
            y = alpha*x
        return y
    
    def elu(self,alpha,x):
        if x >= 0:
            y = x
        else:
            y = alpha*(np.exp(x)-1)
        return y
    
activation = Activation()
print(activation.sigmoid(10))
print(activation.relu(20))
print(activation.tanh(-1))
print(activation.leaky_relu(0.1,-1))
print(activation.elu(0.1,-1))
0.9999546021312976
20
-0.7615941559557649
-0.1
-0.06321205588285576

Faces

Print out all the images’ name and the files’ length.

import os

def listdir(path, list_name):
    for file in os.listdir(path):
        file_path = os.path.join(path, file)
        if os.path.isdir(file_path):
            listdir(file_path,list_name)
        elif os.path.splitext(file_path)[1]=='.jpg':
            file_name= os.path.split(file_path)[-1][0:-4]
            list_name.append(file_name)

'''
def writefile(list):
    f=open("faces.xlsx","w+")
    for i in list:
        f.writelines(i+'\n')
    f.close()

'''

path="face"
list=[]
listdir(path,list)
for i in list:
    print('\n'+'\"'+i+'\"'+'\n')

#writefile(set(list))

f=open("length.txt","w")
print("\nTotal files number: "+str(len(list))+"\n\n")
f.writelines("Total files number: "+str(len(list))+"\n\n")
f.close()

"2370961440_6bc8ce346c"
"2956581526_cd803f2daa"
"303808204_1f744bc407"
"3152653555_68322314f3"
"92053278_be61a225d2"
"343583208_e986824d77"
"299733036_fff5ea6f8e"
"57635685_d41c98f8ca"
"10comm-decarlo"
"809285949_6889026b53"
"1383023626_8a49e4879a"
"1084239450_e76e00b7e7"
"529447797_0f9d2fb756"
"2328398005_d328a70b4c"
"2173711035_dbd53b4f9f"
"2046713398_91aaa6fe1c"
"1878519279_f905d4f34e"
"2210514040_6b03ff2629"
"2322901504_08122b01ba"
"2327253037_66a61ea6fe"
 	"1549040388_b99e9fa295" ​	"363149951_8be04dc6c0" ​	"1198_0_861" ​	"2382SJ8" ​	"96063776_bdb3617b64" ​	"97308305_4b737d0873" ​	"110276240_bec305da91" ​	"297448785_b2dda4b2c0" ​	"137341995_e7c48e9a75" ​	"144044282_87cf3ff76e" ​	"252418361_440b75751b" ​	"262007783_943bbcf613" ​	"152601997_ec6429a43c" ​	"0805personali01" ​	"348272697_832ce65324" ​	"362167809_d5a5dcbfdb" ​	"2633371780_45b740b670" ​	"2902760364_89c50bde40" ​	"3298715079_5af7c78fcb" ​	"3074791551_baee7fa0c1" ​	"2902323565_100017b63c" ​	"2795838930_0cc5aa5f41" ​	"2722779845_7fcb64a096" ​	"2711409561_a0786a3d3d" ​	"3273658251_b95f65c244" ​	"3264867945_fe18d442c1" ​	"2647088981_60e9fe40cd" ​	"3325611505_ddc7beffa1" ​	"deeny.peggy" ​	"matt-mathes" ​	"person" ​	"person_TjahjonoDGondhowiardjo" ​	"3855944735_e252959937" ​	"3856149136_d4595ffdd4" ​	"3872768751_e60d7fdbd5" ​	"3638950581_3387685d3a" ​	"3790616528_297c0ac935" ​	"3718903026_c1bf5dfcf8" ​	"3574737496_6ee8207045" ​	"3689162471_5f9ffb5aa0" ​	"3646828311_bfeb429ef7" ​	"person-7" ​	"3534189272_8ef88ba368" ​	"3555944509_7b477069c6" ​	"britney-bald" ​	"3461016494_56cce9c984" ​	"3534188114_2108895291" ​	"3362762930_24f76cb89c" ​	"personalpic" ​	 ​	 ​	Total files number: 69