我正在根据自己的需要调整以下代码 https://github.com/tensorflow/models/blob/master/slim/datasets/download_and_convert_flowers.py
我需要添加零填充并将图像大小调整为299x299(启动V3输入大小)。
我这样做会添加一些代码来改变原来的
image_data = tf.gfile.FastGFile(filenames[i], 'r').read()
height, width = image_reader.read_image_dims(sess, image_data)
class_name = os.path.basename(os.path.dirname(filenames[i]))
class_id = class_names_to_ids[class_name]
example = dataset_utils.image_to_tfexample(
image_data, 'jpg', height, width, class_id)
用这个
image_data = tf.gfile.FastGFile(filenames[i], 'r').read()
height, width = image_reader.read_image_dims(sess, image_data)
image_decoded = tf.image.decode_jpeg(image_data, channels=None, ratio=None, fancy_upscaling=None, try_recover_truncated=None, acceptable_fraction=None, name=None)
M=max(width,height)
image_decoded = tf.image.pad_to_bounding_box(image_decoded, int(math.floor((M-height)/2)), int(math.floor((M-width)/2)), M, M)
image_decoded = tf.expand_dims(image_decoded, 0)
image_decoded = tf.image.resize_bilinear(image_decoded, [299, 299], align_corners=None, name=None)
image_decoded = tf.squeeze(image_decoded)
image_decoded = tf.bitcast(image_decoded, tf.uint8)
image_data = tf.image.encode_jpeg(image_decoded)
class_name = os.path.basename(os.path.dirname(filenames[i]))
class_id = class_names_to_ids[class_name]
example = dataset_utils.image_to_tfexample(image_data, b'jpg', height, width, class_id)
我收到以下错误
File "convert_dataset.py", line 236, in <module>
tf.app.run()
File "/home/franco/tensorflow/local/lib/python2.7/site-packages/tensorflow/python/platform/app.py", line 44, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "convert_dataset.py", line 233, in main
run(FLAGS.dataset_dir)
File "convert_dataset.py", line 217, in run
dataset_dir)
File "convert_dataset.py", line 165, in _convert_dataset
example = dataset_utils.image_to_tfexample(image_data, b'jpg', height, width, class_id)
File "/home/franco/Desktop/dataset_originario/dataset/dataset_utils.py", line 58, in image_to_tfexample
'image/encoded': bytes_feature(image_data),
File "/home/franco/Desktop/dataset_originario/dataset/dataset_utils.py", line 53, in bytes_feature
return tf.train.Feature(bytes_list=tf.train.BytesList(value=[values]))
File "/home/franco/tensorflow/lib/python2.7/site-packages/google/protobuf/internal/python_message.py", line 508, in init
copy.extend(field_value)
File "/home/franco/tensorflow/lib/python2.7/site-packages/google/protobuf/internal/containers.py", line 275, in extend
new_values = [self._type_checker.CheckValue(elem) for elem in elem_seq_iter]
File "/home/franco/tensorflow/lib/python2.7/site-packages/google/protobuf/internal/type_checkers.py", line 109, in CheckValue
raise TypeError(message)
TypeError: <tf.Tensor 'EncodeJpeg:0' shape=() dtype=string> has type <class 'tensorflow.python.framework.ops.Tensor'>, but expected one of: ((<type 'str'>,),)
我只发现了这个未解决的问题 https://github.com/tensorflow/models/issues/726
我的代码中可能还有其他错误
答案 0 :(得分:0)
我在此步骤<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="hidden" name="combos[0][pics][01]">
<input type="hidden" name="combos[0][pics][02]">
<input type="hidden" name="combos[1][pics][01]">
<input type="hidden" name="combos[1][pics][02]">
<input type="hidden" name="combos[2][pics][01]">
<input type="hidden" name="combos[2][pics][02]">
添加.eval()
它保持这样:
image_data = tf.image.encode_jpeg(image_decoded)
您的github链接不存在,所以我无法评估image_data = tf.image.encode_jpeg(image_decoded).eval()
是否遵循以下相同的模式,但是看起来像从参数中所做的那样。
dataset_utils.image_to_tfexample