Enviado em 07/06/2020 - 15:02h
Fala galera, suavidade? Primeiro tópico que faço por aqui, procurei algo por aqui parecido e não encontrei. Se criei algo errado ou duplicado, me desculpe.
Pessoal estou precisando converter um tfrecord, TENSORFLOW, para JPEG. Porem ele está retornado um erro que não sei como corrigir, se alguém conseguir me ajudar, segue o erro.
Tensor("DecodeJpeg:0", shape=(?, ?, 1), dtype=uint8)
Expected image (JPEG, PNG, or GIF), got empty file
[[node DecodeJpeg (defined at <ipython-input-1-95e438777d08>:38) ]]
Segue o código que estou utilizando
Se alguém conseguir me dar uma luz, ficaria muito grato. Obrigado
Pessoal estou precisando converter um tfrecord, TENSORFLOW, para JPEG. Porem ele está retornado um erro que não sei como corrigir, se alguém conseguir me ajudar, segue o erro.
Tensor("DecodeJpeg:0", shape=(?, ?, 1), dtype=uint8)
Expected image (JPEG, PNG, or GIF), got empty file
[[node DecodeJpeg (defined at <ipython-input-1-95e438777d08>:38) ]]
Segue o código que estou utilizando
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
from google.colab import drive
drive.mount('/content/drive')
c = 0 ##NUMERO DE IMAGENS NO TFRECORD
totalFile=0
##pegar o tfrecord do meu drive
tfrco="/content/drive/My Drive/ColabNotebooks/ddsm-mammography/training10_0/training10_0.tfrecords"
output_path = "/content/drive/My Drive/ColabNotebooks/ddsm-mammography/training10_0/Images10_0"
for record in tf.python_io.tf_record_iterator(tfrco):
c += 1
totalFiles=c
####logfile.write(" {} : {}".format(f, c))
####logfile.flush()
##print("VAI RESTAURAR {} ARQUIVOS {}".format(c,f))
tf.reset_default_graph()
## CAMINHO DE UM TFRECORD PARA LISTA
fq = tf.train.string_input_producer([tfrco], num_epochs=totalFiles)
reader = tf.TFRecordReader()
_, v = reader.read(fq)
fk = {
'image/encoded': tf.FixedLenFeature((), tf.string, default_value=''),
'image/class/synset': tf.FixedLenFeature([], tf.string, default_value=''),
'image/filename': tf.FixedLenFeature([], tf.string, default_value='')
}
ex = tf.parse_single_example(v, fk)
imagem = tf.image.decode_jpeg(ex['image/encoded'], channels=1)
label = tf.cast(ex['image/class/synset'], tf.string)
fileName = tf.cast(ex['image/filename'], tf.string)
## INICIALIZAR VARIAVEIS
init_op = tf.group(tf.global_variables_initializer(),
tf.local_variables_initializer())
sess = tf.Session()
sess.run(init_op)
##aumentar velocidade de gravação
coord = tf.train.Coordinator()
threads = tf.train.start_queue_runners(coord=coord, sess = sess)
#sess.run([tf.global_variables_initializer(),tf.local_variables_initializer()])
## NUMERO DE IMAGENS NO TFRECORD
num_images=c
print("VAI RESTAURAR {} ARQUIVOS ".format(num_images))
print(label)
print(fileName)
print(imagem)
for i in range(num_images):
try:
im_,lbl,fName = sess.run([imagem,label,fileName])
except Exception as e:
print(e)
break
lbl_=lbl.decode("utf-8")
savePath=os.path.join(output_path,lbl_)
if not os.path.exists(savePath):
os.makedirs(savePath)
fName_=os.path.join(savePath, fName.decode("utf-8").split('_')[1])
## CAMINHO A SALVAR
cv2.imwrite(fName_ , im_)
print(fName)
coord.request_stop()
coord.join(threads)
Se alguém conseguir me dar uma luz, ficaria muito grato. Obrigado