Exemplo n.º 1
0
 def prepare_for_vgg16(self, img, config, channel_mean=None):
     prep_img = img.astype(np.float32)
     thresh = config.thresh
     util.logTrace('prepare_for_vgg16', 'thresh=%.1f' % thresh)
     util.replaceWithLogIfAbove(prep_img, thresh)
     prep_resized = imresize(prep_img,(224,224), interp='lanczos', mode='F')
     
     if channel_mean: prep_resized -= channel_mean
     rgb = util.replicate(prep_resized, numChannels=3, dtype=np.float32)
     return rgb
Exemplo n.º 2
0
 def plot_vgg16_img_prep(self, plot, pipeline, plotFigH, config, step2h5list):
     prep_config = pipeline.get_config(name='prepare_for_vgg16')
     channel_mean = self.get_datastat('channel_mean', step2h5list)
     util.logTrace("plot_vgg16_img_prep", "channel_mean is %.2f" % channel_mean)
     basic_iter = self.dset.train_iter(batchsize=1, epochs=1)
     plt = pipeline.plt
     plt.figure(plotFigH)
     plt.clf()
     for X,Y,meta,batchinfo in basic_iter:
         img_batch = X[0]
         img = img_batch[0,:,:]
         prep_img = self.prepare_for_vgg16(img, config=prep_config, channel_mean=channel_mean)
         psplot.compareImages(plt, plotFigH, ("orig",img), ("vgg16 prep",prep_img))
         if pipeline.stop_plots(): break
Exemplo n.º 3
0
 def prepare_for_vgg16(self, img, config, channel_mean=None):
     prep_img = img.astype(np.float32)
     thresh = config.thresh
     util.logTrace('prepare_for_vgg16', 'thresh=%.1f' % thresh)
     util.inplace_log_thresh(prep_img, thresh)
     prep_resized = imresize(prep_img, (224, 224),
                             interp='lanczos',
                             mode='F')
     # TODO: add this, probably why thresholds above 200 failed
     # scale the image so that the log thresh is 200, since vgg16 expected[0,256] for images
     #        prep_resized *= 200.0/thresh
     if channel_mean: prep_resized -= channel_mean
     rgb = util.replicate(prep_resized, num_channels=3, dtype=np.float32)
     return rgb
Exemplo n.º 4
0
 def trace(self, msg, checkcache=True):        
     util.logTrace(hdr=self.hdr, msg=msg, checkcache=checkcache, flag=self.doTrace)