首页 > 其他分享 >PyTorchStepByStep - Chapter 5: Convolutions

PyTorchStepByStep - Chapter 5: Convolutions

时间:2024-10-17 22:01:19浏览次数:1  
标签:Chapter region PyTorchStepByStep single Convolutions filtered np new total

 

single = np.array(
    [[[[5, 0, 8, 7, 8, 1],
       [1, 9, 5, 0, 7, 7],
       [6, 0, 2, 4, 6, 6],
       [9, 7, 6, 6, 8, 4],
       [8, 3, 8, 5, 1, 3],
       [7, 2, 7, 0, 1, 0]]]]
)
single.shape  # (1, 1, 6, 6)

identity = np.array(
    [[[[0, 0, 0],
       [0, 1, 0],
       [0, 0, 0]]]]
)
identity.shape  # (1, 1, 3, 3)

 

region = single[:, :, 0:3, 0:3]
filtered_region = region * identity
total = filtered_region.sum()
total  # np.int64(9)

 

new_region = single[:, :, 0:3, (0 + 1):(3 + 1)]

 

new_filtered_region = new_region * identity
new_total = new_filtered_region.sum()
new_total  # np.int64(5)

 

last_horizontal_region = single[:, :, 0:3, (0 + 4):(3 + 4)]

The selected region does not match the shape of the filter anymore. So, if we try to perform the element-wise multiplication, it fails:

 

标签:Chapter,region,PyTorchStepByStep,single,Convolutions,filtered,np,new,total
From: https://www.cnblogs.com/zhangzhihui/p/18473208

相关文章

  • PyTorchStepByStep - Bonus Chapter: Feature Space
      ......
  • PyTorchStepByStep - Chapter 3: A Simple Classification Problem
     X,y=make_moons(n_samples=100,noise=.3,random_state=0)X_train,X_val,y_train,y_val=train_test_split(X,y,test_size=.2,random_state=13) sc=StandardScaler()sc.fit(X_train)X_train=sc.transform(X_train)X_val=sc.transform(X_val......
  • PyTorchStepByStep - Chapter 2.1: Going Classy
     classStepByStep():def__init__(self,model,loss_fn,optimizer):self.device='cuda'iftorch.cuda.is_available()else'cpu'self.model=model.to(self.device)self.loss_fn=loss_fnself.opti......
  • PyTorchStepByStep - Chapter 2: Rethinking the Training Loop
      defmake_train_step_fn(model,loss_fn,optimizer):defperform_train_step_fn(x,y):#SetmodeltoTRAINmodemodel.train()#Step1-Computemodel'spredictions-forwardpassyhat=model(x)......
  • Cornell cs3110 - Chapter9 Lessons
    使用Menhir构建SimPL的编译器LexerandParser语法分析模块Lexer,Parser,AST是三个依次耦合的模块,可以这么描述三者的关系:Lexer---tokens-->Parser---nodes-->AST相对于上面的图像化描述,cs3110反过来构建整个Lexer和Parser的结构在ast.ml中,定义了AST上......
  • Cornell cs3110 - Chapter7 Exercises
    (*Exercise:mutablefields*)typestudent={name:string;mutablegpa:float;}letstuA={name="Alice";gpa=3.7}let()=stuA.gpa<-4.0(*Exercise:intfun*)letinc=ref(funx->x+1)letnum=!inc3109(*Exercise:a......
  • Cornell cs3110 - Chapter6 Exercises
    (*Exercise:specgame*)(*Whereisanotherprogrammer?*)(*Exercise:polyspec*)(*[Poly]representsimmutablepolynomialswithintegercoeffcients*)moduletypePoly=sig(*[t]isthetypeofpolynomials*)typet(*[evalxp]is[p]e......
  • Cornell cs3110 - Chapter5 Exercises
    (*Exercise:complexsynonym*)moduletypeComplexSig=sigtypecomplexvalzero:complexvaladd:complex->complex->complexend(*Exercise:complexencapsulation*)moduleComplex:ComplexSig=structtypecomplex=float*flo......
  • Cornell cs3110 - Chapter4 Exercises
    (*Exercise:mysteryoperator1*)let($)fx=fx;;(*使得函数的连续调用具有一部分右结合的特质square$2+2与square2+2的运行结果分别是16和6*)(*Exercise:repeat*)letrecrepeatfnx=matchnwith|0->x|_->repeatf(n-1)......
  • Cornell cs3110 - Chapter3 Exercises
    (*Exercise:listexpressions*)letlist1=[1;2;3;4;5];;letlist2=1::2::3::4::5::[];;letlist3=[1]@[2;3;4;]@[5];;(*Exercise:product*)letrecproductl=matchlwith|[]->1|h::t->h*productt;;(*......