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) #####################################
return transformer(data.astype(np.float32)), label trainset = data.vision.datasets.ImageFolderDataset("./dataset/valid_train", 1, train_transform) validset = data.vision.datasets.ImageFolderDataset("./dataset/valid_test", 1, valid_transform) trainloader = data.DataLoader(trainset, batch_size, True, num_workers=8, pin_memory=True) validloader = data.DataLoader(validset, batch_size, False) # model mobilenet = vision.mobilenet0_5(pretrained=True, ctx=ctx).features clf = nn.Sequential() with clf.name_scope(): clf.add(nn.Dense(4096, activation='relu'), nn.Dense(4096, activation='relu'), nn.Dense(1024, activation='relu'), nn.Dense(6)) clf.collect_params().initialize(init=init.Xavier(), ctx=ctx) # scheduler + trainer if args.mask: steps_epochs = [150, 175] else: steps_epochs = [150] it_per_epoch = math.ceil(1243 / batch_size) steps_iterations = [s * it_per_epoch for s in steps_epochs]
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).