TensorFlow学习笔记(一)

2023-05-16

TensorFlow版本2发布后,使用TensorFlow变得更简单和方便,但看网上的很多代码是使用的TensorFlow1进行完成的,每次遇到不懂的函数去查,理解记忆的一般,感觉还是有点不清楚

所以又快速看了一下TensorFlow1常用的方法,感觉似乎比之前清楚了一下。整理记录下方便阅读代码

这个TensorFlow教程挺好的 https://www.w3cschool.cn/tensorflow_python/

课程的话个人感觉莫凡系列的挺好懂

TensorFlow 的特点:

  • 使用图 (graph) 来表示计算任务.
  • 在被称之为 会话 (Session) 的上下文 (context) 中执行图.
  • 使用 tensor 表示数据.
  • 通过 变量 (Variable) 维护状态.
  • 使用 feed 和 fetch 可以为任意的操作(arbitrary operation) 赋值或者从其中获取数据

TensorFlow基本使用之创建图 ,在会话中使用图

import tensorflow as tf

#
# 创建一个常量,产生1*2的矩阵
m1 = tf.constant([[2, 2]])
m2 = tf.constant([[3],
                  [3]])
product = tf.matmul(m1, m2)

print(product)  # wrong! no result

# 在一个会话中启动图
# 调用 sess 的 'run()' 方法来执行矩阵乘法 op, 传入 'product' 作为该方法的参数.

# method1 use session
sess = tf.Session()
result = sess.run(product) 
# 上面提到, 'product' 代表了矩阵乘法 op 的输出, 传入它是向方法表明, 我们希望取回矩阵乘法 op 的输出.
print(result)  # 返回值 'result' 是一个 numpy `ndarray` 对象
sess.close()

# method2 use session
with tf.Session() as sess:
     result_ = sess.run(product)
     print(result_)

使用cpu,GPU

如果机器上有超过一个可用的 GPU, 除第一个外的其它 GPU 默认是不参与计算的. 为了让 TensorFlow 使用这些 GPU, 你必须将 op 明确指派给它们执行. with...Device 语句用来指派特定的 CPU 或 GPU 执行操作:

with tf.Session() as sess:
  with tf.device("/gpu:1"):
    matrix1 = tf.constant([[3., 3.]])
    matrix2 = tf.constant([[2.],[2.]])
    product = tf.matmul(matrix1, matrix2)
    ...

设备用字符串进行标识. 目前支持的设备包括:

  • "/cpu:0": 机器的 CPU.
  • "/gpu:0": 机器的第一个 GPU, 如果有的话.
  • "/gpu:1": 机器的第二个 GPU, 以此类推.

变量or feed

import tensorflow as tf

input1 = tf.placeholder(dtype=tf.float32)
input2 = tf.placeholder(dtype=tf.float32)
output = tf.multiply(input1, input2)

with tf.Session() as sess:
    result=sess.run([output], feed_dict={input1:[7.], input2:[2.]})
    print(result)



import tensorflow as tf
# 创建一个变量
var = tf.Variable(0)    # our first variable in the "global_variable" set

add_operation = tf.add(var, 1)
update_operation = tf.assign(var, add_operation)

with tf.Session() as sess:
    # 必须初始化 once define variables, you have to initialize them by doing this
    sess.run(tf.global_variables_initializer())
    for _ in range(3):
        sess.run(update_operation)
        print(sess.run(var))

激活函数

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt

# fake data
x = np.linspace(-5, 5, 200)     # x data, shape=(100, 1)

# following are popular activation functions
y_relu = tf.nn.relu(x)
y_sigmoid = tf.nn.sigmoid(x)
y_tanh = tf.nn.tanh(x)
y_softplus = tf.nn.softplus(x)
# y_softmax = tf.nn.softmax(x)  softmax is a special kind of activation function, it is about probability

sess = tf.Session()
y_relu, y_sigmoid, y_tanh, y_softplus = sess.run([y_relu, y_sigmoid, y_tanh, y_softplus])

# plt to visualize these activation function
plt.figure(1, figsize=(8, 6))
plt.subplot(221)
plt.plot(x, y_relu, c='red', label='relu')
plt.ylim((-1, 5))
plt.legend(loc='best')

