用python能干什么有意思的事 用python可以做哪些有趣的事

python\u53ef\u4ee5\u505a\u54ea\u4e9b\u6709\u8da3\u7684\u4e8b

\u753b\u753b

\u5728\u672c\u5730\u7528keras\u642d\u5efa\u98ce\u683c\u8f6c\u79fb\u5e73\u53f0
1.\u76f8\u5173\u4f9d\u8d56\u5e93\u7684\u5b89\u88c5
# \u547d\u4ee4\u884c\u5b89\u88c5keras\u3001h5py\u3001tensorflowpip3 install keraspip3 install h5pypip3 install tensorflow
\u5982\u679ctensorflowan\u547d\u4ee4\u884c\u5b89\u88c5\u5931\u8d25\uff0c\u53ef\u4ee5\u5728\u8fd9\u91cc\u4e0b\u8f7dwhl\u5305Python Extension Packages for Windows\uff08\u8fdb\u5165\u7f51\u5740\u540ectrl+F\u8f93\u5165tensorflow\u53ef\u4ee5\u5feb\u901f\u641c\u7d22\uff09
2.\u914d\u7f6e\u8fd0\u884c\u73af\u5883
\u4e0b\u8f7dVGG16\u6a21\u578bz \u653e\u5165\u5982\u4e0b\u76ee\u5f55\u5f53\u4e2d

