<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def image_consumer(socket, hdf5_file, num_expected, shuffle_seed=None, offset=0):
 """Fill an HDF5 file with incoming images from a socket. Parameters socket : :class:`zmq.Socket` PULL socket on which to receive images. hdf5_file : :class:`h5py.File` instance HDF5 file handle to which to write. Assumes `features`, `targets` and `filenames` already exist and have first dimension larger than `sum(images_per_class)`. num_expected : int The number of items we expect to be sent over the socket. shuffle_seed : int or sequence, optional Seed for a NumPy random number generator that permutes the images on disk. offset : int, optional The offset in the HDF5 datasets at which to start writing received examples. Defaults to 0. """

    with progress_bar('images', maxval=num_expected) as pb:
        if shuffle_seed is None:
            index_gen = iter(xrange(num_expected))
        else:
            rng = numpy.random.RandomState(shuffle_seed)
            index_gen = iter(rng.permutation(num_expected))
        for i, num in enumerate(index_gen):
            image_filename, class_index = socket.recv_pyobj(zmq.SNDMORE)
            image_data = numpy.fromstring(socket.recv(), dtype='uint8')
            _write_to_hdf5(hdf5_file, num + offset, image_filename,
                           image_data, class_index)
            pb.update(i + 1)