plt.subplot(222)
plt.plot(x, y_sigmoid, c='red', label='sigmoid')
plt.ylim((-0.2, 1.2))
plt.legend(loc='best')

plt.subplot(223)
plt.plot(x, y_tanh, c='red', label='tanh')
plt.ylim((-1.2, 1.2))
plt.legend(loc='best')

plt.subplot(224)
plt.plot(x, y_softplus, c='red', label='softplus')
plt.ylim((-0.2, 6))
plt.legend(loc='best')

plt.show()

简单神经网络构造

import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

tf.set_random_seed(1)
np.random.seed(1)

# fake data
x = np.linspace(-1, 1, 100)[:, np.newaxis]          # shape (100, 1)
noise = np.random.normal(0, 0.1, size=x.shape)
y = np.power(x, 2) + noise                          # shape (100, 1) + some noise

# plot data
plt.scatter(x, y)
plt.show()

tf_x = tf.placeholder(tf.float32, x.shape)     # input x
tf_y = tf.placeholder(tf.float32, y.shape)     # input y

# neural network layers
l1 = tf.layers.dense(tf_x, 10, tf.nn.relu)          # hidden layer
output = tf.layers.dense(l1, 1)                     # output layer

loss = tf.losses.mean_squared_error(tf_y, output)   # compute cost
optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.5)
train_op = optimizer.minimize(loss)

sess = tf.Session()                                 # control training and others
sess.run(tf.global_variables_initializer())         # initialize var in graph

plt.ion()   # something about plotting 打开交互模式

for step in range(100):
    # train and net output
    _, l, pred = sess.run([train_op, loss, output], {tf_x: x, tf_y: y})
    if step % 5 == 0:
        # plot and show learning process
        plt.cla()#清除活动轴
        plt.scatter(x, y)
        plt.plot(x, pred, 'r-', lw=5)
        plt.text(0.5, 0, 'Loss=%.4f' % l, fontdict={'size': 20, 'color': 'red'})
        plt.pause(0.1)

plt.ioff()#关闭交互模式用于阻塞程序,不让图片关闭
plt.show()

优化器

import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

tf.set_random_seed(1)
np.random.seed(1)

LR = 0.01
BATCH_SIZE = 32

# fake data
x = np.linspace(-1, 1, 100)[:, np.newaxis]          # shape (100, 1)
noise = np.random.normal(0, 0.1, size=x.shape)
y = np.power(x, 2) + noise                          # shape (100, 1) + some noise

# plot dataset
plt.scatter(x, y)
plt.show()

# default network
class Net:
    def __init__(self, opt, **kwargs):
        self.x = tf.placeholder(tf.float32, [None, 1])
        self.y = tf.placeholder(tf.float32, [None, 1])
        l = tf.layers.dense(self.x, 20, tf.nn.relu)
        out = tf.layers.dense(l, 1)
        self.loss = tf.losses.mean_squared_error(self.y, out)
        self.train = opt(LR, **kwargs).minimize(self.loss)

# different nets
net_SGD         = Net(tf.train.GradientDescentOptimizer)
net_Momentum    = Net(tf.train.MomentumOptimizer, momentum=0.9)
net_RMSprop     = Net(tf.train.RMSPropOptimizer)
net_Adam        = Net(tf.train.AdamOptimizer)
nets = [net_SGD, net_Momentum, net_RMSprop, net_Adam]

sess = tf.Session()
sess.run(tf.global_variables_initializer())

losses_his = [[], [], [], []]   # record loss

# training
for step in range(300):          # for each training step
    index = np.random.randint(0, x.shape[0], BATCH_SIZE)
    b_x = x[index]
    b_y = y[index]

    for net, l_his in zip(nets, losses_his):
        _, l = sess.run([net.train, net.loss], {net.x: b_x, net.y: b_y})
        l_his.append(l)     # loss recoder

# plot loss history
labels = ['SGD', 'Momentum', 'RMSprop', 'Adam']
for i, l_his in enumerate(losses_his):
    plt.plot(l_his, label=labels[i])
plt.legend(loc='best')
plt.xlabel('Steps')
plt.ylabel('Loss')
plt.ylim((0, 0.2))
plt.show()

 

保存模型与加载模型

