title: Tensorflow Keras multiple prediction model
body: <p>I'm trying to use a convolution neural network to predict multiple outputs from a single image. Right now, the images/associated values are in a tensorflow dataset in the form <code>img, value_1, value_2, value_3, value_4, value_5</code>, where all are Tensors. I've created a model using the following code:</p>
  
  <pre class="lang-py prettyprint-override"><code>model = models.Sequential()
  model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH, 3)))
  model.add(layers.MaxPooling2D((2, 2)))
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  model.add(layers.MaxPooling2D((2, 2)))
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  model.add(layers.Flatten())
  model.add(layers.Dense(64, activation='relu'))
  model.add(layers.Dense(5, activation='softmax'))
  model.compile(optimizer='adam',
                loss='sparse_categorical_crossentropy',
                metrics=['mae'])
  
  model.fit(train_ds, epochs=2, steps_per_epoch=STEPS_PER_EPOCH)
  </code></pre>
  
  <p>When I run this, I get the following error: <code>ValueError: too many values to unpack (expected 3)</code></p>
  
  <p>I've also tried creating the dataset to be of the form <code>img, (value_1, value_2, value_3, value_4, value_5)</code>, but that gives the following error: <code>ValueError: Error when checking model target: the list of Numpy arrays that you are passing to your model is not the size the model expected. Expected to see 1 array(s), but instead got the following list of 5 arrays: [&lt;tf.Tensor 'ExpandDims:0' shape=(None, 1) dtype=string&gt;, &lt;tf.Tensor 'ExpandDims_1:0' shape=(None, 1) dtype=string&gt;, &lt;tf.Tensor 'ExpandDims_2:0' shape=(None, 1) dtype=string&gt;, &lt;tf.Tensor 'ExpandDims_3...</code></p>
  
  <p>How can I fix my model to be able to predict multiple values?</p>
  
  <p>EDIT:
  Full code is here:</p>
  
  <pre class="lang-py prettyprint-override"><code>from __future__ import absolute_import, division, print_function, unicode_literals
  import numpy as np
  import cv2
  import imutils
  from scipy import misc
  import random
  import glob
  import pathlib
  
  import os
  import matplotlib.pyplot as plt
  #os.environ["CUDA_VISIBLE_DEVICES"]="-1"  
  
  import tensorflow as tf
  from tensorflow.keras import datasets, layers, models
  
  import tensorflow.keras.backend as K
  
  AUTOTUNE = tf.data.experimental.AUTOTUNE
  
  def decode_img(img):
    img = tf.image.decode_png(img, channels=3)
    img = tf.image.convert_image_dtype(img, tf.float32)
    return tf.image.resize(img, [IMG_WIDTH, IMG_HEIGHT])
  
  def process_path(file_path):
      parts = tf.strings.split(file_path, '_')
      file = tf.io.read_file(file_path)
      img = decode_img(file)
      return img, (tf.strings.split(parts[0], '/')[5], parts[1], parts[2], parts[3], tf.strings.split(parts[4], '.p')[0])
  
  
  #for f in labeled_ds.take(1):
      #print(f[1])
      #print(tf.strings.split(f[1][4], '.p')[0])
      #print(tf.strings.split(f[1][0], '/')[5])
  
  def prepare_for_training(ds, cache=False, shuffle_buffer_size=1000):
    if cache:
      if isinstance(cache, str):
        ds = ds.cache(cache)
      else:
        ds = ds.cache()
  
    ds = ds.shuffle(buffer_size=shuffle_buffer_size)
    ds = ds.repeat()
    ds = ds.batch(BATCH_SIZE)
    ds = ds.prefetch(buffer_size=AUTOTUNE)
  
    return ds
  
  data_dir = pathlib.Path("/home/connor/capstone/train3/")
  image_count = len(list(data_dir.glob('*.png')))
  print(image_count)
  image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
  BATCH_SIZE = 4
  IMG_HEIGHT = 1024
  IMG_WIDTH = 1024
  STEPS_PER_EPOCH = np.ceil(image_count/BATCH_SIZE)
  
  list_ds = tf.data.Dataset.list_files("/home/connor/capstone/train3/*.png")
  
  labeled_ds = list_ds.map(process_path, num_parallel_calls=AUTOTUNE)
  train_ds = prepare_for_training(labeled_ds)
  
  model = models.Sequential()
  model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(IMG_HEIGHT, IMG_WIDTH, 3)))
  model.add(layers.MaxPooling2D((2, 2)))
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  model.add(layers.MaxPooling2D((2, 2)))
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  model.add(layers.Flatten())
  model.add(layers.Dense(64, activation='relu'))
  model.add(layers.Dense(5, activation='softmax'))
  model.compile(optimizer='adam',
                loss='sparse_categorical_crossentropy',
                metrics=['mae'])
  
  model.fit(train_ds, epochs=2, steps_per_epoch=STEPS_PER_EPOCH) 
  </code></pre>