示例#1
0
def create_reactive_image_grid(n_row, n_col, image_list, image_data,
                               image_path):
    """
    Get an HTML element corresponding to the responsive image grid.

    Args:
        n_rows = int, current number of rows in the grid (Input: indicates resizing)
        n_cols = int, current number of columns in the grid (Input: indicates resizing)
        image_list = list, containing a list of file paths where the valid images for the chosen directory are stored
        image_data = dict, with keys 'position' (for visible grid locations) and 'keep' (whether to keep / remove the image) (State)
                     Note: each keys contains a list, of lists of ints, a sequence of data about each completed image group
        image_path = list, of 1 str, the filepath where the images in image-container were loaded from

    Returns: html.Div element (containing the grid of images) that can update the responsive-image-grid element
    """

    image_path = image_path[0]
    # If it doesn't already exist, add an entry (dict) for this image path into the data dictionary
    if image_path not in image_data:
        image_data[image_path] = {'position': [], 'keep': [], 'filename': []}

    # Reduce the image_list by removing the masked images (so they can no longer appear in the image grid / image zoom)
    flat_mask = utils.create_flat_mask(image_data[image_path]['position'],
                                       len(image_list))
    image_list = [
        img_src for i, img_src in enumerate(image_list) if not flat_mask[i]
    ]

    return utils.create_image_grid(n_row, n_col, image_list)
示例#2
0
文件: models.py 项目: nhandam/p3_wgan
    def _samples_h(self,
                   filepath,
                   x_batches,
                   num_samples=100,
                   tile_shape=(10, 10)):
        '''
        Strategically move data by Mover
        '''
        if not os.path.exists(os.path.dirname(filepath)):
            os.makedirs(os.path.dirname(filepath))

        num = ((num_samples - 1) // self.batch_size + 1) * self.batch_size
        x = np.zeros(
            [num, self.img_size[0], self.img_size[1], self.img_size[2]],
            dtype=np.float32)
        batches = make_batches(num, self.batch_size)
        for batch_idx, (batch_start, batch_end) in enumerate(batches):
            x_batch = x_batches[batch_start:batch_end]
            x[batch_start:batch_end] = self.tf_session.run(
                self.h, feed_dict={self.x: x_batch})
        idx = np.random.permutation(num)[:num_samples]
        x = (x[idx] + 1.0) / 2.0
        imgs = create_image_grid(x,
                                 img_size=self.img_size,
                                 tile_shape=tile_shape)
        spm.imsave(filepath, imgs)
示例#3
0
    def _samples(self, filepath, tile_shape=(10, 10)):
        if not os.path.exists(os.path.dirname(filepath)):
            os.makedirs(os.path.dirname(filepath))

        num_samples = tile_shape[0] * tile_shape[1]
        x = self._generate(num_samples)
        imgs = create_image_grid(x, img_size=self.img_size, tile_shape=tile_shape)
        import scipy.misc
        scipy.misc.imsave(filepath, imgs)
示例#4
0
文件: models.py 项目: nhandam/p3_wgan
    def _samples(self, filepath, num_samples=100, tile_shape=(10, 10)):
        '''
        Generate samples by Generator
        '''
        if not os.path.exists(os.path.dirname(filepath)):
            os.makedirs(os.path.dirname(filepath))

        x = self._generate(num_samples)
        imgs = create_image_grid(x,
                                 img_size=self.img_size,
                                 tile_shape=tile_shape)
        spm.imsave(filepath, imgs)
示例#5
0
    def _samples_by_gen(self, filepath):
        if not os.path.exists(os.path.dirname(filepath)):
            os.makedirs(os.path.dirname(filepath))

        num_samples = self.num_gens * 10
        tile_shape = (self.num_gens, 10)

        sess = self.tf_session
        img_per_gen = num_samples // self.num_gens
        x = np.zeros([num_samples, self.img_size[0], self.img_size[1], self.img_size[2]],
                     dtype=np.float32)
        for i in range(0, img_per_gen, self.g_batch_size):
            z_batch = self.z_prior.sample([self.g_batch_size * self.num_gens, self.num_z]).astype(np.float32)
            samples = sess.run(self.sampler, feed_dict={self.z: z_batch})

            for gen in range(self.num_gens):
                x[gen * img_per_gen + i:gen * img_per_gen + min(i + self.g_batch_size, img_per_gen)] = \
                    samples[
                    gen * self.g_batch_size:gen * self.g_batch_size + min(self.g_batch_size, img_per_gen)]

        x = (x + 1.0) / 2.0
        imgs = create_image_grid(x, img_size=self.img_size, tile_shape=tile_shape)
        import scipy.misc
        scipy.misc.imsave(filepath, imgs)
示例#6
0
 def generate_grid(self, truncation_psi=0.7):
     seeds = np.random.randint((2**32 - 1), size=9)
     return create_image_grid(
         self.generate_images(self.generate_zs_from_seeds(seeds),
                              truncation_psi), 0.7, 3)
示例#7
0
         html.Button(id='delete-button', children='Delete'),
     ],
              style={
                  'display': 'none',
                  'height': 'auto'
              }),
 ],
          style={'height': '17vh'}),
 html.Div([
     html.Table([
         html.Tr([
             html.Td(id='responsive-image-grid',
                     children=utils.create_image_grid(
                         n_row=4,
                         n_col=4,
                         rows_max=ROWS_MAX,
                         cols_max=COLS_MAX,
                         image_list=config.IMAGE_SRCS,
                         empty_img_path=config.EMPTY_IMG_PATH),
                     style={
                         'width': '50vw',
                         'height': 'auto',
                         'border-style': 'solid',
                     }),
             html.Td([
                 html.Div(id='zoomed-image',
                          children=html.Img(src=config.IMAGE_SRCS[0],
                                            style=config.IMG_STYLE_ZOOM),
                          style={
                              'width': '70%',
                              'display': 'block',
示例#8
0
              style={'display': 'none'}),
     html.Div([
         html.Button(id='keep-button', children='Keep'),
         html.Button(id='delete-button', children='Delete'),
     ],
              style={
                  'display': 'none',
                  'height': 'auto'
              }),
 ],
          style={'height': '17vh'}),
 html.Div([
     html.Table([
         html.Tr([
             html.Td(id='responsive-image-grid',
                     children=utils.create_image_grid(
                         2, 2, config.IMAGE_SRCS),
                     style={
                         'width': '50vw',
                         'height': 'auto',
                         'border-style': 'solid',
                     }),
             html.Td([
                 html.Div(id='zoomed-image',
                          children=html.Img(src=config.IMAGE_SRCS[0],
                                            style=config.IMG_STYLE_ZOOM),
                          style={
                              'width': '70%',
                              'display': 'block',
                              'margin-left': 'auto',
                              'margin-right': 'auto'
                          })