"""
Know more, visit my Python tutorial page: https://morvanzhou.github.io/tutorials/
My Youtube Channel: https://www.youtube.com/user/MorvanZhou

Dependencies:
tensorflow: 1.1.0
matplotlib
numpy
"""
import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

tf.set_random_seed(1)
np.random.seed(1)

# fake data
x = np.linspace(-1, 1, 100)[:, np.newaxis]          # shape (100, 1)
noise = np.random.normal(0, 0.1, size=x.shape)
y = np.power(x, 2) + noise                          # shape (100, 1) + some noise


def save():
    print('This is save')
    # build neural network
    tf_x = tf.placeholder(tf.float32, x.shape)  # input x
    tf_y = tf.placeholder(tf.float32, y.shape)  # input y
    l = tf.layers.dense(tf_x, 10, tf.nn.relu)          # hidden layer
    o = tf.layers.dense(l, 1)                     # output layer
    loss = tf.losses.mean_squared_error(tf_y, o)   # compute cost
    train_op = tf.train.GradientDescentOptimizer(learning_rate=0.5).minimize(loss)

    sess = tf.Session()
    sess.run(tf.global_variables_initializer())  # initialize var in graph

    saver = tf.train.Saver()  # define a saver for saving and restoring

    for step in range(100):                             # train
        sess.run(train_op, {tf_x: x, tf_y: y})

    saver.save(sess, './params', write_meta_graph=False)  # meta_graph is not recommended

    # plotting
    pred, l = sess.run([o, loss], {tf_x: x, tf_y: y})
    plt.figure(1, figsize=(10, 5))
    plt.subplot(121)
    plt.scatter(x, y)
    plt.plot(x, pred, 'r-', lw=5)
    plt.text(-1, 1.2, 'Save Loss=%.4f' % l, fontdict={'size': 15, 'color': 'red'})


def reload():
    print('This is reload')
    # build entire net again and restore
    tf_x = tf.placeholder(tf.float32, x.shape)  # input x
    tf_y = tf.placeholder(tf.float32, y.shape)  # input y
    l_ = tf.layers.dense(tf_x, 10, tf.nn.relu)          # hidden layer
    o_ = tf.layers.dense(l_, 1)                     # output layer
    loss_ = tf.losses.mean_squared_error(tf_y, o_)   # compute cost

    sess = tf.Session()
    # don't need to initialize variables, just restoring trained variables
    saver = tf.train.Saver()  # define a saver for saving and restoring
    saver.restore(sess, './params')

    # plotting
    pred, l = sess.run([o_, loss_], {tf_x: x, tf_y: y})
    plt.subplot(122)
    plt.scatter(x, y)
    plt.plot(x, pred, 'r-', lw=5)
    plt.text(-1, 1.2, 'Reload Loss=%.4f' % l, fontdict={'size': 15, 'color': 'red'})
    plt.show()


save()

# destroy previous net
tf.reset_default_graph()

reload()

tensorboard可视化

参考文档:TensorBoard:图表可视化 - TensorFlow官方文档中文版 (pythontab.com)

1.创建writer,写日志文件
writer=tf.summary.FileWriter('/path/to/logs', tf.get_default_graph())

2.保存日志文件
writer.close()

3.运行可视化命令,启动服务
tensorboard –logdir /path/to/logs

4.打开可视化界面
通过浏览器打开服务器访问端口http://xxx.xxx.xxx.xxx:6006

TensorBoard的使用流程

  1. 添加记录节点:tf.summary.scalar/image/histogram()
  2. 汇总记录节点:merged = tf.summary.merge_all()
  3. 运行汇总节点:summary = sess.run(merged),得到汇总结果
  4. 日志书写器实例化:summary_writer = tf.summary.FileWriter(logdir, graph=sess.graph),实例化的同时传入 graph 将当前计算图写入日志
  5. 调用日志书写器实例对象summary_writeradd_summary(summary, global_step=i)方法将所有汇总日志写入文件
  6. 调用日志书写器实例对象summary_writerclose()方法写入内存,否则它每隔120s写入一次

"""
Know more, visit my Python tutorial page: https://morvanzhou.github.io/tutorials/
My Youtube Channel: https://www.youtube.com/user/MorvanZhou

Dependencies:
tensorflow: 1.1.0
numpy
"""
import tensorflow as tf
import numpy as np

