日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

TF之p2p:基于TF利用p2p模型部分代码实现提高图像的分辨率

發(fā)布時(shí)間:2025/3/21 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 TF之p2p:基于TF利用p2p模型部分代码实现提高图像的分辨率 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

TF之p2p:基于TF利用p2p模型部分代碼實(shí)現(xiàn)提高圖像的分辨率

?

?

?

目錄

一、tfimage.py文件功能解釋

二、process.py添加一個(gè)新操作


?

?

?

一、tfimage.py文件功能解釋

1、此處的create_op就調(diào)用了tf.get_default_session().run()方法,可以將Tensor 操作的函數(shù)轉(zhuǎn)變?yōu)閷?duì)Numpy 數(shù)組操作的函數(shù),轉(zhuǎn)換后的函數(shù)輸出為Numpy的數(shù)組,而不是Tensor。例如,下面的decode_jpeg和decode_png。

def create_op(func, **placeholders):op = func(**placeholders)def f(**kwargs):feed_dict = {}for argname, argvalue in kwargs.items():placeholder = placeholders[argname]feed_dict[placeholder] = argvaluereturn tf.get_default_session().run(op, feed_dict=feed_dict)return fdecode_jpeg = create_op(func=tf.image.decode_jpeg,contents=tf.placeholder(tf.string), )decode_png = create_op(func=tf.image.decode_png,contents=tf.placeholder(tf.string), )

2、tfimage.py里使用decode_jpeg和deco de_png定義了一個(gè)load函數(shù)。load函數(shù)的輸入是一個(gè)圖片文件路徑,返回的是numpy. ndarray 形式的圖像數(shù)據(jù)。

def load(path):with open(path, "rb") as f:contents = f.read()_, ext = os.path.splitext(path.lower())if ext == ".jpg":image = decode_jpeg(contents=contents)elif ext == ".png":image = decode_png(contents=contents)else:raise Exception("invalid image suffix")return to_float32(image=image)

3、還利用create_op函數(shù)定義了若干函數(shù)

rgb_to_grayscale = create_op(func=tf.image.rgb_to_grayscale,images=tf.placeholder(tf.float32), )……crop = create_op(func=tf.image.crop_to_bounding_box,image=tf.placeholder(tf.float32),offset_height=tf.placeholder(tf.int32, []),offset_width=tf.placeholder(tf.int32, []),target_height=tf.placeholder(tf.int32, []),target_width=tf.placeholder(tf.int32, []), )pad = create_op(func=tf.image.pad_to_bounding_box,image=tf.placeholder(tf.float32),offset_height=tf.placeholder(tf.int32, []),offset_width=tf.placeholder(tf.int32, []),target_height=tf.placeholder(tf.int32, []),target_width=tf.placeholder(tf.int32, []), )

?

二、process.py添加一個(gè)新操作

1、process.py 的主處理函數(shù)process 使用了上述load 函數(shù)讀入圖片,接著做了一些處理后保存。

def process(src_path, dst_path):src = im.load(src_path)if a.operation == "grayscale":dst = grayscale(src)elif a.operation == "resize":dst = resize(src)elif a.operation == "blank":dst = blank(src)elif a.operation == "combine":dst = combine(src, src_path)elif a.operation == "edges":dst = edges(src)elif a.operation == "blur":dst = blur(src)else:raise Exception("invalid operation")im.save(dst, dst_path)

2、添加新的函數(shù)

?

?

?

?

?

?

?

?

總結(jié)

以上是生活随笔為你收集整理的TF之p2p:基于TF利用p2p模型部分代码实现提高图像的分辨率的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。