深度学习与计算机视觉系列(1)_基础介绍

作者:寒小阳
时间:2015年11月。
出处:http://blog.csdn.net/han_xiaoyang/article/details/49876119
声明:版权所有,转载请注明出处,谢谢。

1.背景

计算机视觉/computer vision是一个火了N年的topic。持续化升温的原因也非常简单:在搜索/影像内容理解/医学应用/地图识别等等领域应用太多,大家都有一个愿景『让计算机能够像人一样去”看”一张图片,甚至”读懂”一张图片』。

有几个比较重要的计算机视觉任务,比如图片的分类,物体识别,物体定位于检测等等。而近年来的神经网络/深度学习使得上述任务的准确度有了非常大的提升。加之最近做了几个不大不小的计算机视觉上的项目,爱凑热闹的博主自然不打算放过此领域,也边学边做点笔记总结,写点东西,写的不正确的地方,欢迎大家提出和指正。

2.基础知识

为了简单易读易懂,这个课程笔记系列中绝大多数的代码都使用python完成。这里稍微介绍一下python和Numpy/Scipy(python中的科学计算包)的一些基础。

2.1 python基础

python是一种长得像伪代码,具备高可读性的编程语言。
优点挺多:可读性相当好,写起来也简单,所想立马可以转为实现代码,且社区即为活跃,可用的package相当多;缺点:效率一般。

2.1.1 基本数据类型

最常用的有数值型(Numbers),布尔型(Booleans)和字符串(String)三种。

  • 数值型(Numbers)

可进行简单的运算,如下:

x = 5
print type(x) # Prints "<type 'int'>"
print x       # Prints "5"
print x + 1   # 加; prints "6"
print x - 1   # 减; prints "4"
print x * 2   # 乘; prints "10"
print x ** 2  # 幂; prints "25"
x += 1  #自加
print x  # Prints "6"
x *= 2  #自乘
print x  # Prints "12"
y = 2.5
print type(y) # Prints "<type 'float'>"
print y, y + 1, y * 2, y ** 2 # Prints "2.5 3.5 5.0 6.25"

PS:python中没有x++ 和 x– 操作

  • 布尔型(Booleans)

包含True False和常见的与或非操作

t = True
f = False
print type(t) # Prints "<type 'bool'>"
print t and f # 逻辑与; prints "False"
print t or f  # 逻辑或; prints "True"
print not t   # 逻辑非; prints "False"
print t != f  # XOR; prints "True" 
  • 字符串型(String)

字符串可以用单引号/双引号/三引号声明

hello = 'hello'   
world = "world"   
print hello       # Prints "hello"
print len(hello)  # 字符串长度; prints "5"
hw = hello + ' ' + world  # 字符串连接
print hw  # prints "hello world"
hw2015 = '%s %s %d' % (hello, world, 2015)  # 格式化字符串
print hw2015  # prints "hello world 2015"

字符串对象有很有有用的函数:

s = "hello"
print s.capitalize()  # 首字母大写; prints "Hello"
print s.upper()       # 全大写; prints "HELLO"
print s.rjust(7)      # 以7为长度右对齐,左边补空格; prints "  hello"
print s.center(7)     # 居中补空格; prints " hello "
print s.replace('l', '(ell)')  # 字串替换;prints "he(ell)(ell)o"
print '  world '.strip()  # 去首位空格; prints "world"
2.1.2 基本容器
  • 列表/List

和数组类似的一个东东,不过可以包含不同类型的元素,同时大小也是可以调整的。

xs = [3, 1, 2]   # 创建
print xs, xs[2]  # Prints "[3, 1, 2] 2"
print xs[-1]     # 第-1个元素,即最后一个
xs[2] = 'foo'    # 下标从0开始,这是第3个元素
print xs         # 可以有不同类型,Prints "[3, 1, 'foo']"
xs.append('bar') # 尾部添加一个元素
print xs         # Prints 
x = xs.pop()     # 去掉尾部的元素
print x, xs      # Prints "bar [3, 1, 'foo']"

列表最常用的操作有:
切片/slicing
即取子序列/一部分元素,如下:

nums = range(5)    # 从1到5的序列
print nums         # Prints "[0, 1, 2, 3, 4]"
print nums[2:4]    # 下标从2到4-1的元素 prints "[2, 3]"
print nums[2:]     # 下标从2到结尾的元素
print nums[:2]     # 从开头到下标为2-1的元素  [0, 1]
print nums[:]      # 恩,就是全取出来了
print nums[:-1]    # 从开始到第-1个元素(最后的元素)
nums[2:4] = [8, 9] # 对子序列赋值
print nums         # Prints "[0, 1, 8, 8, 4]"

循环/loops
即遍历整个list,做一些操作,如下:

animals = ['cat', 'dog', 'monkey']
for animal in animals:
    print animal
# 依次输出 "cat", "dog", "monkey",每个一行.

可以用enumerate取出元素的同时带出下标

animals = ['cat', 'dog', 'monkey']
for idx, animal 
  • 47
    点赞
  • 152
    收藏
    觉得还不错? 一键收藏
  • 24
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 24
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值