Ejemplo n.º 1
0
    def on_epoch_end(self, pbar, epoch, last_metrics, *args, **kwargs):
        "Put the various losses in the recorder and show a sample image."
        """
        data = self.learn.data
        inputBPre = torch.unbind(self.last_input[1], dim=0)
        aToA = im.Image(self.last_gen[0]/2+0.5)
        bToB = im.Image(self.last_gen[1]/2+0.5)
        aToB = im.Image(self.last_gen[2]/2+0.5)
        bToA = im.Image(self.last_gen[3]/2+0.5)
        self.imgs.append(aToA)
        self.imgs.append(aToB)
        self.imgs.append(bToB)
        self.imgs.append(bToA)
        self.titles.append(f'Epoch {epoch}-A to A')
        self.titles.append(f'Epoch {epoch}-A to B')
        self.titles.append(f'Epoch {epoch}-B to B')
        self.titles.append(f'Epoch {epoch}-B to A')
        pbar.show_imgs(self.imgs, self.titles)
        """
        # pdb.set_trace()
        orig, orig2 = self.last_input
        orig.detach()
        orig2.detach()
        orig_cont, orig_hooks = self.content_encoder(orig)
        orig_style = self.style_encoder(orig)

        orig2_cont, orig2_hooks = self.content_encoder(orig2)
        orig2_style = self.style_encoder(orig2)

        one2two = self.decoder(orig_cont, orig2_style, orig_hooks).detach()
        two2one = self.decoder(orig2_cont, orig_style, orig2_hooks).detach()

        o1 = im.Image(orig[0] / 2 + 0.5)
        o2 = im.Image(orig2[0] / 2 + 0.5)
        o2t = im.Image(one2two[0] / 2 + 0.5)
        t2o = im.Image(two2one[0] / 2 + 0.5)
        self.imgs.append(o1)
        self.imgs.append(o2)
        self.imgs.append(o2t)
        self.imgs.append(t2o)

        self.titles.append(f'Epoch {epoch}-o1')
        self.titles.append(f'Epoch {epoch}-o2')
        self.titles.append(f'Epoch {epoch}-onetrans')
        self.titles.append(f'Epoch {epoch}-twotrans')

        pbar.show_imgs(self.imgs, self.titles)

        return
Ejemplo n.º 2
0
def load_image(image_file):
    pil_img = PIL.Image.open(image_file)

    img = pil_img.convert('RGB')
    img = image.pil2tensor(img, np.float32).div_(255)
    img = image.Image(img)
    return img, np.asarray(pil_img)
Ejemplo n.º 3
0
 def process_image(self, img_stream):
     img = (PIL.Image.open(img_stream)).convert(mode='RGB')
     img = self.transforms(img)
     img = image_func.Image(img)
     img = img.set_sample()
     return img
Ejemplo n.º 4
0
 def to_one(self):
     tensor = 0.5 + torch.cat(self.data, 2) / 2
     return im.Image(tensor)
Ejemplo n.º 5
0
	st.write('## This is ',str(pred_class).capitalize(),' with probablity of ',pred_prob,'%')



options = st.radio('',('Select Image','Enter Image URL','Upload an image'))
#Select image
if options =='Select Image':
	static = os.listdir('static')
	test_image = st.selectbox('Please select a image:',static)
	file_path = 'static/' + test_image
	pil_img =Image.open(file_path)

	#read the image
	img = pil_img.convert('RGB')
	img = image.pil2tensor(img,np.float32).div_(224)
	img = image.Image(img)

    #display image
	display_img = mpimg.imread(file_path)
	st.image(pil_img,use_column_width=True)

	predict(img)




#Image URL
if options == 'Enter Image URL':
	url = st.text_input('Enter Image URL')

	if url != '':