Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make examples work with Metal Performance Shaders #22

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion main_test_fbcnn_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ def main():
logger = logging.getLogger(logger_name)
logger.info('--------------- quality factor: {:d} ---------------'.format(quality_factor))

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
border = 0
if torch.cuda.is_available():
device = torch.device('cuda')
elif torch.backends.mps.is_available():
device = torch.device('mps')
else:
device = torch.device('cpu')


# ----------------------------------------
Expand Down
16 changes: 13 additions & 3 deletions main_test_fbcnn_color_real.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,13 @@ def main():
utils_logger.logger_info(logger_name, log_path=os.path.join(E_path, logger_name+'.log'))
logger = logging.getLogger(logger_name)

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
border = 0
if torch.cuda.is_available():
device = torch.device('cuda')
elif torch.backends.mps.is_available():
device = torch.device('mps')
else:
device = torch.device('cpu')


# ----------------------------------------
Expand Down Expand Up @@ -83,7 +88,7 @@ def main():

#img_E,QF = model(img_L, torch.tensor([[0.6]]))
img_E,QF = model(img_L)
QF = 1- QF
QF = 1 - QF
img_E = util.tensor2single(img_E)
img_E = util.single2uint(img_E)
logger.info('predicted quality factor: {:d}'.format(round(float(QF*100))))
Expand All @@ -93,7 +98,12 @@ def main():
for QF_set in QF_control:
logger.info('Flexible control by QF = {:d}'.format(QF_set))
# from IPython import embed; embed()
qf_input = torch.tensor([[1-QF_set/100]]).cuda() if device == torch.device('cuda') else torch.tensor([[1-QF_set/100]])
if device == torch.device('cuda'):
qf_input = torch.tensor([[1-QF_set/100]]).cuda()
elif device == torch.device('mps'):
qf_input = torch.tensor([[1-QF_set/100]]).to('mps')
else:
qf_input = torch.tensor([[1-QF_set/100]])
img_E,QF = model(img_L, qf_input)
QF = 1- QF
img_E = util.tensor2single(img_E)
Expand Down
7 changes: 6 additions & 1 deletion main_test_fbcnn_gray.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,13 @@ def main():
logger = logging.getLogger(logger_name)
logger.info('--------------- quality factor: {:d} ---------------'.format(quality_factor))

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
border = 0
if torch.cuda.is_available():
device = torch.device('cuda')
elif torch.backends.mps.is_available():
device = torch.device('mps')
else:
device = torch.device('cpu')


# ----------------------------------------
Expand Down
7 changes: 6 additions & 1 deletion main_test_fbcnn_gray_doublejpeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ def main():
logger = logging.getLogger(logger_name)
logger.info('--------------- QF1={:d}, QF2={:d} ---------------'.format(qf1,qf2))

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
border = 0
if torch.cuda.is_available():
device = torch.device('cuda')
elif torch.backends.mps.is_available():
device = torch.device('mps')
else:
device = torch.device('cpu')


# ----------------------------------------
Expand Down