def verify_image_jpeg(imagepath, imageshape):
scope = inspect.stack()[0][3]
try:
graph = tf.get_default_graph()
path = graph.get_tensor_by_name(scope + '/path:0')
decode = graph.get_tensor_by_name(scope + '/decode_jpeg:0')
except KeyError:
tf.logging.debug('creating decode_jpeg tensor')
path = tf.placeholder(tf.string, name=scope + '/path')
imagefile = tf.read_file(path, name=scope + '/read_file')
decode = tf.image.decode_jpeg(imagefile, channels=3, name=scope + '/decode_jpeg')
try:
image = tf.get_default_session().run(decode, {path: imagepath})
except:
return False
return np.all(np.equal(image.shape[:2], imageshape[:2]))
评论列表
文章目录