This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| children_counter = 0 | |
| for n,c in rn18.named_children(): | |
| print("Children Counter: ",children_counter," Layer Name: ",n,) | |
| children_counter+=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from torchvision import models | |
| rn18 = models.resnet18(pretrained=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |