<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def predict(self, image_arr, featurize=False):
 """ Predict a set of images in batches. Parameters image_arr : NxHxWxC :obj:`numpy.ndarray` input set of images in a num_images x image height x image width x image channels array (must match parameters of network) featurize : bool whether or not to use the featurization layer or classification output layer Returns ------- :obj:`numpy.ndarray` num_images x feature_dim containing the output values for each input image """

        # setup prediction
        num_images = image_arr.shape[0]
        output_arr = None

        # predict by filling in image array in batches
        close_sess = False
        if not self._initialized and self._dynamic_load:
            self._load()
        with self._graph.as_default():
            if self._sess is None: 
                close_sess = True               
                self.open_session()

            i = 0
            while i < num_images:
                dim = min(self._batch_size, num_images-i)
                cur_ind = i
                end_ind = cur_ind + dim
                self._input_arr[:dim,:,:,:] = image_arr[cur_ind:end_ind,:,:,:] - self._mean
                if featurize:
                    output = self._sess.run(self._feature_tensor,
                                            feed_dict={self._input_node: self._input_arr})
                else:
                    output = self._sess.run(self._output_tensor,
                                            feed_dict={self._input_node: self._input_arr})
                if output_arr is None:
                    output_arr = output
                else:
                    output_arr = np.r_[output_arr, output]

                i = end_ind
            if close_sess:
                self.close_session()
        return output_arr[:num_images,...]