3.\u4ee3\u7801\u7f16\u5199
from __future__ import print_functionfrom keras.preprocessing.image import load_img, img_to_arrayfrom scipy.misc import imsaveimport numpy as npfrom scipy.optimize import fmin_l_bfgs_bimport timeimport argparsefrom keras.applications import vgg16from keras import backend as Kparser = argparse.ArgumentParser(description='Neural style transfer with Keras.')parser.add_argument('base_image_path', metavar='base', type=str,help='Path to the image to transform.')parser.add_argument('style_reference_image_path', metavar='ref', type=str,help='Path to the style reference image.')parser.add_argument('result_prefix', metavar='res_prefix', type=str,help='Prefix for the saved results.')parser.add_argument('--iter', type=int, default=10, required=False,help='Number of iterations to run.')parser.add_argument('--content_weight', type=float, default=0.025, required=False,help='Content weight.')parser.add_argument('--style_weight', type=float, default=1.0, required=False,help='Style weight.')parser.add_argument('--tv_weight', type=float, default=1.0, required=False,help='Total Variation weight.')args = parser.parse_args()base_image_path = args.base_image_pathstyle_reference_image_path = args.style_reference_image_pathresult_prefix = args.result_prefixiterations = args.iter# these are the weights of the different loss componentstotal_variation_weight = args.tv_weightstyle_weight = args.style_weightcontent_weight = args.content_weight# dimensions of the generated picture.width, height = load_img(base_image_path).sizeimg_nrows = 400img_ncols = int(width * img_nrows / height)# util function to open, resize and format pictures into appropriate tensorsdef preprocess_image(image_path):img = load_img(image_path, target_size=(img_nrows, img_ncols))img = img_to_array(img)img = np.expand_dims(img, axis=0)img = vgg16.preprocess_input(img)return img# util function to convert a tensor into a valid imagedef deprocess_image(x):if K.image_data_format() == 'channels_first':x = x.reshape((3, img_nrows, img_ncols))x = x.transpose((1, 2, 0))else:x = x.reshape((img_nrows, img_ncols, 3))# Remove zero-center by mean pixelx[:, :, 0] += 103.939x[:, :, 1] += 116.779x[:, :, 2] += 123.68# 'BGR'->'RGB'x = x[:, :, ::-1]x = np.clip(x, 0, 255).astype('uint8')return x# get tensor representations of our imagesbase_image = K.variable(preprocess_image(base_image_path))style_reference_image = K.variable(preprocess_image(style_reference_image_path))# this will contain our generated imageif K.image_data_format() == 'channels_first':combination_image = K.placeholder((1, 3, img_nrows, img_ncols))else:combination_image = K.placeholder((1, img_nrows, img_ncols, 3))# combine the 3 images into a single Keras tensorinput_tensor = K.concatenate([base_image,style_reference_image,combination_image], axis=0)# build the VGG16 network with our 3 images as input# the model will be loaded with pre-trained ImageNet weightsmodel = vgg16.VGG16(input_tensor=input_tensor,weights='imagenet', include_top=False)print('Model loaded.')# get the symbolic outputs of each "key" layer (we gave them unique names).outputs_dict = dict([(layer.name, layer.output) for layer in model.layers])# compute the neural style loss# first we need to define 4 util functions# the gram matrix of an image tensor (feature-wise outer product)def gram_matrix(x):assert K.ndim(x) == 3if K.image_data_format() == 'channels_first':features = K.batch_flatten(x)else:features = K.batch_flatten(K.permute_dimensions(x, (2, 0, 1)))gram = K.dot(features, K.transpose(features))return gram# the "style loss" is designed to maintain# the style of the reference image in the generated image.# It is based on the gram matrices (which capture style) of# feature maps from the style reference image# and from the generated imagedef style_loss(style, combination):assert K.ndim(style) == 3assert K.ndim(combination) == 3S = gram_matrix(style)C = gram_matrix(combination)channels = 3size = img_nrows * img_ncolsreturn K.sum(K.square(S - C)) / (4. * (channels ** 2) * (size ** 2))# an auxiliary loss function# designed to maintain the "content" of the# base image in the generated imagedef content_loss(base, combination):return K.sum(K.square(combination - base))# the 3rd loss function, total variation loss,# designed to keep the generated image locally coherentdef total_variation_loss(x):assert K.ndim(x) == 4if K.image_data_format() == 'channels_first':a = K.square(x[:, :, :img_nrows - 1, :img_ncols - 1] - x[:, :, 1:, :img_ncols - 1])b = K.square(x[:, :, :img_nrows - 1, :img_ncols - 1] - x[:, :, :img_nrows - 1, 1:])else:a = K.square(x[:, :img_nrows - 1, :img_ncols - 1, :] - x[:, 1:, :img_ncols - 1, :])b = K.square(x[:, :img_nrows - 1, :img_ncols - 1, :] - x[:, :img_nrows - 1, 1:, :])return K.sum(K.pow(a + b, 1.25))# combine these loss functions into a single scalarloss = K.variable(0.)layer_features = outputs_dict['block4_conv2']base_image_features = layer_features[0, :, :, :]combination_features = layer_features[2, :, :, :]loss += content_weight * content_loss(base_image_features,combination_features)feature_layers = ['block1_conv1', 'block2_conv1','block3_conv1', 'block4_conv1','block5_conv1']for layer_name in feature_layers:layer_features = outputs_dict[layer_name]style_reference_features = layer_features[1, :, :, :]combination_features = layer_features[2, :, :, :]sl = style_loss(style_reference_features, combination_features)loss += (style_weight / len(feature_layers)) * slloss += total_variation_weight * total_variation_loss(combination_image)# get the gradients of the generated image wrt the lossgrads = K.gradients(loss, combination_image)outputs = [loss]if isinstance(grads, (list, tuple)):outputs += gradselse:outputs.append(grads)f_outputs = K.function([combination_image], outputs)def eval_loss_and_grads(x):if K.image_data_format() == 'channels_first':x = x.reshape((1, 3, img_nrows, img_ncols))else:x = x.reshape((1, img_nrows, img_ncols, 3))outs = f_outputs([x])loss_value = outs[0]if len(outs[1:]) == 1:grad_values = outs[1].flatten().astype('float64')else:grad_values = np.array(outs[1:]).flatten().astype('float64')return loss_value, grad_values# this Evaluator class makes it possible# to compute loss and gradients in one pass# while retrieving them via two separate functions,# "loss" and "grads". This is done because scipy.optimize# requires separate functions for loss and gradients,# but computing them separately would be inefficient.class Evaluator(object):def __init__(self):self.loss_value = Noneself.grads_values = Nonedef loss(self, x):assert self.loss_value is Noneloss_value, grad_values = eval_loss_and_grads(x)self.loss_value = loss_valueself.grad_values = grad_valuesreturn self.loss_valuedef grads(self, x):assert self.loss_value is not Nonegrad_values = np.copy(self.grad_values)self.loss_value = Noneself.grad_values = Nonereturn grad_valuesevaluator = Evaluator()# run scipy-based optimization (L-BFGS) over the pixels of the generated image# so as to minimize the neural style lossif K.image_data_format() == 'channels_first':x = np.random.uniform(0, 255, (1, 3, img_nrows, img_ncols)) - 128.else:x = np.random.uniform(0, 255, (1, img_nrows, img_ncols, 3)) - 128.for i in range(iterations):print('Start of iteration', i)start_time = time.time()x, min_val, info = fmin_l_bfgs_b(evaluator.loss, x.flatten(),fprime=evaluator.grads, maxfun=20)print('Current loss value:', min_val)# save current generated imageimg = deprocess_image(x.copy())fname = result_prefix + '_at_iteration_%d.png' % iimsave(fname, img)end_time = time.time()print('Image saved as', fname)print('Iteration %d completed in %ds' % (i, end_time - start_time))
\u590d\u5236\u4e0a\u8ff0\u4ee3\u7801\u4fdd\u5b58\u4e3aneural_style_transfer.py(\u968f\u4fbf\u547d\u540d)
4.\u8fd0\u884c
\u65b0\u5efa\u4e00\u4e2a\u7a7a\u6587\u4ef6\u5939\uff0c\u628a\u4e0a\u4e00\u6b65\u9aa4\u7684\u6587\u4ef6neural_style_transfer.py\u653e\u5165\u8fd9\u4e2a\u7a7a\u6587\u4ef6\u5939\u4e2d\u3002\u7136\u540e\u628a\u76f8\u5e94\u7684\u6a21\u677f\u56fe\u7247\uff0c\u5f85\u8f6c\u5316\u56fe\u7247\u653e\u5165\u8be5\u6587\u4ef6\u5f53\u4e2d\u3002
python neural_style_transfer.py \u4f60\u7684\u5f85\u8f6c\u5316\u56fe\u7247\u8def\u5f84 \u6a21\u677f\u56fe\u7247\u8def\u5f84 \u4fdd\u5b58\u7684\u751f\u4ea7\u56fe\u7247\u8def\u5f84\u52a0\u540d\u79f0\uff08\u6ce8\u610f\u4e0d\u9700\u8981\u6709.jpg\u7b49\u540e\u7f00\uff09python neural_style_transfer.py './me.jpg' './starry_night.jpg' './me_t'
\u8fed\u4ee3\u7ed3\u679c\u622a\u56fe\uff1a