tf.set_random_seed(1)
np.random.seed(1)

# fake data
x = np.linspace(-1, 1, 100)[:, np.newaxis]          # shape (100, 1)
noise = np.random.normal(0, 0.1, size=x.shape)
y = np.power(x, 2) + noise                          # shape (100, 1) + some noise

with tf.variable_scope('Inputs'):#用tf.variable_scope命名Inputs(名称),x,y属于Inputs层级下的节点
    tf_x = tf.placeholder(tf.float32, x.shape, name='x')
    tf_y = tf.placeholder(tf.float32, y.shape, name='y')

with tf.variable_scope('Net'):
    l1 = tf.layers.dense(tf_x, 10, tf.nn.relu, name='hidden_layer')
    output = tf.layers.dense(l1, 1, name='output_layer')

    # add to histogram summary
    tf.summary.histogram('h_out', l1)
    tf.summary.histogram('pred', output)

loss = tf.losses.mean_squared_error(tf_y, output, scope='loss')
train_op = tf.train.GradientDescentOptimizer(learning_rate=0.5).minimize(loss)
tf.summary.scalar('loss', loss)     # add loss to scalar summary

sess = tf.Session()
sess.run(tf.global_variables_initializer())

writer = tf.summary.FileWriter('./log', sess.graph)     # write to file
merge_op = tf.summary.merge_all()                       # operation to merge all summary

for step in range(100):
    # train and net output
    _, result = sess.run([train_op, merge_op], {tf_x: x, tf_y: y})
    writer.add_summary(result, step)

# Lastly, in your terminal or CMD, type this :
# $ tensorboard --logdir path/to/log
# open you google chrome, type the link shown on your terminal or CMD. (something like this: http://localhost:6006)

注意:节点域:tf2使用tf.name_scope('XX'):使可视化更简洁

 

启动TensorBoard 

输入下面的指令来启动TensorBoard

tensorboard --logdir=/path/to/log-directory

这里的参数 logdir 指向 SummaryWriter 序列化数据的存储路径。如果logdir目录的子目录中包含另一次运行时的数据,那么 TensorBoard 会展示所有运行的数据。一旦 TensorBoard 开始运行,你可以通过在浏览器中输入 localhost:6006 来查看 TensorBoard。

梯度下降

"""
Know more, visit my Python tutorial page: https://morvanzhou.github.io/tutorials/
My Youtube Channel: https://www.youtube.com/user/MorvanZhou

Dependencies:
tensorflow: 1.1.0
matplotlib
numpy
"""
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

LR = 0.1
REAL_PARAMS = [1.2, 2.5]
INIT_PARAMS = [[5, 4],
               [5, 1],
               [2, 4.5]][2]

x = np.linspace(-1, 1, 200, dtype=np.float32)   # x data

# Test (1): Visualize a simple linear function with two parameters,
# you can change LR to 1 to see the different pattern in gradient descent.

# y_fun = lambda a, b: a * x + b
# tf_y_fun = lambda a, b: a * x + b


# Test (2): Using Tensorflow as a calibrating tool for empirical formula like following.

# y_fun = lambda a, b: a * x**3 + b * x**2
# tf_y_fun = lambda a, b: a * x**3 + b * x**2


# Test (3): Most simplest two parameters and two layers Neural Net, and their local & global minimum,
# you can try different INIT_PARAMS set to visualize the gradient descent.

y_fun = lambda a, b: np.sin(b*np.cos(a*x))
tf_y_fun = lambda a, b: tf.sin(b*tf.cos(a*x))

noise = np.random.randn(200)/10
y = y_fun(*REAL_PARAMS) + noise         # target

# tensorflow graph
a, b = [tf.Variable(initial_value=p, dtype=tf.float32) for p in INIT_PARAMS]
pred = tf_y_fun(a, b)
mse = tf.reduce_mean(tf.square(y-pred))
train_op = tf.train.GradientDescentOptimizer(LR).minimize(mse)

a_list, b_list, cost_list = [], [], []
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    for t in range(400):
        a_, b_, mse_ = sess.run([a, b, mse])
        a_list.append(a_); b_list.append(b_); cost_list.append(mse_)    # record parameter changes
        result, _ = sess.run([pred, train_op])                          # training


