日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

深度学总结:Image Style Transfer pytorch方式实现,这个是非基于autoencoder和domain adversrial方式

發(fā)布時(shí)間:2024/9/15 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 深度学总结:Image Style Transfer pytorch方式实现,这个是非基于autoencoder和domain adversrial方式 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

文章目錄

  • 論文鏈接:
  • 主要思路:
  • pytorch實(shí)現(xiàn):
    • 計(jì)算content的Loss:
    • 計(jì)算style 的Loss:
    • 計(jì)算total的Loss:
    • 訓(xùn)練過程:

論文鏈接:

https://www.cv-foundation.org/openaccess/content_cvpr_2016/papers/Gatys_Image_Style_Transfer_CVPR_2016_paper.pdf
作者運(yùn)用了一個(gè)披著深度學(xué)習(xí)外表的傳統(tǒng)方法做這個(gè)問題,技術(shù)不提倡,思路、想法很天才。

主要思路:

1、想辦法分離style features和content features;
2、怎么得到content features,作者偷懶直接取vgg19里面conv4_2的features,當(dāng)作content features;
3、怎么得到style features,作者發(fā)揮天才的偷懶,認(rèn)為style就是features之間的相關(guān)度,作者直接取vgg19里面conv1_1,conv2_1,conv3_1,conv4_1,conv5_1這5層的feature map來算風(fēng)格相關(guān)度,作者又發(fā)現(xiàn)不同的layer對(duì)風(fēng)格有影響,前面的風(fēng)格細(xì)膩,后面的風(fēng)格粗獷,又給這5個(gè)層的loss誤差加了權(quán)重。
4、那么目標(biāo)是什么了?就是new_image和content_image的內(nèi)容接近,new_image和stytle_image的風(fēng)格接近,LtotalL_{total}Ltotal? = LcontentL_{content}Lcontent?+LstyleL_{style}Lstyle?,首先要像,其次才是風(fēng)格,所以LcontentL_{content}Lcontent?的比重要大。

pytorch實(shí)現(xiàn):

計(jì)算content的Loss:

前面提到了作者偷懶直接取vgg19里面conv4_2的features,當(dāng)作content features,那么只需要比較兩個(gè)feature map的差別就行了。

# the content losscontent_loss = torch.mean((target_features['conv4_2'] - content_features['conv4_2'])**2)

計(jì)算style 的Loss:

def gram_matrix(tensor):""" Calculate the Gram Matrix of a given tensor Gram Matrix: https://en.wikipedia.org/wiki/Gramian_matrix"""# get the batch_size, depth, height, and width of the Tensor_, d, h, w = tensor.size()# reshape so we're multiplying the features for each channeltensor = tensor.view(d, h * w)# calculate the gram matrixgram = torch.mm(tensor, tensor.t())return gram


# weights for each style layer # weighting earlier layers more will result in *larger* style artifacts # notice we are excluding `conv4_2` our content representation style_weights = {'conv1_1': 1.,'conv2_1': 0.75,'conv3_1': 0.2,'conv4_1': 0.2,'conv5_1': 0.2}# get style features only once before training style_features = get_features(style, vgg)# calculate the gram matrices for each layer of our style representation style_grams = {layer: gram_matrix(style_features[layer]) for layer in style_features}for layer in style_weights:# get the "target" style representation for the layertarget_feature = target_features[layer]target_gram = gram_matrix(target_feature)_, d, h, w = target_feature.shape# get the "style" style representationstyle_gram = style_grams[layer]# the style loss for one layer, weighted appropriatelylayer_style_loss = style_weights[layer] * torch.mean((target_gram - style_gram)**2)# add to the style lossstyle_loss += layer_style_loss / (d * h * w)

計(jì)算total的Loss:

content_weight = 1 # alpha style_weight = 1e6 # beta# calculate the *total* loss total_loss = content_weight * content_loss + style_weight * style_loss

訓(xùn)練過程:

有人可能問VGG參數(shù)固定住了,需要的參數(shù)是什么了,參數(shù)就是新圖啊?通過上述loss調(diào)整圖像的像素值,這個(gè)和我們一般了解到的有點(diǎn)不一樣。
新圖就是在原圖的基礎(chǔ)上慢慢變化,f復(fù)制原圖并設(shè)置新圖為trainable的:

# create a third "target" image and prep it for change # it is a good idea to start of with the target as a copy of our *content* image # then iteratively change its style target = content.clone().requires_grad_(True).to(device)

訓(xùn)練大概代碼如下:

# for displaying the target image, intermittently show_every = 400# iteration hyperparameters optimizer = optim.Adam([target], lr=0.003) steps = 2000 # decide how many iterations to update your image (5000)for ii in range(1, steps+1):# get the features from your target imagetarget_features = get_features(target, vgg)# the content losscontent_loss = torch.mean((target_features['conv4_2'] - content_features['conv4_2'])**2)# the style loss# initialize the style loss to 0style_loss = 0# then add to it for each layer's gram matrix lossfor layer in style_weights:# get the "target" style representation for the layertarget_feature = target_features[layer]target_gram = gram_matrix(target_feature)_, d, h, w = target_feature.shape# get the "style" style representationstyle_gram = style_grams[layer]# the style loss for one layer, weighted appropriatelylayer_style_loss = style_weights[layer] * torch.mean((target_gram - style_gram)**2)# add to the style lossstyle_loss += layer_style_loss / (d * h * w)# calculate the *total* losstotal_loss = content_weight * content_loss + style_weight * style_loss# update your target imageoptimizer.zero_grad()total_loss.backward()optimizer.step()

總結(jié)

以上是生活随笔為你收集整理的深度学总结:Image Style Transfer pytorch方式实现,这个是非基于autoencoder和domain adversrial方式的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 黑丝扣逼 | 国产精品专区在线观看 | 麻豆网页 | 污污网站免费在线观看 | 色呦呦中文字幕 | 99国产精品免费视频 | 日韩成人在线观看视频 | 色哟哟网站入口 | 我们2018在线观看免费版高清 | 中文字幕日韩欧美一区二区 | 国v精品久久久网 | 精品国产乱码久久久久久图片 | 不卡福利视频 | 毛片a| 四虎成人精品永久免费av九九 | 久久国产柳州莫菁门 | 国产免费看av | 另类色综合 | 91国内在线视频 | 草久在线 | 中文字幕免费在线视频 | 亚洲丝袜av | 91精品人妻一区二区三区果冻 | 超碰在线人人干 | 亚洲国产看片 | 在线观看免费中文字幕 | 豆花免费跳转入口官网 | av一级 | 久久艹综合 | 波多野吉衣一二三区乱码 | 欧美第十页 | 国产卡一卡二卡三无线乱码新区 | 草草久久久无码国产专区 | 国产美女精品一区二区三区 | 国产专区第一页 | 大尺度做爰呻吟舌吻网站 | 熟妇大屁股一区二区三区视频 | 夜色一区二区三区 | 少妇特黄一区二区三区 | 国产91丝袜在线播放 | 欧美毛片视频 | 我们的2018中文免费看 | 欧美毛片免费看 | 91精品国产aⅴ一区二区 | 亚洲精品第一页 | 欧美三级午夜理伦三级中视频 | 国产农村妇女精品久久久 | 精品久久香蕉国产线看观看亚洲 | 九九热视频这里只有精品 | 在线免费国产视频 | 91色啪| a级在线播放 | 欧美偷拍少妇精品一区 | 加勒比hezyo黑人专区 | 黄网站免费大全入口 | a毛片基地 | 青青草在线视频免费观看 | 美女扒开下面让男人捅 | 国产精品无码电影在线观看 | 男生和女生一起差差差很痛的视频 | 秋霞福利影院 | 在线观看99 | 一本色道久久综合精品婷婷 | 黄色小说在线免费观看 | 国产精品免费入口 | 亚洲人av在线 | 中文字幕第23页 | 日韩欧美国产一区二区在线观看 | 雷电将军和丘丘人繁衍后代视频 | 香蕉综合视频 | 9色视频在线观看 | 成人手机在线观看 | 美女免费黄视频 | 午夜理伦三级做爰电影 | 天天操天天干天天舔 | 天天婷婷 | 91免费视频播放 | 婷婷在线综合 | 狠狠干综合网 | 久久久久久久久久一级 | 亚洲中文字幕一区 | 国产精品久久久久久久久岛 | 9cao| 日本在线有码 | 亚洲欧美日韩动漫 | 又黄又爽又刺激的视频 | 视频三区在线 | 国产第4页| 久久精品国产久精国产 | 亚洲影院在线观看 | 日韩乱码人妻无码中文字幕 | 95视频在线 | 一级毛毛片 | 高清一区二区视频 | 国产69精品久久久久777 | 久久99久久99精品免视看婷婷 | 精品免费国产一区二区三区 | 欧美亚洲激情视频 | 日本美女毛茸茸 |