2017 Python最新面试题及答案16道题

15个重要Python面试题 测测你适不适合做Python?

torch.squeeze()

Returns a tensor with all the dimensions of input of size 1 removed.

torch.unsqueeze(input, dim, out=None) → Tensor
Returns a new tensor with a dimension of size one inserted at the specified position.

Python 3:filter()

filter() 函数用于过滤序列,过滤掉不符合条件的元素,返回一个迭代器对象,如果要转换为列表,可以使用 list() 来转换。

该接收两个参数,第一个为函数,第二个为序列,序列的每个元素作为参数传递给函数进行判,然后返回 True 或 False,最后将返回 True 的元素放到新列表中。

Gensim

Gensim是一款开源的第三方Python工具包,用于从原始的非结构化的文本中,无监督地学习到文本隐层的主题向量表达。它支持包括TF-IDF,LSA,LDA,和word2vec在内的多种主题模型算法,支持流式训练,并提供了诸如相似度计算,信息检索等一些常用任务的API接口。简单地说,Gensim主要处理文本数据,对文本数据进行建模挖掘。

https://blog.csdn.net/HuangZhang_123/article/details/80326363

traceback

捕获并打印异常,可以输出哪个文件哪个函数哪一行报的错。

@classmethod,@staticmethod,@property

torch.max()

__call__

在类中实现该方法,一个类实例可以变成一个可调用对象。

代码出处:https://www.cnblogs.com/superxuezhazha/p/5793536.html

更多特殊函数: https://www.cnblogs.com/xiao987334176/p/8884002.html#autoid-0-1-0

IoU(Intersection over Union)的计算

def IOU(xywh1, xywh2):
    x1, y1, w1, h1 = xywh1
    x2, y2, w2, h2 = xywh2

dx = min(x1+w1, x2+w2) - max(x1, x2)
    dy = min(y1+h1, y2+h2) - max(y1, y2)
    intersection = dx * dy if (dx >=0 and dy >= 0) else 0.
    
    union = w1 * h1 + w2 * h2 - intersection
    return (intersection / union)

其中(x1,y1),(x2,y2)分别为两个矩阵左下角的顶点,w,h为宽和高。

xml解析

https://www.cnblogs.com/zqchen/articles/3936805.html

layer of model

model.children() returns an iterable of high-level layers present in model.

model.named_children() returns an iterable of two-element tuples, where the first element is the name of the high-level layer and the second element is the high-level layer.

inception loss

if is_inception and phase == 'train':
                        # From https://discuss.pytorch.org/t/how-to-optimize-inception-model-with-auxiliary-classifiers/7958
                        outputs, aux_outputs = model(inputs)
                        loss1 = criterion(outputs, labels)
                        loss2 = criterion(aux_outputs, labels)
                        loss = loss1 + 0.4*loss2

inception_v3 requires the input size to be (299,299), whereas all of the other models expect (224,224).

详解Pytorch中的网络构造(nn.Module)

https://zhuanlan.zhihu.com/p/53927068

affine_grad和grid_sample

https://www.jianshu.com/p/723af68beb2e

torch.gather

torch.cat

.view() : reshape a tensor.

By default, user created Tensors have 'requires_grad = False'

.requires_grad_() 和 .detach()

torch.nn.ReplicationPad2d(padding)

Pads the input tensor using replication of the input boundary.

torch.tensor(np_array):

.numpy():Converting a Torch Tensor to a NumPy Array

.from_numpy: Converting NumPy Array to Torch Tensor

tensor_b is a different view (interpretation) of the same data present in the underlying storage

torch.stack: 增加新的维度做堆叠

torch.masked_select :在训练阶段,损失函数通常需要进行mask操作,因为一个batch中句子的长度通常是不一样的,一个batch中不足长度的位置需要进行填充(pad)补0,最后生成句子计算loss时需要忽略那些原本是pad的位置的值,即只保留mask中值为1位置的值,忽略值为0位置的值

Python标准库(3.x): itertools库

https://www.cnblogs.com/tp1226/p/8453564.html

Python标准库(3.x): 内建函数

https://www.cnblogs.com/tp1226/p/8446503.html

torch.einsum:

https://www.jqr.com/article/000481

Scikit-Learn中TF-IDF权重计算方法主要用到两个类:CountVectorizer和TfidfTransformer

