分类:TensorFLow
2020
10-08
我就废话不多说了,大家还是直接看代码吧~flyfish#a#[[1,2,3],#[4,5,6]]a=tf.constant([1,2,3,4,5,6],shape=[2,3])#b1#[[7,8],#[9,10],#[11,12]]b1=tf.constant([7,8,9,10,11,12],shape=[3,2])#b2#[[789]#[101112]]b2=tf.constant([7,8,9,10,11,12],shape=[2,3])#c矩阵相乘第一个矩阵的列数(column)等于第二个矩阵的行数(row)#[[58,64],#[139,154]]c=tf.matmul...
继续阅读 >
概述在使用keras中的keras.backend.batch_dot和tf.matmul实现功能其实是一样的智能矩阵乘法,比如A,B,C,D,E,F,G,H,I,J,K,L都是二维矩阵,中间点表示矩阵乘法,AG表示矩阵A和G矩阵乘法(A的列维度等于G行维度),WX=Zimportkeras.backendasKimporttensorflowastfimportnumpyasnpw=K.variable(np.random.randint(10,size=(10,12,4,5)))k=K.variable(np.random.randint(10,size=(10,12,5,8)))z=K.batch_dot(w,k)...
继续阅读 >
直接上代码:fig_loss=np.zeros([n_epoch])fig_acc1=np.zeros([n_epoch])fig_acc2=np.zeros([n_epoch])forepochinrange(n_epoch):start_time=time.time()#trainingtrain_loss,train_acc,n_batch=0,0,0forx_train_a,y_train_ainminibatches(x_train,y_train,batch_size,shuffle=True):_,err,ac=sess.run([train_op,loss,acc],feed_dict={x:x_train_a,y_:y_train_a})train_loss+=err;train_ac...
继续阅读 >