- benchmark_results
- data
- images
- job_logs
- pytorch_ssim
- results
- training_results
- .gitignore
- _overview.md
- _readme.ipynb
- app_spec.yml
- BSD100_009.png
- coding_here.ipynb
- data_utils.py
- handler.py
- loss.py
- main.ipynb
- model.py
- out_srf_4_BSD100_009.png
- project_requirements.txt
- README.md
- test_benchmark.py
- test_image.py
- test_video.py
- train.py
- vgg16.pth
coding_here.ipynb @master — view markup · raw · history · blame
In [10]:
import torch
#import torchvision.models as models
from torchvision.models.vgg import vgg16
vgg = vgg16(pretrained=False)
vgg.load_state_dict(torch.load('vgg16.pth'))
print(vgg)
print('ok')
In [3]:
import argparse
import torch
import matplotlib.pyplot as plt # plt 用于显示图片
from PIL import Image
from torch.autograd import Variable
from torchvision.transforms import ToTensor, ToPILImage
from model import Generator
UPSCALE_FACTOR=4
IMAGE_NAME ='BSD100_009.png'
MODEL_NAME = 'netG_epoch_4_100.pth'
model = Generator(UPSCALE_FACTOR).eval()
model.load_state_dict(torch.load('results/epochs/' + MODEL_NAME, map_location=lambda storage, loc: storage))
image = Image.open(IMAGE_NAME)
image = Variable(ToTensor()(image), volatile=True).unsqueeze(0)
out = model(image)
out_img = ToPILImage()(out[0].data.cpu())
plt.imshow(out_img)
plt.axis('off') # 不显示坐标轴
plt.show()
out_img.save('out_srf_' + str(UPSCALE_FACTOR) + '_' + IMAGE_NAME)
In [5]:
import os
import sys
import time
import re
import base64
from io import BytesIO
from PIL import Image
def image_to_base64(img):
global scale
buffered = BytesIO()
imgSize = img.size
if scale > 1:
resize_img = img.resize((int(imgSize[0]*scale), int(imgSize[1]*scale)))
else:
resize_img = img
resize_img.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue())
return img_str.decode("utf-8")
In [14]:
import base64
from io import BytesIO
# pip3 install pillow
from PIL import Image
# 若img.save()报错 cannot write mode RGBA as JPEG
# 则img = Image.open(image_path).convert('RGB')
def image_to_base64(image_path):
img = Image.open(image_path)
output_buffer = BytesIO()
img.save(output_buffer, format='JPEG')
byte_data = output_buffer.getvalue()
base64_str = base64.b64encode(byte_data)
return base64_str
In [15]:
import re
import base64
from io import BytesIO
from PIL import Image
def base64_to_image(base64_str, image_path=None):
base64_data = re.sub('^data:image/.+;base64,', '', base64_str)
byte_data = base64.b64decode(base64_data)
image_data = BytesIO(byte_data)
img = Image.open(image_data)
if image_path:
img.save(image_path)
return img
In [17]:
import matplotlib.pyplot as plt # plt 用于显示图片
img = 'BSD100_009.png'
img_str = image_to_base64(img)
#print(img_str)
out_img = base64_to_image(img_str,False)
plt.imshow(out_img)
plt.axis('off') # 不显示坐标轴
In [ ]:
5dd13c5024d57fa935c71de9?type=app
# Initialise Client object
client = Client(api_key='33799e1c5d6fa05fdd7dec3aa7aad868445d1c737edcf9c37fa89cb3b39cb2d9',
project_id='5bf7c0491afd94074fb77d3c', user_ID='harvien',
project_type='app', source_file_path='picmigration.py',
silent=True)
# Make run/train/predict command alias for further use
run = client.run
train = client.train
predict = client.predict
# Make controller alias for further use
controller = client.controller