# visualization codes:
print('a=', a_, 'b=', b_)
plt.figure(1)
plt.scatter(x, y, c='b')    # plot data
plt.plot(x, result, 'r-', lw=2)   # plot line fitting
# 3D cost figure
fig = plt.figure(2); ax = Axes3D(fig)
a3D, b3D = np.meshgrid(np.linspace(-2, 7, 30), np.linspace(-2, 7, 30))  # parameter space
cost3D = np.array([np.mean(np.square(y_fun(a_, b_) - y)) for a_, b_ in zip(a3D.flatten(), b3D.flatten())]).reshape(a3D.shape)
ax.plot_surface(a3D, b3D, cost3D, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'), alpha=0.5)
ax.scatter(a_list[0], b_list[0], zs=cost_list[0], s=300, c='r')  # initial parameter place
ax.set_xlabel('a'); ax.set_ylabel('b')
ax.plot(a_list, b_list, zs=cost_list, zdir='z', c='r', lw=3)    # plot 3D gradient descent
plt.show()

 

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

TensorFlow学习笔记(一) 的相关文章

  • python多线程学习

    Python3 线程中常用的两个模块为 xff1a thread xff08 已经废弃 xff09 threading 推荐使用 线程模块 Python3 通过两个标准库 thread 和 threading 提供对线程的支持 thread
  • 爬虫实战之多线程下载表情包

    一般下载 import requests from lxml import etree import os import re from urllib request import urlretrieve headers 61 39 Use
  • 卷积padding,kernel_initializer

    TensorFlow和 keras layers convolutional Conv1D和tf layers Conv1D函数 keras layers convolutional Conv1D filters kernel size s
  • python刷题之链表常见操作

    链表常用操作 也可以把列表当做队列用 xff0c 只是在队列里第一加入的元素 xff0c 第一个取出来 xff1b 但是拿列表用作这样的目的效率不高 在列表的最后添加或者弹出元素速度快 xff0c 然而在列表里插入或者从头部弹出速度却不快
  • 刷题之链表

    链表相关 19 删除链表的倒数第 N 个结点 难度中等1261收藏分享切换为英文接收动态反馈 给你一个链表 xff0c 删除链表的倒数第 n 个结点 xff0c 并且返回链表的头结点 进阶 xff1a 你能尝试使用一趟扫描实现吗 xff1f
  • 高级爬虫: 使用 Selenium 浏览器

    安装Selenium和chromedriver xff1a 因为 Selenium 需要操控你的浏览器 所以安装起来比传统的 Python 模块要多几步 先在 terminal 或者 cmd 用 pip 安装 selenium python
  • python刷题之栈和队列

    20 有效的括号 难度简单2228 给定一个只包括 39 39 xff0c 39 39 xff0c 39 39 xff0c 39 39 xff0c 39 39 xff0c 39 39 的字符串 s xff0c 判断字符串是否有效 有效字符串
  • python实现堆的基本操作及堆相关练习

    堆 heap 又被为优先队列 priority queue 尽管名为优先队列 xff0c 但堆并不是队列 回忆一下 xff0c 在队列中 xff0c 我们可以进行的限定操作是dequeue和enqueue dequeue是按照进入队列的先后
  • python刷题之集合、哈希表常见操作及练习

    集合 集合是一个无序不重复元素的集 基本功能包括关系测试和消除重复元素 可以用大括号 创建集合 注意 xff1a 如果要创建一个空集合 xff0c 你必须用 set 而不是 xff1b 后者创建一个空的字典 xff0c 下一节我们会介绍这个
  • 用selenium爬取拉勾网职位信息及常见问题处理

    初步爬虫框架构造 下面采用selenium进行爬虫 xff0c 首先构造一下爬虫的框架 xff0c 将整个程序构造为一个类 xff0c 其中主要包括 xff1a 获取每个详细职位信息的链接 xff08 parse page url xff0
  • Scrapy爬虫快速入门

    Scrapy快速入门 Scrapy框架模块功能 xff1a Scrapy Engine xff08 引擎 xff09 xff1a Scrapy框架的核心部分 负责在Spider和ItemPipeline Downloader Schedul
  • 嵌入式系统USB CDROM虚拟光驱驱动程序开发

    带U盘功能的的USB接口设备已经越来越常见了 如果能够把产品说明书或者产品设备驱动程序做成一个USB CDROM xff0c 那该多方便 假设 xff1a 你已经有了USB mass storage驱动 你的任务是在此基础上增加一个USB
  • Redis集群原理详解

    一 Redis集群介绍 xff1a 1 为什么需要Redis集群 xff1f 在讲Redis集群架构之前 xff0c 我们先简单讲下Redis单实例的架构 xff0c 从最开始的一主N从 xff0c 到读写分离 xff0c 再到Sentin
  • python刷题之快慢指针与二分查找

    141 环形链表 难度简单986 给定一个链表 xff0c 判断链表中是否有环 如果链表中有某个节点 xff0c 可以通过连续跟踪 next 指针再次到达 xff0c 则链表中存在环 为了表示给定链表中的环 xff0c 我们使用整数 pos
  • LeetCode每日一题

    191 位1的个数 难度简单290 编写一个函数 xff0c 输入是一个无符号整数 xff08 以二进制串的形式 xff09 xff0c 返回其二进制表达式中数字位数为 39 1 39 的个数 xff08 也被称为汉明重量 xff09 提示
  • scrapy模拟豆瓣登录

    看的课程是21天搞定分布式爬虫 xff0c 应该是几年前的了 xff0c 课程当时还是验证码 xff0c 现在登录和之前都不一样了现在需要你拖动滑块完成拼图 之前的页面 现在验证码都变成拼图了 学学原理吧 首先创建scrapy项目 首先进入
  • 利用Scrapy框架爬取汽车之家图片(详细)

    爬取结果 爬取步骤 创建爬虫文件 进入cmd命令模式下 xff0c 进入想要存取爬虫代码的文件 xff0c 我这里是进入e盘下的E pystudy scraping文件夹内 C Users wei gt E E gt cd E pystud
  • Scrapy框架下载器和随机请求头

    下载器中间键可以为我们设置多个代理ip与请求头 xff0c 达到反反爬虫的目的 下面是scrapy为我们创建好的中间件的类 Process request self request spider 参数 request 发送请求的reques
  • scrapy爬取完整网页完整数据,简书(最新)

    需求 xff1a 简书网站整站爬虫 数据保存到mysql数据库中 将seleniume 43 chromedriver集成到scrapy 爬取结果如下 xff1a 安装Selenium和chromedriver xff1a https bl
  • 图和图的基本知识

    1 1 图的表示 1 2 图的特性 子图Subgraph 连通分量Connected Component 接通图Connected Graph 最短路径Shortest Path 图直径Diameter 1 3 图中心性 Centralit

随机推荐

  • BFS和DFS的python实现(要记住)

    BFS DFS python模板与实现 BFS模板 1 无需分层遍历 while queue 不空 xff1a cur 61 queue pop for 节点 in cur的所有相邻节点 xff1a if 该节点有效且未访问过 xff1a
  • BFS与 DFS题目练习(python)

    107 二叉树的层序遍历 II 难度中等423 给定一个二叉树 xff0c 返回其节点值自底向上的层序遍历 xff08 即按从叶子节点所在层到根节点所在的层 xff0c 逐层从左向右遍历 xff09 例如 xff1a 给定二叉树 3 9 2
  • LeetCode每日一题-合并两个有序数组

    88 合并两个有序数组 难度简单878 给你两个有序整数数组 nums1 和 nums2 xff0c 请你将 nums2 合并到 nums1 中 xff0c 使 nums1 成为一个有序数组 初始化 nums1 和 nums2 的元素数量分
  • debian 系统无声音

    系统识别了硬件 xff0c 加载了内核 可是就是没声音 在基础条件都满足的情况下 xff0c 尝试输入 xff1a sudo alsactl init 反正我是一输入声音就出来了 转载于 https my oschina net skyoo
  • 爬虫实战-爬取房天下网站全国所有城市的新房和二手房信息(最新)

    看到https www cnblogs com derek1184405959 p 9446544 html项目 xff1a 爬取房天下网站全国所有城市的新房和二手房信息和其他博客的代码 xff0c 因为网站的更新或者其他原因都不能正确爬取
  • pytorch 模型保存与加载 cpu转GPU

    model eval 的重要性 在2 中最后用到了model eval 是因为 只有在执行该命令后 34 dropout层 34 及 34 batch normalization层 34 才会进入 evalution 模态 而在 34 训练
  • 数据分析及数据分析的工作流程

    1 什么是数据分析 数据分析是根据业务问题 xff0c 对数据进行收集 xff0c 清洗 xff0c 处理和建模的过程 xff0c 用于识别有助于业务的信息 xff0c 获取关键业务结论并辅助决策 界定业务问题 xff08 以宜家为例 xf
  • SQL练习网站

    之前上过数据库的课程 xff0c 但感觉零零散散 xff0c 现在已经不记得多少 xff0c 一方面是没有总结另一方面是没有练习 https sqlbolt com 但感觉网页加载的很慢 但我发现以上两者结合起来棒棒哒 有中文 xff0c
  • SQL入门(二)查询执行顺序

    完整查询 SELECT DISTINCT column AGG FUNC column or expression FROM mytable JOIN another table ON mytable column 61 another t
  • SQL入门之基本语法

    下面是为了方便查考在GitHub上找到的一个教程 目录 开始使用 登录MySQL创建数据库创建数据库表增删改查 SELECTUPDATEINSERTDELETEWHEREAND 和 OR ANDORORDER BYINNOTUNIONASJ
  • python有向图,无向图绘制

    https www jianshu com p 52bb142314ebR语言画网络图 https blog csdn net fly hawk article details 78513257 python绘制无向图 xff0c 输入数据
  • 知识追踪待解决问题记录-交流贴

    记录遇到知识追踪的问题 xff0c 欢迎大家进行留言交流 1 DKT中的图如何画的 好像是根据这个公式 但还没画出来 2 GKT跑的效果很差 可能原因是作者对数据的特殊处理 xff0c 作者的实验数据好像不是assistment的 后面有人
  • conda安装包遇到问题An unexpected error has occurred. Conda has prepared the above report.

    之前还没问题 xff0c 现在就 base C Users wei gt conda activate tensoflow1 tensoflow1 C Users wei gt conda install seaborn Collectin
  • Requests库爬取实例

    网络爬虫的盗亦有道 网络爬虫的尺寸 爬取网页 xff0c 玩转网页 xff1a 小规模 xff0c 数据量小 xff0c 爬取速度不敏感 xff1b Requests库 爬取网站 爬取系列网站 xff1a 中规模 xff0c 数据量较大 x
  • Java8两个集合(List)取交集、并集、差集、去重并集

    Java8两个集合 List 取交集 并集 差集 去重并集 java guava 集合的操作 xff1a 交集 差集 并集 span class token keyword import span span class token name
  • XML,JSON,YAML

    信息标记的三种形式 信息的标记 xff1a 标记后的信息可形成信息组织结构 xff0c 增加了信息维度 标记后的信息可用于通信 存储和展示 标记的结构与信息一样具有重要价值标记后的信息有利于程序理解和运用 HTML的信息标记 xff1a H
  • python爬虫 2021中国大学排名定向爬虫

    最近的几篇博客来源是之前我下载的一个课件 在网上搜索了一下是一下这个课程的 xff0c 可以结合视频博客以及代码去更好地学习 Python网络爬虫与信息提取 北京理工大学 中国大学MOOC 慕课 icourse163 org 但是课程内容的
  • 爬虫小案例之爬取京东商品链接

    观察URL翻页的变化 爬取页面URL如下 base url 61 39 https search jd com Search keyword 61 39 43 keyword for x in range 1 num 43 1 url 61
  • Tensorflow,pytorch查看模型参数,模型可视化

    参数结构打印 TensorFlow1 12的打印结构 xff1a for var in tf trainable variables print 34 Listing trainable variables 34 print var Ten
  • TensorFlow学习笔记(一)

    TensorFlow版本2发布后 xff0c 使用TensorFlow变得更简单和方便 xff0c 但看网上的很多代码是使用的TensorFlow1进行完成的 xff0c 每次遇到不懂的函数去查 xff0c 理解记忆的一般 xff0c 感觉