Google engineer Qinshou Tensorflow2.0- introductory to advanced

  • Chapter 1 Tensorflow Introduction and environmental structures
  • Chapter 2 Tensorflow keras combat
  • Chapter 3 Tensorflow basis using the API
  • Chapter 4 Tensorflow dataset use
  • Chapter 5 Tensorflow Estimator uses tf1.0
  • Chapter 6 convolutional neural network
  • Chapter 7 Recurrent Neural Networks
  • Chapter 8 Tensorflow distributed
  • Chapter 9 Tensorflow save and deployment model
  • Chapter 10 Machine Translation

    Plus group receive a free full set of learning materials

    Courses to Tensorflow2.0 framework as the main image classification, forecasting prices, text classification, text generation, machine translation, Titanic and other projects as the basis to predict survival

    Explain Tensorflow framework to use, so that students gain the ability to use flexible Tensorflow while learning related to the depth of learning / knowledge of machine learning, deep learning at junior engineer

    More sharing resources as follows:

    Advanced data entry comprehensive Python3 +

    Python3 data analysis and modeling of actual mining

    Python build a distributed search engine crawlers

    Classical algorithms and machine learning applications Python3 entry

    Advanced Programming Python Flask RESTFul API before and after the end of the separation succinctly

    Based TensorFlow Application of Artificial Intelligence Fun hottest Python framework

    Other 3 small exception handling skills

    Highlights:

    1) take the initiative to throw an exception

    2) the use of assertions identify problems

    3) How to deal with multiple exceptions

    1. Take the initiative to throw an exception

    When the program in the occurrence of certain conditions when we want the program to be able to take the initiative thrown after, we generally raise statement, throw an exception if there is no try / except, it would throw the python interpreter to handle

    The basic syntax:

    raise SomeException,args

    • The first parameter is the name of SomeException trigger an exception must be a string, a class or instance

    • Args tuple reasons described abnormality information, abnormality We generally string

    for i in range(1,5):

    if i>3:

    raise ValueError,'i>3'

    else:

    print i

    >>

    1

    2

    3

    raise ValueError,'i>3'

    若我们想自己去处理抛出的异常,我们需要加上try/except

    try:

    for i in range(1,5):

    if i>3:

    raise ValueError,'i>3'

    else:

    print i

    except ValueError,e:

    print 'catch the value error:',e

    >>

    1

    2

    3

    catch the value error: i>3

    2.利用assert语句来发现问题

    和其他的主流语言c,c++一样,python也有断言,assert语句是一种有条件在程序代码中触发异常,主要是为了调试程序服务的,能快速方便的查找程序的异常,或者一些不恰当的输入.

    assert的用法如下:

    assert expression ,args

    • expression 是一个表达式

    • args 是对条件判断的描述信息

    也就是说如果表达式为假,就会触发异常,所以一般我们会把表达式写成我们认为正确的程序应该满足的条件,相当于我们代码块做的一条报警线,告诉你,正确路应该怎么走,一旦不满足正确的行为,就会响起警报 ,触发异常

    x=10

    y=20

    assert x==y ,'x not equal y'

    >>

        assert x==y ,'x not equal y'

    AssertionError: x not equal y

    上面的代码,我们设的警戒线是x==y,这个是正确的行为,一旦x不等于y, 就会抛出异常,它在执行的过程中其实相当于执行如下代码:

    x=10

    y=20

    if __debug__ and not x==y:

    raise AssertionError('x not equal y')

    >>

    raise AssertionError('x not equal y')

    AssertionError: x not equal y

    __debug__是Python内置的系统关键字,就像None一样,而且默认为True,只能读不能写.(也许有小伙伴会问我什么是内置的关键字可以看我的历史文章:'如果避开变量作用域的陷阱')

    有的同学说assert这么好,是不是可以多用错了:

    1).assert 虽然不错,但是不要滥用,断言是设计用来捕获用户自定义的约束, 而不是捕获程序本身的错误

    2).如果程序本身的异常能够处理就不要用断言,比如列表越界啊,类型不匹配啊,除数为0这样的错误

    3).还有处理用户的输入,最好用条件判断,不符合条件的时候输出错误信息就可以了.

    3.如何处理多个异常 

    比如我们在打开文件的时候,有可能会遇到各种异常,比如文件不存在啊,权限不够啊等等,我们希望能归类到一个元组里面,用一个代码块来处理所有不同的异常,可以用下面的方法:

    try:

        f=open('xxx.txt'):

        do_something(f)

    except (FileNotFoundError,PermissionError):

        handle_file_error()

    finally:

    f.close()

    这个是示例代码(这段代码不能运行),其中的FileNotFoundError,PermissionError都是继承OSError(关于类的概念我们后面的文章会详细讲)

      • 特别是有子类继承父类的时候,嵌套的时候,因为except是按照顺序进行的,只要有一个触发了,就不在往下检查了

      • 如果各个异常类之间具有继承关系,则子类应该写在前面,否则父类将会直接截获子类异常

    如果我们写成下面这样:

    try:

    f=open('missing')

    except OSError:

    print ('It failed')

    except FileNotFoundError:

    print ('File not found')

    想上面这样的情况,FileNotFoundError永远不会执行,因为父类OSError写在了前面.

Guess you like

Origin www.cnblogs.com/qiaoke6/p/11613287.html