首页 > 其他分享 >test

test

时间:2022-09-25 20:23:17浏览次数:43  
标签:10 None name inputer tf test size

test.py

import tensorflow as tf
import numpy as np
def add_layer(inputs, in_size, out_size, activation_function=None):  # inputs.shape=[None,1],in_size.shape=1,out_size=10 |inputs.shape=[None,10],in_size.shape=10,out_size=1
    with tf.name_scope('layer'):
        with tf.name_scope('weights'):
            Weights = tf.Variable(tf.random_normal([in_size, out_size]), name='w')  # [1,10] | [10,1]
        with tf.name_scope('bias'):
            biases = tf.Variable(tf.zeros([1, out_size]) + 0.1, name='b')  # [1,10],这个1跟上面那个1貌似不是一个意思 | [1,1]
        with tf.name_scope('wx_plus_b'):
            Wx_plus_b = tf.matmul(inputs, Weights) + biases  # 注意这里顺序,inputs在前。[None,1]×[1,10]+[1,10](python广播)=[None,10] | [None,10]×[10,1]+[1,1](python广播)=[None,1]
        if activation_function is None:
            outputs = Wx_plus_b
        else:
            outputs = activation_function(Wx_plus_b)
        return outputs

# 训练集数据和标签
train_data_x = np.linspace(-1,1,300, dtype=np.float32)[:, np.newaxis]  # shape=(300,1)
noise = np.random.normal(0, 0.05, train_data_x.shape).astype(np.float32)
label_y = np.square(train_data_x) - 0.5 + noise
with tf.name_scope('inputs'):
    inputer_x = tf.placeholder(tf.float32, [None, 1], name='inputer_x')
    inputer_y = tf.placeholder(tf.float32, [None, 1], name='inputer_y')

# 设计的网络结构是1-10-1的
l1 = add_layer(inputer_x, 1, 10, activation_function=tf.nn.relu)
prediction = add_layer(l1, 10, 1, activation_function=None)
with tf.name_scope('loss'):
    loss = tf.reduce_mean(tf.reduce_sum(tf.square(inputer_y-prediction), reduction_indices=[1]))
with tf.name_scope('train_scope'):
    train_step = tf.train.GradientDescentOptimizer(0.1).minimize(loss)

sess = tf.Session()

init = tf.global_variables_initializer()
sess.run(init)
writer = tf.summary.FileWriter("logs", sess.graph)  # 文件写在该.py文件同级,在命令行中,用tensorboard --logdir=.打开

for i in range(1000):
    # training
    sess.run(train_step, feed_dict={inputer_x: train_data_x, inputer_y: label_y})
    if i % 50 == 0:
        # to see the step improvement
        print(sess.run(loss, feed_dict={inputer_x: train_data_x, inputer_y: label_y}))

标签:10,None,name,inputer,tf,test,size
From: https://www.cnblogs.com/watson04/p/16728692.html

相关文章

  • AtCoder Beginner Contest 270
    咕咕咕。D-Stones冲了发贪心,然后WA。然后想了个DP,就令\(dp_{n,0/1}\)表示石头总数为\(n\)时,先手/后手最多能拿多少个石头,然后跑个\(O(nk)\)的DP就完事了。......
  • Weekly Contest 311
    WeeklyContest311ProblemASmallestEvenMultiple思路水题,判一下奇偶就行代码classSolution:defsmallestEvenMultiple(self,n:int)->int:if......
  • 组合测试术语:Pairwise/All-Pairs、OATS(Orthogonal Array Testing Strategy)
    组合测试组合测试(CombinatorialTest)是一种黑盒测试用例生成方法,主要针对多输入参数组合场景。目前业界较流行的两种组合测试方法,一种是Pairwise/All-Pairs,即配对组合。OA......
  • AtCoder Beginner Contest 268(D-E)
    D-UniqueUsername 题意:给出n个字符串,以任意顺序排列,然后在每两个字符串中间加最少一个"_",然后给出m个字符串,问是否能得出一个字符串,不在这m个字符串中,并且长度在3-16......
  • 每天进步一点点-pytest插件介绍
    pytest-html插件使用测试结果生成HTML报告安装pip3installpytest-html-ihttp://pypi.douban.com/simple/--trusted-hostpypi.douban.com快速入门pytest......
  • AtCoder Beginner Contest 043 题解
    欢迎来到我的算法小屋前言 TaskNameAChildrenandCandies(ABCEdit)BUnhappyHacking(ABCEdit)CBeTogetherDUnbalancedA1)题目描述2......
  • 持续集成环境问题汇总(基于:java + testng + httpclient + allure + git + gitlab + jen
    说明包含前期调试遇到的问题 idea中,命令执行testng.xml,报错PleaserefertoD:\myjava\apiAutoTest\target\surefire-reportsfortheindividualtestresults.参考......
  • java.nio.file.AccessDeniedException: /home/jenkins/agent/workspace/gift/target/a
    企业级持续集成  自动化框架:java+testng+httpclient+allure  持续集成:git+gitlab+jenkins+pipeline+maven+harbor+docker+k8s 持续集成环......
  • Test 2022.09.22
    今天是COCI专场T1PAVORI题意从\(1-n\)的所有数中选出若干组两两互质的二元组,使得数轴上的\(1-n\)之间的区间被完全覆盖的方案数解决容易想到先排序然后再dp,定义\(dp[......
  • test
    importcom.mongodb.client.MongoCollectionimportcom.mongodb.client.model.BulkWriteOptionsimportcom.mongodb.client.model.InsertOneModelimportcom.mongodb.cl......