################## # Hyperparameter # #----------------# ctx = mx.cpu() lr = 0.05 epochs = 10 momentum = 0.9 batch_size = 64 #----------------# # Hyperparameter # ################## ################## model from mxnet.gluon.model_zoo import vision net = vision.densenet121(classes=10, pretrained=False, ctx=ctx) # net = vision.densenet161(classes=10, pretrained=False, ctx=ctx) # net = vision.densenet169(classes=10, pretrained=False, ctx=ctx) # net = vision.densenet201(classes=10, pretrained=False, ctx=ctx) ################## 그래프 import gluoncv inputShape = (1, 3, 224, 224) gluoncv.utils.viz.plot_network(net, shape=inputShape) ##### 전처리 ############################################## def transformer(data, label): data = mx.image.imresize(data, 224, 224) data = mx.nd.transpose(data, (2, 0, 1))
import mxnet as mx import time import gluoncv from mxnet import nd, autograd from mxnet import gluon from mxnet.gluon import nn inputShape = (1, 3, 224, 224) from mxnet.gluon.model_zoo import vision alexnet = vision.alexnet() inception = vision.inception_v3() resnet18v1 = vision.resnet18_v1() resnet18v2 = vision.resnet18_v2() squeezenet = vision.squeezenet1_0() densenet = vision.densenet121() mobilenet = vision.mobilenet0_5() ############### 그래프 ############### import gluoncv gluoncv.utils.viz.plot_network(resnet18v1, shape=inputShape) #####################################
out = out.as_in_context(mx.cpu()) out = out.asnumpy() res = '' for item in out: res += str(item) +' ' #print(res) fw1.write(res+'\n') label = root.strip().split('/')[-1] if(train == True): fw2.write(label+'\n') print(label) else: fw2.write(file+'\n') print(file) fw1.close() fw2.close() print('net done!!!') pretrained_net = models.densenet121(pretrained=True) net = nn.HybridSequential() for layer in pretrained_net.features: net.add(layer) print(net) ctx = mx.gpu() net.collect_params().reset_ctx(ctx) net.hybridize() dir = 'data/test_b/' suffix=['jpg'] batch_net(dir,suffix,net,train=False)
import json import matplotlib.pyplot as plt import mxnet as mx from mxnet import gluon, nd from mxnet.gluon.model_zoo import vision import numpy as np ctx = mx.cpu() densenet121 = vision.densenet121(pretrained=True, ctx=ctx) mobileNet = vision.mobilenet0_5(pretrained=True, ctx=ctx) resnet18 = vision.resnet18_v1(pretrained=True, ctx=ctx) mx.test_utils.download( 'https://raw.githubusercontent.com/dmlc/web-data/master/mxnet/doc/tutorials/onnx/image_net_labels.json' ) categories = np.array(json.load(open('image_net_labels.json', 'r'))) # filename = mx.test_utils.download('https://github.com/dmlc/web-data/blob/master/mxnet/doc/tutorials/onnx/images/dog.jpg?raw=true', fname='dog.jpg') filename = 'scorp.jpg' image = mx.image.imread(filename) plt.imshow(image.asnumpy()) plt.show() # Read the image: this will return a NDArray shaped as (image height, image width, 3), with the three channels in RGB order. # Resize the shorter edge of the image 224. # Crop, using a size of 224x224 from the center of the image. # Shift the mean and standard deviation of our color channels to match the ones of the dataset the network has been trained on. # Transpose the array from (Height, Width, 3) to (3, Height, Width).
def densenet121mxnetload(): net = vision.densenet121(pretrained=True) net.hybridize() return net