\u8fed\u4ee3\u8fc7\u7a0b\u5bf9\u6bd4

\u53ef\u4ee5\u7528Python\u722c\u866b\u6293\u53d6\u7f51\u7edc\u4e0a\u7684\u56fe\u7247\u3001\u7535\u5f71\u94fe\u63a5\uff1b\u8fd8\u53ef\u4ee5\u7528Python\u7f16\u5199\u81ea\u52a8\u5316\u767b\u5f55\u811a\u672c\uff0c\u7528\u4e8e\u4e00\u4e9b\u8bba\u575b\u7684\u81ea\u52a8\u7b7e\u5230\uff1b\u8fd8\u6709\u4e00\u4e9b\u5e94\u7528\u7684\u7b2c\u4e09\u65b9\u5ba2\u6237\u7aef\u4e5f\u662f\u7528Python\u7f16\u5199\u7684\uff1b\u8fd8\u53ef\u4ee5\u7f16\u5199\u4e00\u4e9b\u5c0f\u6e38\u620f\u3002

躺着赚钱

一位匿名知乎网友爆料用Python写了自动化交易程序,2年躺着赚了200万!相当于普通程序员10年的工资,此刻的心情...你懂的!

不过,这位大侠的真实身份也被网友找出了,真是人红了想低调都不行。

程序员式浪漫

程序员不轻易展示浪漫,一旦浪漫起来也是非常帅的。他们不屑于送情书,也无意送玫瑰花,他们用自己的语言表达对自己另一半的爱,这种语言叫作“代码”。

如果上面这段“代码”不过瘾的话,我们接着欣赏。

代码:

(⊙o⊙)…是不是很高深?这句话的汉语解释是“你的一句明天见,偷走了我整夜的睡眠”。

当然,具备了Money和浪漫,也未必能迎娶白富美,毕竟男女比例失衡的现实摆在这里,但不必担心,Python也为宅男准备了锦囊。

宅男必备

