コード例 #1
0
def test_get_model_names():
    """
    Check that the module loads the list of names and is non-empty.
    """

    names = Instafilter.get_models()
    assert isinstance(names, list)
    assert len(names) > 1
コード例 #2
0
from instafilter import Instafilter

st.set_option("deprecation.showfileUploaderEncoding", False)

st.beta_set_page_config(
    layout="wide",
    initial_sidebar_state="expanded",
)

url = "https://github.com/thoppe/instafilter"
st.markdown("# [Instafilter]({url}) demo")

model_name = st.sidebar.selectbox(
    "Choose a filter",
    sorted(Instafilter.get_models()),
    index=20,
)
model = Instafilter(model_name)

raw_image_bytes = st.file_uploader("Choose an image...")

if raw_image_bytes is not None:

    img0 = np.array(Image.open(raw_image_bytes))

    with st.spinner(text="Applying filter..."):
        # Apply the model, convert to BGR first and after
        img1 = model(img0[:, :, ::-1], is_RGB=False)[:, :, ::-1]

    st.image([img1, img0],
コード例 #3
0
import cv2
from pathlib import Path
from instafilter import Instafilter

scale_size = 0.741

f_source = "train_new_model/input/Normal.jpg"
save_dest = Path("examples")
save_dest.mkdir(exist_ok=True)

img0 = cv2.imread(f_source)

for name in Instafilter.get_models():

    f_save = save_dest / (name + ".jpg")
    model = Instafilter(name)

    img1 = model(f_source)
    img2 = cv2.resize(img1, None, fx=scale_size, fy=scale_size)

    print(f"Saving {name}, {img2.shape}")
    cv2.imwrite(str(f_save), img2)