ADMMutils.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:sparsecnn 作者: fkiaee 项目源码 文件源码
def ImageProducer(filename_queue): 
    filename = os.path.realpath(os.path.join(os.path.dirname(__file__), 'cifar10/zca.pkl'))
    file = open(filename, 'rb')
    data = pickle.load(file)
    file.close() 
    Wzca= tf.constant(data['zca'],tf.float32)
    label_bytes = 1; 
    height = 32; width = 32; depth = 3
    image_bytes = height * width * depth
    record_bytes = label_bytes + image_bytes
    reader = tf.FixedLengthRecordReader(record_bytes=record_bytes)
    key, value = reader.read(filename_queue)
    record_bytes = tf.decode_raw(value, tf.uint8)
    label_byte_slices = tf.slice(record_bytes, [0], [label_bytes]);
    label = tf.cast(label_byte_slices, tf.int32)
    image = tf.slice(record_bytes, [label_bytes], [image_bytes])#tf.reshape(tf.slice(record_bytes, [label_bytes], [image_bytes]),[depth,height,width])
    image = tf.cast(image, tf.float32)   
    image = tf.reshape(image,[1,image_bytes])  
    image = tf.sub(image,tf.reduce_mean(image))
    scale = tf.constant(55.); thresh = tf.constant(1.)
    std_val  = tf.div(tf.sqrt(tf.reduce_sum(tf.square(image))),scale); 
    f4 = lambda: std_val
    f5 = lambda: thresh
    normalizer = tf.cond(tf.less(std_val,1e-8),f5,f4)
    image = tf.div(image,normalizer)
    image = tf.sub(image,tf.reduce_mean(image))
    img_RGB = tf.matmul(image,Wzca)
    depth_major = tf.reshape(img_RGB,[depth,height,width])
    image = tf.transpose(depth_major, [1, 2, 0])  
    return image, label
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号