Implementation vs real world example
engahmed1190 opened this issue · 11 comments
Hello,
I would like to know the importance of having annotation images in the testing of the model , why we don't provide RBG images only
Basically this is the implementation
valid_images, valid_annotations = validation_dataset_reader.get_consecutive_batch(FLAGS.batch_size)
pred = sess.run(pred_annotation, feed_dict={image: valid_images, annotation: valid_annotations,
keep_probability: 1.0})
why don't we only do that
pred = sess.run(pred_annotation, feed_dict={image: valid_images, keep_probability: 1.0})
@txzhao can you help on this please
Hi,
Sorry for the late reply. I'm kind of occupied by some other projects and don't have much time to check the code. From what I've seen so far, I think you are right. We could simplify this line of code. I must have been too lazy or hurry to think about it clearly when I coded this part. But I think it won't affect the testing results.
Hello Tianxiao
i have tried to load the model using this code
from __future__ import print_function
import tensorflow as tf
import numpy as np
import inception_v3_fcn
IMAGE_SIZE = 224
NUM_OF_CLASSESS = 22
def load_image(filename):
with open(filename) as f:
return np.array(f.read())|
sess = tf.Session()
print("Setting up Saver...")
saver = tf.train.import_meta_graph('./logs/allmodel.ckpt-100000.meta')
print("meta graph loaded")
saver.restore(sess,tf.train.latest_checkpoint('./logs'))
all_vars = tf.get_collection('vars')
'''
for v in tf.global_variables():
print(v.name)
'''
image = tf.placeholder(tf.float32, shape=[None, IMAGE_SIZE, IMAGE_SIZE, 3], name="input_image")
tf.summary.image("input_image", image, max_outputs=2)
pred_annotation, logits, end_points = inception_v3_fcn.inception_v3_fcn(image, num_classes=NUM_OF_CLASSESS, dropout_keep_prob=1.0)
tf.summary.image("pred_annotation", tf.cast(pred_annotation, tf.uint8), max_outputs=2)
pred = sess.run(pred_annotation, feed_dict={image: load_image('actor.jpg').flatten()})
i have get an error related to
Traceback (most recent call last):
File "loading_model.py", line 42, in <module>
pred = sess.run(pred_annotation, feed_dict={image: load_image('actor.jpg').flatten()})
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 895, in run
run_metadata_ptr)
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1093, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
File "/usr/local/lib/python2.7/dist-packages/numpy/core/numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: ����
i think it related to the image feed , actually i need to understand this part to feed the image with real data , can you please advise how i can achieve that
Thanks in advance
@txzhao
Hi,
I don't remember I did the flatten() operation to the input image. You can try get rid of that, and if still errors show up, I would suggest checking the code inside BatchDatsetReader.py. Be careful about the shape of input images.
@txzhao
Hello ,
i have found that you use
image = misc.imread("actor.jpg")
temp_resize_image = misc.imresize(image,[224, 224], interp='nearest')
resize_image = temp_resize_image.reshape([-1, 224, 224, 3])
but still something missing , that is the error
Traceback (most recent call last):
File "inception_FCN.py", line 283, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "inception_FCN.py", line 281, in main
pred = sess.run(pred_annotation, feed_dict={image:hash(tuple(resize_image))})
TypeError: unhashable type: 'numpy.ndarray'
sorry for the late reply. I don't quite understand why you want to hash your input image. Could you try getting rid of hash(tuple(...)) part?
Btw, as for the shape of image, it should have following form: [number_of_images, width_of_image, height_of_image, number_of_channels].
@txzhao
i hope you are still available , i manged to find out the issue . name image is used somewhere else
i want to save the predicted image correctly
i am using that
pred = np.squeeze(pred, axis=3)
misc.imsave(pred,"pred.png" )
i got this error
Traceback (most recent call last):
File "inception_FCN.py", line 287, in <module>
tf.app.run()
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 48, in run
_sys.exit(main(_sys.argv[:1] + flags_passthrough))
File "inception_FCN.py", line 284, in main
misc.imsave("pred.png", pred)
File "/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.py", line 197, in imsave
im = toimage(arr, channel_axis=2)
File "/usr/local/lib/python2.7/dist-packages/scipy/misc/pilutil.py", line 289, in toimage
raise ValueError("'arr' does not have a suitable array shape for "
ValueError: 'arr' does not have a suitable array shape for any mode.
Hi, yes I'm available. I checked this scipy.misc.imsave function and it seems that it could only handle specific image matrices (with shape HxW, HxWx3, HxWx4). Please check if pred has the right shape, and an alternative is using matplotlib.pyplot.savefig to save your result. I used it in colorize.py for your information.
(1, 224, 224) is the prediction shape . think its ok
shouldn't the shape be (224, 224) or (224, 224, 3) instead of (1, 224, 224)?
https://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imsave.html
this should work. don't forget to denote cmap as cmap = plt.cm.jet
.