“当硬盘没有空间的时候,当身体无力不能下手;我还是不能和你分手,不能和你分手,你的存在是我治愈空虚的粮酒”,这首《至Python》,扎心了,歌词的原意下图正解!

上述好玩的事情,远远不是Python的全部,接下来给大家介绍几个高大上的。

魔镜

每篇清晨,当我们对着镜子梳妆打扮时,镜子上显示现在的时间、今天的天气,或者一句奋斗的名言警句,会不会有种温馨而又不失斗志的生活感呢?

这个魔镜是由树莓派打造的,树莓派是一款主要基于Linux的单机电脑,可以连接电视、显示器、键盘鼠标等设备,还可以玩游戏和播放视频。Python是树莓派的主要编程语言。

买买买

11月份的前几天,最悲伤的是快递小哥,因为快递量逐天下降,直到双十一下午开始迅速反弹。剁手党们决定将积攒了半个月甚至1个月的物品,在11.11当天全部买入,那么怎样才能买到最实惠的商品呢?毫无疑问,用Python呀!

确定商品类别后,用Python爬出各大购物网站的商品销量、购买数以及折扣信息,就可以及时发现性价比高的了。

人工智能世界名画

2015年,德国科学家用深度学习算法让人工智能系统学习梵高、莫奈等世界著名画家的画风绘制新的“人工智能世界名画”,先让我们来欣赏名画风采。这效果是不是让你很动心?

除了建筑自然风景外,我们也可以将自己的照片,转成世界名画风格,也是很酷的吆。

这个程序代码是可以下载的,有基于Python深度学习库DeepPy的实现版本,有基于Python深度学习库TensorFlow的实现版本,有基于Python深度学习库Caffe的实现版本,还有基于Python深度学习库Keras的实现版本。

