Skip to content

Instantly share code, notes, and snippets.

View sadimanna's full-sized avatar
🎯
Focusing

Siladittya Manna sadimanna

🎯
Focusing
View GitHub Profile
import torch
import torch.nn as nn
from torchvision.models.utils import load_state_dict_from_url
from typing import Type, Any, Callable, Union, List, Dict, Optional, cast
from torch import Tensor
from collections import OrderedDict
class new_model(nn.Module):
def __init__(self, output_layer):
super().__init__()
self.output_layer = output_layer
self.pretrained = models.resnet18(pretrained=True)
self.children_list = []
for n,c in self.pretrained.named_children():
self.children_list.append(c)
if n == self.output_layer:
break
class new_model(nn.Module):
def __init__(self,output_layer = None):
super().__init__()
self.pretrained = models.resnet18(pretrained=True)
self.output_layer = output_layer
self.layers = list(self.pretrained._modules.keys())
self.layer_count = 0
for l in self.layers:
if l != self.output_layer:
self.layer_count += 1
children_counter = 0
for n,c in rn18.named_children():
print("Children Counter: ",children_counter," Layer Name: ",n,)
children_counter+=1
from torchvision import models
rn18 = models.resnet18(pretrained=True)
nBytesTotal = nImg*nR*nC*1 #since each pixel data is 1 byte
images_array = np.asarray(st.unpack('>'+'B'*nBytesTotal,imagesfile.read(nBytesTotal))).reshape((nImg,nR,nC))
import sympy as sp
if __name__ == '__main__':
stime = time.time()
denominations = [1,2,5,10,20,50,100,200]
maxpowers = [200//d for d in denominations]
x = sp.symbols('x')
fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X, Y, datapts,color='goldenrod')
def animate(i):
# "i" is updated for each frame i = 10 when frame = 10
# for 360 frames, azim will take 360 values for a round display of the 3D plot
ax.view_init(elev=10., azim=i)
return fig,
from mpl_toolkits import mplot3d
from matplotlib import animation
from mpl_toolkits.mplot3d import Axes3D
X, Y = np.meshgrid(x, y)
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_wireframe(X, Y, datapts, color='black')
ax.view_init(elev=2., azim=30) #JUST FOR CLEARLY VIEWING THIS PLOT
ax.set_title('wireframe')
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1.inset_locator import zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset