Reduced disk I/O
MODIFY
tika-parsers/src/main/resources/org/apache/tika/parser/recognition/tf/InceptionRestDockerfile
tika-parsers/src/main/resources/org/apache/tika/parser/recognition/tf/InceptionRestDockerfile
@@ -37,12 +37,10 @@ RUN \
wget https://raw.githubusercontent.com/KranthiGV/tika/TIKA-2306/tika-parsers/src/main/resources/org/apache/tika/parser/recognition/tf/inceptionapi.py -O /usr/bin/inceptionapi.py && \
chmod +x /usr/bin/inceptionapi.py
-
# clean up cache, so we can publish smaller image to hub
RUN apt-get clean
ENV PYTHONPATH="$PYTHONPATH:/models-c15fada28113eca32dc98d6e3bec4755d0d5b4c2/slim"
-ENV LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4"
-
+#ENV LD_PRELOAD="/usr/lib/libtcmalloc_minimal.so.4"
# expose API port, this is the default port
EXPOSE 8764

MODIFY
tika-parsers/src/main/resources/org/apache/tika/parser/recognition/tf/inceptionapi.py
tika-parsers/src/main/resources/org/apache/tika/parser/recognition/tf/inceptionapi.py
@@ -223,37 +223,37 @@ class Classifier(flask.Flask):
self.names = imagenet.create_readable_names_for_imagenet_labels()
self.image_size = inception.inception_v4.default_image_size
- def classify(self, image_string, topk):
- dest_directory = FLAGS.model_dir
-
- with tf.Graph().as_default():
- image = tf.image.decode_jpeg(image_string, channels=3)
+ self.image_str_placeholder = tf.placeholder(tf.string)
+ image = tf.image.decode_jpeg(self.image_str_placeholder, channels=3)
processed_image = inception_preprocessing.preprocess_image(
image, self.image_size, self.image_size, is_training=False)
processed_images = tf.expand_dims(processed_image, 0)
-
# Create the model, use the default arg scope to configure the
# batch norm parameters.
with slim.arg_scope(inception.inception_v4_arg_scope()):
logits, _ = inception.inception_v4(
processed_images, num_classes=1001, is_training=False)
- probabilities = tf.nn.softmax(logits)
+ self.probabilities = tf.nn.softmax(logits)
+ dest_directory = FLAGS.model_dir
init_fn = slim.assign_from_checkpoint_fn(
os.path.join(dest_directory, 'inception_v4.ckpt'),
slim.get_model_variables('InceptionV4'))
- with tf.Session() as sess:
- init_fn(sess)
- _, probabilities = sess.run([image, probabilities])
- probabilities = probabilities[0, 0:]
+ self.sess = tf.Session()
+ init_fn(self.sess)
+
+ def classify(self, image_string, topk):
+ eval_probabilities = self.sess.run(self.probabilities, feed_dict={
+ self.image_str_placeholder: image_string})
+ eval_probabilities = eval_probabilities[0, 0:]
sorted_inds = [i[0] for i in sorted(
- enumerate(-probabilities), key=lambda x:x[1])]
+ enumerate(-eval_probabilities), key=lambda x:x[1])]
res = []
for i in range(topk):
index = sorted_inds[i]
- score = float(probabilities[index])
+ score = float(eval_probabilities[index])
res.append((index, self.names[index], score))
return res

Reduced disk I/O