├── models ├── 2x │ ├── EDSR_x2.pb │ ├── ESPCN_x2.pb │ ├── FSRCNN-small_x2.pb │ ├── FSRCNN_x2.pb │ └── LapSRN_x2.pb ├── 3x │ ├── EDSR_x3.pb │ ├── ESPCN_x3.pb │ ├── FSRCNN-small_x3.pb │ └── FSRCNN_x3.pb ├── 4x │ ├── EDSR_x4.pb │ ├── ESPCN_x4.pb │ ├── FSRCNN-small_x4.pb │ ├── FSRCNN_x4.pb │ └── LapSRN_x4.pb └── 8x │ └── LapSRN_x8.pb ├── packages.txt ├── readme.md ├── requirements.txt ├── result.jpeg ├── result.png └── streamlit_app.py /models/2x/EDSR_x2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/2x/EDSR_x2.pb -------------------------------------------------------------------------------- /models/2x/ESPCN_x2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/2x/ESPCN_x2.pb -------------------------------------------------------------------------------- /models/2x/FSRCNN-small_x2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/2x/FSRCNN-small_x2.pb -------------------------------------------------------------------------------- /models/2x/FSRCNN_x2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/2x/FSRCNN_x2.pb -------------------------------------------------------------------------------- /models/2x/LapSRN_x2.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/2x/LapSRN_x2.pb -------------------------------------------------------------------------------- /models/3x/EDSR_x3.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/3x/EDSR_x3.pb -------------------------------------------------------------------------------- /models/3x/ESPCN_x3.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/3x/ESPCN_x3.pb -------------------------------------------------------------------------------- /models/3x/FSRCNN-small_x3.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/3x/FSRCNN-small_x3.pb -------------------------------------------------------------------------------- /models/3x/FSRCNN_x3.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/3x/FSRCNN_x3.pb -------------------------------------------------------------------------------- /models/4x/EDSR_x4.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/4x/EDSR_x4.pb -------------------------------------------------------------------------------- /models/4x/ESPCN_x4.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/4x/ESPCN_x4.pb -------------------------------------------------------------------------------- /models/4x/FSRCNN-small_x4.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/4x/FSRCNN-small_x4.pb -------------------------------------------------------------------------------- /models/4x/FSRCNN_x4.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/4x/FSRCNN_x4.pb -------------------------------------------------------------------------------- /models/4x/LapSRN_x4.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/4x/LapSRN_x4.pb -------------------------------------------------------------------------------- /models/8x/LapSRN_x8.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/models/8x/LapSRN_x8.pb -------------------------------------------------------------------------------- /packages.txt: -------------------------------------------------------------------------------- 1 | python3-opencv -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Free Image Upscaler Using Deep Learning (AI) 📸 2 | 3 | A simple interface to upscale your images using deep learning (AI). 4 | In streamlit, there is a shortage in terms of CPU, to solve this issue use codes in GitHub on your own device or use another scale twice. 5 | 6 | 7 | # Demo 8 | https://mehrdad-dev-image-upscaler-deep-learning-streamlit-app-b16947.streamlit.app/ 9 | 10 | 11 | **Note:** If you see a error like "Oh, no - Error running app", it is because CPU shortage in streamlit. to solve this issue use codes in GitHub on your own device or use another scale twice. 12 | 13 | 14 | # Local machine 15 | 1. clone this repo 16 | 2. Install requirements.txt 17 | 3. and then run demo with this command: 18 | ``` 19 | python3 -m streamlit run streamlit_app.py 20 | ``` 21 | 22 | # Models 23 | 1. EDSR - [Paper](https://arxiv.org/pdf/1707.02921.pdf) 24 | 25 | 2. LapSRN - [Paper](https://arxiv.org/pdf/1710.01992.pdf) 26 | 27 | 3. FSRCNN - [Paper](https://arxiv.org/pdf/1608.00367.pdf) 28 | 29 | 4. ESPCN - [Paper](https://arxiv.org/pdf/1609.05158.pdf) 30 | 31 | 32 | # Licence 33 | MIT licence. 34 | 35 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | opencv-python 3 | opencv-contrib-python 4 | numpy 5 | matplotlib 6 | -------------------------------------------------------------------------------- /result.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/result.jpeg -------------------------------------------------------------------------------- /result.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mehrdad-dev/Image-Upscaler-Deep-Learning/5bed72c59a62095e1a32db4ddb4b4a5d9154a98a/result.png -------------------------------------------------------------------------------- /streamlit_app.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import matplotlib.pyplot as plt 3 | import streamlit as st 4 | import numpy as np 5 | from datetime import datetime 6 | 7 | ############################# start - variables ################################ 8 | sr = cv2.dnn_superres.DnnSuperResImpl_create() 9 | 10 | models_2x = ['EDSR_x2.pb', 'ESPCN_x2.pb', 11 | 'FSRCNN-small_x2.pb', 'FSRCNN_x2.pb', 'LapSRN_x2.pb'] 12 | models_3x = ['EDSR_x3.pb', 'ESPCN_x3.pb', 'FSRCNN-small_x3.pb', 'FSRCNN_x3.pb'] 13 | models_4x = ['EDSR_x4.pb', 'ESPCN_x4.pb', 14 | 'FSRCNN-small_x4.pb', 'FSRCNN_x4.pb', 'LapSRN_x4.pb'] 15 | models_8x = ['LapSRN_x8.pb'] 16 | 17 | BASE_PATH = 'models/' 18 | STREAMLIT = True # change it to False if you are running in your local machine. 19 | 20 | ############################# start - functions ################################ 21 | 22 | def upscale(model_path: str, model_name: str, scale: str, img, img_type: str): 23 | scale = int(scale.split('x')[0]) 24 | sr.readModel(model_path) 25 | sr.setModel(model_name, scale) 26 | result = sr.upsample(img) 27 | img_type = img_type.split('/')[1] 28 | save_path = f'result.{img_type}' 29 | plt.imsave(save_path, result[:, :, ::-1]) 30 | return result[:, :, ::-1], save_path 31 | 32 | 33 | def get_modelname(selected_model: str) -> str: 34 | if 'EDSR' in selected_model: 35 | return 'edsr' 36 | elif 'LapSRN' in selected_model: 37 | return 'lapsrn' 38 | elif 'ESPCN' in selected_model: 39 | return 'espcn' 40 | elif 'FSRCNN' in selected_model: 41 | return 'fsrcnn' 42 | elif 'LapSRN' in selected_model: 43 | return 'lapsrn' 44 | 45 | 46 | def model_selector(scale: str) -> str: 47 | model = '' 48 | if scale == '2x': 49 | model = st.selectbox( 50 | 'Which model do you want to use?', 51 | ('Not selected', models_2x[0], models_2x[1], models_2x[2], models_2x[3], 52 | models_2x[4])) 53 | elif scale == '3x': 54 | model = st.selectbox( 55 | 'Which model do you want to use?', 56 | ('Not selected', models_3x[0], models_3x[1], models_3x[2], models_3x[3])) 57 | elif scale == '4x': 58 | model = st.selectbox( 59 | 'Which model do you want to use?', 60 | ('Not selected', models_4x[0], models_4x[1], models_4x[2], models_4x[3], models_4x[4])) 61 | elif scale == '8x': 62 | model = st.selectbox( 63 | 'Which model do you want to use?', 64 | ('Not selected', models_8x[0])) 65 | else: 66 | return False, False 67 | 68 | model_name = get_modelname(model) 69 | return model, model_name 70 | 71 | 72 | ############################# start - Streamlit ################################ 73 | 74 | st.title('Free Image Upscaler Using Deep Learning 📸') 75 | st.markdown( 76 | 'By [Mehrdad Mohammadian](https://mehrdad-dev.github.io)', unsafe_allow_html=True) 77 | 78 | about = """ 79 | This demo provides a simple interface to upscale your images using deep learning (AI). 80 | In streamlit, there is a shortage in terms of CPU, to solve this issue use codes in 81 | GitHub on your own device or use another scale twice. 82 | 83 | 84 | **Note:** If you see a error like "Oh, no - Error running app", it is because CPU shortage in streamlit. 85 | """ 86 | st.markdown(about, unsafe_allow_html=True) 87 | 88 | scale = st.selectbox( 89 | 'Which scale do you want to apply to your image?', 90 | ('Not selected', '2x', '3x', '4x', '8x')) 91 | 92 | 93 | uploaded_file = None 94 | model, model_name = model_selector(scale) 95 | if model and model != 'Not selected': 96 | model_path = BASE_PATH + scale + '/' + model 97 | uploaded_file = st.file_uploader("Upload a jpg image", type=["jpg", "png"]) 98 | 99 | 100 | image = None 101 | if uploaded_file is not None: 102 | # file_details = {"Filename":uploaded_file.name,"FileType":uploaded_file.type,"FileSize":uploaded_file.size} 103 | file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8) 104 | image = cv2.imdecode(file_bytes, 1) 105 | st.image(image, channels="BGR", caption='Your uploaded image') 106 | 107 | if scale == '8x' and image.shape[0] <= 128 and STREAMLIT==True: 108 | st.error("Your image for the 8x scale is too big, because there is a shortage \ 109 | in terms of CPU, to solve this issue use GitHub codes on your own device or \ 110 | **plseae select another image or use another scale twice.**") 111 | elif scale == '4x' and image.shape[0] <= 200 and STREAMLIT==True: 112 | st.error("Your image for the 4x scale is too big, because there is a shortage \ 113 | in terms of CPU, to solve this issue use GitHub codes on your own device or \ 114 | **plseae select another image or use another scale twice.**") 115 | elif scale == '3x' and image.shape[0] <= 540 and STREAMLIT==True: 116 | st.error("Your image for the 3x scale is too big, because there is a shortage \ 117 | in terms of CPU, to solve this issue use GitHub codes on your own device or \ 118 | **plseae select another image or use another scale twice.**") 119 | elif scale == '2x' and image.shape[0] <= 550 and STREAMLIT==True: 120 | st.error("Your image for the 3x scale is too big, because there is a shortage \ 121 | in terms of CPU, to solve this issue use GitHub codes on your own device or \ 122 | **plseae select another image or use another scale twice.**") 123 | else: 124 | left_column, right_column = st.columns(2) 125 | pressed = left_column.button('Upscale!') 126 | 127 | if pressed: 128 | pressed = False 129 | st.info('Processing ...') 130 | result, save_path = upscale( 131 | model_path, model_name, scale, image, uploaded_file.type) 132 | st.success('Image is ready, you can download it now!') 133 | st.balloons() 134 | st.image(result, channels="RGB", caption='Your upscaled image') 135 | with open(save_path, 'rb') as f: 136 | st.download_button('Download the image', f, file_name=scale + 137 | '_' + str(datetime.now()) + '_' + save_path) 138 | --------------------------------------------------------------------------------