label_bytesとbytestream.seekの用法がわかりません。
http://www.buildinsider.net/small/booktensorflow/0201
を参考にして今Tensorflowの勉強をしています。
しかし、以下のコードを書いたとき
# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import numpy as np class Cifar10Record(object): width = 32 height = 32 depth = 3 def set_label(self,label_byte): self.label = np.frombuffer(label_byte,dtype=np.uint8) def set_image(self,image_bytes): byte_buffer = np.frombuffer(image_bytes,dtype=np.int8) reshaped_array = np.reshape(byte_buffer,[self.depth,self.height,self.width]) self.byte_array = np.transpose(reshaped_array,[1,2,0]) self.byte_array = self.byte_array.astype(np.float32) class Cifar10Reader(object): def __init__(self,filename): if not os.path.exists(filename): print(filename + ' is not exist') return self.bytestream = open(filename,mode="rb") def close(self): if not self.bytestream: self.bytestream.close() def read(self,index): result = Cifar10Record() label_bytes = 1 image_bytes = result.height * result.width * result.depth record_bytes = label_bytes + image_bytes self.bytestream.seek(record_bytes * index,0) result.set_label(self.bytestream.read(label_bytes)) result.set_image(self.bytestream.read(image_bytes)) return result
以下の部分でlabel_bytesを使っていてこの用法がわかりません。
def read(self,index): result = Cifar10Record() label_bytes = 1 image_bytes = result.height * result.width * result.depth record_bytes = label_bytes + image_bytes self.bytestream.seek(record_bytes * index,0) result.set_label(self.bytestream.read(label_bytes)) result.set_image(self.bytestream.read(image_bytes)) return result
なぜ画像を認識するシステムで、それぞれの画像のバイト数は違うのに、 label_bytesで1を固定で設定しているのでしょうか?
さらに、 record_bytesでlabel_bytes とimage_bytes の足し算を行っていて
それをbytestream.seekメソッドで渡している理由もわかりません。
bytestream.seekメソッドを検索したのですが、この書き特有のものなのか、リファレンスが出てこなくて...。
この書き方はこのコード特有なものかと思いきや
http://qiita.com/qooa/items/561ac4cbd20a276ebd42
で別の画像認識を行っている方も同じ書き方をしています。
この部分は画像認識にマストなものなのでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/04/12 02:20
2017/04/12 02:29 編集
退会済みユーザー
2017/04/12 02:35