python学习网,大量的免费python视频教程,欢迎在线学习!



  • Python鑳藉共浠涔?Python琛屼笟搴旂敤棰嗗煙鏈夊摢浜?
    绛旓細浠ヤ笂涔熶粎鏄粙缁嶄簡Python搴旂敤棰嗗煙鐨勨滃啺灞变竴瑙掆濓紝渚嬪锛岃繕鍙互鍒╃敤Pygame杩涜娓告垙缂栫▼锛涚敤PIL鍜屽叾浠栫殑涓浜涘伐鍏疯繘琛屽浘鍍忓鐞嗭紱鐢≒yRo宸ュ叿鍖呰繘琛屾満鍣ㄤ汉鎺у埗缂栫▼锛岀瓑绛夈傛湁鍏磋叮鐨勮鑰咃紝鍙嚜琛屾悳绱㈣祫鏂欒繘琛岃缁嗕簡瑙c備互涓婂氨鏄叧浜庘Python鑳藉共浠涔锛烶ython琛屼笟搴旂敤棰嗗煙鏈夊摢浜涳紵鈥濈殑鍏ㄩ儴鍐呭鍒嗕韩浜嗭紝甯屾湜灏忓厰鐨勭簿褰╄В绛...
  • 鐜板湪瀛﹀ソpython鑳藉共浠涔?
    绛旓細python鍙互鍋浠涔 1 棣栧厛锛屾渶鍩烘湰鐨勫姛鑳藉氨鏄熷姪python涓嚜甯︾殑绉戝璁$畻鍖匩umpy銆乸adas銆乵atplotlib绛夛紝瀹屾垚澶嶆潅鐨勬暟鎹垎鏋愩2 缃戠粶鐖櫕锛鍒╃敤python鍙互浠庣綉缁滀笂鐖彇浠讳綍鏍煎紡鐨勬暟鎹紝姣斿鏂囨湰鏁版嵁銆侀煶棰戙佽棰戞暟鎹佸浘鐗囩瓑銆## 鏍囬 ##python鐖彇缃戠粶灏忚3 璇嶄簯鍥撅紝鍒╃敤python瀵硅鏂欓泦鍒嗚瘝澶勭悊鍚庯紝杈撳嚭涓у寲...
  • python鑳藉共浠涔?
    绛旓細瀛﹀畬Python涔嬪悗锛屽彲浠ヤ粠浜嬩互涓嬪伐浣滃矖浣嶏細1銆亀eb寮鍙戯細Python鎷ユ湁闈炲父瀹屽杽鐨勪笌web鏈嶅姟鍣ㄨ繘琛屼氦浜掔殑搴擄紝浠ュ強澶ч噺鍏嶈垂鍓嶇缃戦〉妯℃澘锛屾湁闈炲父浼樼鑰屼笖鎴愮啛鐨刣iangoWEB妗嗘灦锛屽姛鑳介綈鍏ㄣ2銆丩inux杩愮淮锛氶氳繃shell鑴氭湰鍘诲疄鐜拌嚜鍔ㄥ寲杩愮淮锛屼絾鏄紪绋嬭兘鍔涜緝寮憋紝鍙互浣跨敤鍔熻兘鐨勫簱寰堝皯锛岃孭ython浣滀负鑳舵按璇█锛屽彲浠ュ緢鏂逛究鐨勪笌鍏朵粬...
  • 瀛︿範Python鍚庡埌搴鑳藉共浠涔
    绛旓細4銆佺綉绔欏悗鍙 鑳藉澶勭悊缃戠珯鍚庡彴鐨勪富娴佺紪绋嬭瑷涓昏杩樻槸Java鍜宲hp锛屽井杞殑.net涔熷彲浠ャPython浣滀负闆嗘垚鍖栫紪绋嬭瑷鍒朵綔璧锋潵涔熻兘寰堝ソ鐨勬彁鍗囨晥鐜囷紝宸茬粡鏈夊緢澶氬垱涓氬叕鍙稿湪閫夋嫨鍒朵綔鍚庡彴缃戠珯鐨勬椂鍊欏凡缁忔湁鎰忚瘑鍦板悜Python闈犳嫝浜嗭紝澧炲姞浜嗙綉绔欏悗鍙扮殑缂栫▼璇█鐨勫紑鍙戞柟鍚戙備互涓婂氨鏄垎浜殑Python璇█鐢ㄥ埌鏈澶氱殑鍑犱釜澶ф柟鍚戙傚綋涓...
  • python鑳藉共浠涔鐢
    绛旓細python鑳藉共浠涔鐢紵璁╂垜浠竴璧蜂簡瑙d竴涓嬪惂锛丳ython鏄竴绉嶈法骞冲彴鐨勮绠楁満绋嬪簭璁捐璇█锛岃兘鍋氬緢澶氫簨鎯咃紝涓昏搴旂敤浜庝互涓嬭繖浜涙柟闈細1銆乄eb寮鍙慞ython鎷ユ湁寰堝鍏嶈垂鏁版嵁鍑芥暟搴撱佸厤璐箇eb缃戦〉妯℃澘绯荤粺銆佷互鍙婁笌web鏈嶅姟鍣ㄨ繘琛屼氦浜掔殑搴擄紝鍙互瀹炵幇web寮鍙戯紝鎼缓web妗嗘灦銆2銆佹暟鎹瀛﹀皢Python鐢ㄤ簬鏈哄櫒瀛︿範锛氬彲浠ョ爺绌朵汉宸ユ櫤鑳姐...
  • 瀛︿範python鑳藉共浠涔
    绛旓細瀛︿範Python鑳藉共浠涔锛熶竴銆丳ython鐨勫簲鐢ㄩ鍩 Python鏄竴绉嶅箍娉浣跨敤鐨楂樼骇缂栫▼璇█锛屽叾搴旂敤棰嗗煙澶氭牱涓斿箍娉涖傚涔燩ython锛屼綘鍙互浠庝簨澶氱棰嗗煙鐨勫伐浣滐紝鍖呮嫭浣嗕笉闄愪簬鏁版嵁鍒嗘瀽銆佹満鍣ㄥ涔犮乄eb寮鍙戙佽嚜鍔ㄥ寲鑴氭湰缂栧啓绛夈備簩銆丳ython鍦ㄦ暟鎹垎鏋愰鍩熺殑搴旂敤 Python鍦ㄦ暟鎹垎鏋愰鍩熸湁鐫骞挎硾鐨勫簲鐢ㄣ傞氳繃瀛︿範Python锛屼綘鍙互浣跨敤...
  • python鑳藉共浠涔
    绛旓細杩愮淮宸ョ▼甯堢粡甯歌鐩戞帶涓婄櫨鍙版満鍣ㄧ殑杩愯锛屾垨鍚屾椂閮ㄧ讲鐨勬儏鍐点浣跨敤Python鍙互鑷姩鍖栨壒閲忕鐞嗘湇鍔″櫒锛岃捣鍒1涓汉椤10涓汉鐨勬晥鏋溿傝嚜鍔ㄥ寲杩愮淮涔熸槸Python鐨勪富瑕佸簲鐢ㄦ柟鍚戜箣涓锛屽畠鍦ㄧ郴缁熺鐞嗐佹枃妗g鐞嗘柟闈㈤兘鏈夊緢寮哄ぇ鐨勫姛鑳姐傚钩鍧囪柂璧勶細15~25K 鎶鑳借姹傦細Python銆乻hell銆丩inux銆佹暟鎹簱銆乷penpyxl搴撶瓑 6銆佽嚜鍔ㄥ寲娴嬭瘯...
  • python閮鍙互骞蹭粈涔?
    绛旓細Python鍙互鍋浠涔寮鍙?浠庝笟鏂瑰悜鏈鍝簺?1銆佽蒋浠跺紑鍙戯細Python璇█鏀寔澶氬嚱鏁扮紪绋嬶紝鍙互鎷呬换浠讳綍杞欢鐨勫紑鍙戝伐浣滐紝鏄畠鐨勬爣閰嶈兘鍔涖2銆佺瀛﹁绠楋細Python鏄竴闂ㄩ氱敤鐨勭▼搴忚璁¤瑷锛屾瘮Matlab鎵閲囩敤鐨勮剼鏈瑷鐨勫簲鐢ㄨ寖鍥存洿骞挎硾锛屾湁鏇村鐨勭▼搴忓簱鐨勬敮鎸侊紝鍋氱瀛﹁绠楁槸闈炲父鍚堥傜殑閫夋嫨銆3銆佽嚜鍔ㄥ寲杩愮淮锛歅ython鏄綔涓鸿繍缁...
  • python瀛︽潵涓昏鏄共浠涔堢殑
    绛旓細鍏跺疄python鏈瀹冪殑寮哄ぇ涔嬪锛屼粖澶╂垜浠潵鎵掍竴鎵抪ython涓浠涔杩欎箞鐏紝瀹冨埌搴曢兘鑳藉共鍟锛 涓寮犲浘鐗囩湅鎳俻ython涓昏搴旂敤棰嗗煙锛1銆佷簯璁$畻 PYTHON璇█绠楁槸浜戣绠楁渶鐏殑璇█锛 鍏稿瀷搴旂敤OpenStack銆2銆乄EB鍓嶇寮鍙 python鐩告瘮php\ruby鐨勬ā鍧楀寲璁捐锛岄潪甯镐究浜庡姛鑳芥墿灞曪紱澶氬勾鏉ュ舰鎴愪簡澶ч噺浼樼鐨剋eb寮鍙戞鏋讹紝骞朵笖鍦ㄤ笉鏂...
  • 瀛︿範Python鍒板簳鑳藉共浠涔
    绛旓細浣犲彲鑳藉凡缁忓惉璇磋繃寰堝绉嶆祦琛岀殑缂栫▼璇█锛屾瘮濡傚湪澶у閲屾劅瑙夐潪甯搁毦瀛︾殑C璇█锛岃繘鍏ョぞ浼氶潪甯告祦琛岀殑Java璇█锛屼互鍙婇傚悎鍒濆鑰呯殑Basic璇█锛岄潪甯搁傚悎缃戦〉缂栫▼鐨凧ava璇█绛夛紝Python鏄粬浠叾涓殑涓绉嶃侾ython鍙互鍋浠涔锛1锛夌綉绔欏悗绔▼搴忓憳锛浣跨敤瀹冨崟闂寸綉绔欙紝鍚庡彴鏈嶅姟姣旇緝瀹规槗缁存姢銆傚锛欸mail銆乊outube銆佺煡涔庛佽眴鐡 2...
  • 扩展阅读:学python后到底能干什么 ... 学python有前途吗 ... python培训班学费一般多少 ... python编程入门自学 ... c++和python先学哪个 ... 学python最佳年龄 ... python初学编程必背 ... python就业太难了 ... python一个月能挣多少钱 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网