2023年12月22日发(作者:数学试卷高考海南)
initial=nt(0.1,shape=shape) return le(initial)
def train(self): x=older(32,[None,9]) y=older(32,[None,32]) w_fc1=_variable([9,500]) b_fc1=_vairable([500]) w_fc2=_variable([500,500]) b_fc2=_vairable([500]) w_fc3=_variable([500,500]) b_fc3=_vairable([500]) w_fc4=_variable([500,32]) b_fc4=_vairable([32]) h_fc1=((x,w_fc1)+b_fc1) h_fc2=d((h_fc1,w_fc2)+b_fc2) h_fc3=((h_fc2,w_fc3)+b_fc3) h_fc4=(h_fc3,w_fc4)+b_fc4 loss=_mean(x_cross_entropy_with_logits_v2(labels=y,logits=h_fc4)) train=timizer().minimize(loss) accuracy=_mean((((h_fc4,1),(y,1)),32)) mse=_mean((((h_fc4,1)-(y,1)),32)) init=_variables_initializer()
with n() as sess: (init) x_test,y_test=_batch(50000) for epoch in range(_step): for i in range(_num): x_,y_=_batch(_size) (train,feed_dict={x:x_,y:y_}) acc,m=([accuracy,mse],feed_dict={x:x_test,y:y_test}) print(\"epoch:\",epoch,\"accuracy:\",acc,\"mse:\",m) self.w_fc1,self.b_fc1,self.w_fc2,self.b_fc2,self.w_fc3,self.b_fc3,self.w_fc4,self.b_fc4= ([w_fc1,b_fc1,w_fc2,b_fc2,w_fc3,b_fc3,w_fc4,b_fc4],feed_dict={x:x_test,y:y_test})
def predict(self,x): h_fc1=((x,self.w_fc1)+self.b_fc1) h_fc2=d((h_fc1,self.w_fc2)+self.b_fc2) h_fc3=((h_fc2,self.w_fc3)+self.b_fc3) h_fc4=(h_fc3,self.w_fc4)+self.b_fc4 pre=(h_fc4,1) with n() as sess: pre=(pre) return pre
def save_para(self): (\"jie3_\",w_fc1=self.w_fc1,b_fc1=self.b_fc1,w_fc2=self.w_fc2,b_fc2=self.b_fc2, w_fc3=self.w_fc3,b_fc3=self.b_fc3,w_fc4=self.w_fc4,b_fc4=self.b_fc4)
temp=(\'\')data=temp[\'data\']label=temp[\'label\']
dnn=DNN(data,label,0.002,200)()_para()x=([[1,2,3,4,5,9,7,8,6]],dtype=\'float32\')step=t(x)(2)预测
import numpy as npimport tensorflow as tfclass Prediction: def __init__(self): self.n=3 self.N=self.n*self.n temp=(\'jie3_\') self.w_fc1=temp[\'w_fc1\'] self.b_fc1=temp[\'b_fc1\'] self.w_fc2=temp[\'w_fc2\'] self.b_fc2=temp[\'b_fc2\'] self.w_fc3=temp[\'w_fc3\'] self.b_fc3=temp[\'b_fc3\'] self.w_fc4=temp[\'w_fc4\'] self.b_fc4=temp[\'b_fc4\'] self.X=[-1,0,1,0] self.Y=[0,-1,0,1]
def pre_step(self,x): x=e(1,-1).astype(\'float32\') h_fc1=((x,self.w_fc1)+self.b_fc1) h_fc2=d((h_fc1,self.w_fc2)+self.b_fc2) h_fc3=((h_fc2,self.w_fc3)+self.b_fc3) h_fc4=(h_fc3,self.w_fc4)+self.b_fc4 pre=(h_fc4,1) with n() as sess: pre=(pre) return pre
def pre_next(self,sta,bk_x,bk_y,bk_x_p,bk_y_p): step=[10000,10000,10000,10000] for i in range(4): x=bk_x+self.X[i] y=bk_y+self.Y[i] if x<0 or x>=self.n or y<0 or y>=self.n or x==bk_x_p and y==bk_y_p: continue t=sta[x][y] sta[x][y]=self.N sta[bk_x][bk_y]=t step[i]=_step(sta) sta[x][y]=t sta[bk_x][bk_y]=self.N return (step)
更多推荐
高考,海南,数学试卷,作者
发布评论