跑深度学习网络时碰到的一些问题记录

分两部分记录:

一.日志信息

二.程序语言

#############################################################################

一.日志信息

    在TRAIN_DIR路径下会产生四种文件:

        1.checkpoint:文本文件,包含所有model.ckpt-xxxx,相当于是不同时间节点生成的所有ckpt文件的一个索引。

        2.model.ckpt-2124.data-000000-of-000001:模型文件,保存模型的权重

        3.model.ckpt-2124.meta: 图文件,保存模型的网络图

        4.model.ckpt-2124.index: 这个不清楚

        5.graph.pbtxt: 用protobuf格式保存的模型的图

    Tensorflow使用五个不同级别的日志消息。按照上升的顺序,它们是DEBUG,INFO,WARN,ERROR和FATAL。当在任何这些级别配置日志记录时,Tensorflow将输出与该级别相对应的所有日志消息以及所有级别的严格级别。例如,如果设置了ERROR的日志记录级别,则会收到包含ERROR和FATAL消息的日志输出,如果设置了一个DEBUG级别,则会从所有五个级别获取日志消息。

    默认情况下,Tensorflow在WARN的日志记录级别进行配置,但是在跟踪模型训练时,需要将级别调整为INFO,tf.logging.set_verbosity(tf.logging.INFO)

二.程序语言

1.join 和 os.path.join函数

    join:用于合并字符串数组

    os.path.join:用于合并多个路径

import os
dataset_dir = '.'
file_pattern = 'fgvc_%s.tfrecord'
split_name = 'train'
a = os.path.join(dataset_dir, file_pattern % (split_name))
print a   #./fgvc_train.tfrecord

2.tf.expand_dims 和 tf.squeeze

    tf.expand_dims: 用于增加维度(点击打开链接)

import tensorflow as tf
a = tf.constant([[1,2,3],[4,5,6]])
with tf.Session() as sess:
    print sess.run(a)
    '''
    [[1 2 3]
     [4 5 6]]
     '''
    print tf.shape(a)
    '''
    Tensor("Shape_5:0", shape=(2,), dtype=int32)
    '''
    a_1 = tf.expand_dims(a,0)
    print sess.run(a_1)
    '''
    [[[1 2 3]
      [4 5 6]]]
    '''
    print tf.shape(a_1)
    '''
    Tensor("Shape_6:0", shape=(3,), dtype=int32)
    '''
    a_2 = tf.expand_dims(a,-1)
    print sess.run(a_2)
    '''
    [[[1]
      [2]
      [3]]

     [[4]
      [5]
      [6]]]
    '''
    print tf.shape(a_2)
    '''
    Tensor("Shape_7:0", shape=(3,), dtype=int32)
    '''
    a_3 = tf.expand_dims(a,1)
    print sess.run(a_3)
    '''
    [[[1 2 3]]

     [[4 5 6]]]
     '''
    print tf.shape(a_3)
    '''
    Tensor("Shape_8:0", shape=(3,), dtype=int32)
    '''

      tf.squeeze:减少多余的维度

import tensorflow as tf
a = tf.constant([[1]])
b = tf.constant([[[1,2],[3,4]]])
with tf.Session() as sess:
    print sess.run(a) #[[1]]
    print sess.run(tf.squeeze(a)) # 1
    print sess.run(b) 
    '''
    [[[1 2]
      [3 4]]]
      '''
    print sess.run(tf.squeeze(b))
    '''
    [[1 2]
     [3 4]]
    '''

    3.tf.cast 函数

   用法:tf. cast(x, dtype, name=None)

  作用:将x的数据格式转化成dtype.

import tensorflow as tf
a = tf.constant([[1.2]])
b = tf.constant([[[1,2],[3,4]]])
with tf.Session() as sess:
    print sess.run(a) #[[1.2]]
    print sess.run(tf.cast(a, tf.int32))# [[1]]

    dtype类别有:tf.bool, tf.int32, tf.int64, tf.float32, tf.float64

4.将Tensor张量转化为numpy数组

点击打开链接

注:tensorflow里面不能将张量转化成矩阵后用numpy计算,因为numpy里不能实现梯度反传。

5.不能用for循环遍历图片的所有像素点,这样会导致op节点爆炸。

6.如果采用tf.initialize_all_variables().run(),所有权重都将初始化,如果只训练某一层权重则不应用这句命令。

详细内容:点击打开链接

7.tf查找元素相关程序  点击打开链接

8.tf.matmul与tf.multiply

    tf.matmul:矩阵乘法

    tf.multiply:element-wise。对应元素相称,如两个矩阵的第一行第一列相乘。

9.tf.shape(a) 和a.get_shape()

点击打开链接

10.tf.argmax   返回最大值的下标

        tf.argmax(    ,axis = 0)    纵向比较

        tf.argmax(    , axis = 1)   横向比较

点击打开链接

11.

猜你喜欢

转载自blog.csdn.net/weixin_39880579/article/details/80493391