Pytorch Code积累的更多相关文章

  1. Iris Classification on PyTorch

    Iris Classification on PyTorch code # -*- coding:utf8 -*- from sklearn.datasets import load_iris fro ...

  2. (转载)PyTorch代码规范最佳实践和样式指南

    A PyTorch Tools, best practices & Styleguide 中文版:PyTorch代码规范最佳实践和样式指南 This is not an official st ...

  3. 使用PyTorch构建神经网络以及反向传播计算

    使用PyTorch构建神经网络以及反向传播计算 前一段时间南京出现了疫情,大概原因是因为境外飞机清洁处理不恰当,导致清理人员感染.话说国外一天不消停,国内就得一直严防死守.沈阳出现了一例感染人员,我在 ...

  4. 实践torch.fx第一篇——基于Pytorch的模型优化量化神器

    第一篇--什么是torch.fx 今天聊一下比较重要的torch.fx,也趁着这次机会把之前的torch.fx笔记整理下,笔记大概拆成三份,分别对应三篇: 什么是torch.fx 基于torch.fx ...

  5. 论文笔记:Auto-DeepLab: Hierarchical Neural Architecture Search for Semantic Image Segmentation

    Auto-DeepLab: Hierarchical Neural Architecture Search for Semantic Image Segmentation2019-03-18 14:4 ...

  6. 【Beta】测试报告

    测试计划 一.对新增加的用户注册.登录及访问控制的测试 注册信息的填写 用户名包含纯大小写字母.数字.中文.特殊字符及几种情况的混合 密码包含大小写字母.数字和特殊字符 用户名长度不大于150个字节 ...

  7. An intriguing failing of convolutional neural networks and the CoordConv solution

    An intriguing failing of convolutional neural networks and the CoordConv solution NeurIPS 2018 2019- ...

  8. Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization

    Arbitrary Style Transfer in Real-time with Adaptive Instance Normalization 2019-10-10 10:50:19 Paper ...

  9. SiamRPN: High Performance Visual Tracking with Siamese Region Proposal Network

    High Performance Visual Tracking with Siamese Region Proposal Network 2018-11-26 18:32:02 Paper:http ...

随机推荐

  1. 【浅墨Unity3D Shader编程】之中的一个 夏威夷篇:游戏场景的创建 & 第一个Shader的书写

    本系列文章由@浅墨_毛星云 出品.转载请注明出处. 文章链接:http://blog.csdn.net/poem_qianmo/article/details/40723789 作者:毛星云(浅墨)  ...

  2. 基于 Android NDK 的学习之旅-----HelloWorld

    Hello World作为所有编程语言的起始阶段,占据着无法改变的地位,所有中/英/法/德/美……版本的编程教材中,hello world总是作为第一个TEST记录于书本之中,所有的编程第一步就在于此 ...

  3. 【hdu 4315】Climbing the Hill

    Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...

  4. 微信小程序从零开始开发步骤(一)

    从零到有写一个小程序系列专题,很早以前就想写来分享,但由于项目一直在进展,没有过多的时间研究技术,现在可以继续分享了.1:注册用没有注册过微信公众平台的邮箱注册一个微信公众号, 申请帐号 ,点击 ht ...

  5. STS开发环境搭建与配置

    STS开发环境搭建与配置 (2012-04-11 07:24:51) 转载▼ 1.   环境准备 安装JDK.MAVEN 1.1.        下载 下载sprdfingsource-tool-su ...

  6. 一个封装比较完整的FTP类——clsFTP

    前几天,看见园子里面的博友写了一个支持断点续传的FTP类,一时技痒,干脆写了个更完整的clsFtp类.只是我写这个clsFtp不是支持断点续传的目的,而是为了封装FTP几个基本常用的操作接口. 功能 ...

  7. NOIP模拟 Game - 简单博弈,dp

    题意: 有n个带权球,A和B两个人,A先手拿球,一开始可以拿1个或2个,如果前一个人拿了k个,那么当前的这个人只能那k或k+1个,如果当前剩余的球不足,那么剩下的球都作废,游戏结束.假设两个人都是聪明 ...

  8. Erlang与ActionScript3采用JSON格式进行Socket通讯

    http://hideto.iteye.com/blog/235811 需要下载as3corelib来为ActionScript3处理JSON codec server.erl -module(ser ...

  9. 【codeforces 777C】 Alyona and Spreadsheet

    [题目链接]:http://codeforces.com/contest/777/problem/C [题意] 给你n行m列的矩阵: 然后给你k个询问[l,r]; 问你在第l到第r行,是否存在一个列, ...

  10. 【项目积累】对JSON数据的处理

    [项目简述]         接触.NET项目非常长一段时间了,前台用的都是MVC框架.不知道大家是否想过一个问题.我们是怎样将数据显示到前台的,换句话说,MVC能够识别怎么样的数据形式?答案非常ea ...