zoukankan      html  css  js  c++  java
  • tensorflow2

    # step1 加载包
    import tensorflow
    as tf import numpy as np
    # step2 输入:随机产生数据 # Create 100 phony x, y data points in NumPy, y = x * 0.1 + 0.3 x_data = np.random.rand(100).astype(np.float32) y_data = x_data * 0.1 + 0.3
    #step 3: 参数:定义参数并初始化 # Try to find values for W and b that compute y_data = W * x_data + b # (We know that W should be 0.1 and b 0.3, but TensorFlow will # figure that out for us.) W = tf.Variable(tf.random_uniform([1], -1.0, 1.0)) b = tf.Variable(tf.zeros([1])) y = W * x_data + b
    #steo 4:预测的值y,损失函数,求解器
    # Minimize the mean squared errors. loss = tf.reduce_mean(tf.square(y - y_data)) optimizer = tf.train.GradientDescentOptimizer(0.5) train = optimizer.minimize(loss)
    # step 5:初始化 # Before starting, initialize the variables. We will 'run' this first. init = tf.initialize_all_variables()
    # step 6: 创建会话并运行初始化 # Launch the graph. sess = tf.Session() sess.run(init)

    # step 7: 迭代求解
    # Fit the line. for step in range(201): sess.run(train) if step % 20 == 0: print(step, sess.run(W), sess.run(b)) # Learns best fit is W: [0.1], b: [0.3]
  • 相关阅读:
    51Nod1740 蜂巢迷宫
    51Nod1279 扔盘子
    51Nod1095 Anigram单词
    51Nod1094 和为k的连续区间
    51Nod1072 威佐夫游戏
    PHP 图片处理
    ubuntu 安装 ftp
    linux下ab网站压力测试命令
    iptables FOr linux
    discuz 个性化时间函数
  • 原文地址:https://www.cnblogs.com/Wanggcong/p/5847510.html
Copyright © 2011-2022 走看看