首页 炒股软件文章正文

厦门蓝帽子最新股价:今天中国银行股价图

炒股软件 2021年03月08日 00:30 6999 云鼎网络

# pylint: skip-fileimport randomimport cv2import mxnet as mximport numpy as npimport osfrom mxnet.io import DataIter, DataBatchclass FileIter(DataIter): #一般都是继承DataIter """FileIter object in fcn-xs example. Taking a file list file to get dataiter. in this example, we use the whole image training for fcn-xs, that is to say we do not need resize/crop the image to the same size, so the batch_size is set to 1 here Parameters ---------- root_dir : string the root dir of image/label lie in flist_name : string the list file of iamge and label, every line owns the form: index \t image_data_path \t image_label_path cut_off_size : int if the maximal size of one image is larger than cut_off_size, then it will crop the image with the minimal size of that image data_name : string the data name used in symbol data(default data name) label_name : string the label name used in symbol softmax_label(default label name) """ def __init__(self, root_dir, flist_name, rgb_mean=(117, 117, 117), data_name="data", label_name="softmax_label", p=None): super(FileIter, self).__init__() self.fac = p.fac #这里的P是自己定义的config self.root_dir = root_dir self.flist_name = os.path.join(self.root_dir, flist_name) self.mean = np.array(rgb_mean) # (R, G, B) self.data_name = data_name self.label_name = label_name self.batch_size = p.batch_size self.random_crop = p.random_crop self.random_flip = p.random_flip self.random_color = p.random_color self.random_scale = p.random_scale self.output_size = p.output_size self.color_aug_range = p.color_aug_range self.use_rnn = p.use_rnn self.num_hidden = p.num_hidden if self.use_rnn: self.init_h_name = 'init_h' self.init_h = mx.nd.zeros((self.batch_size, self.num_hidden)) self.cursor = -1 self.data = mx.nd.zeros((self.batch_size, 3, self.output_size[0], self.output_size[1])) self.label = mx.nd.zeros((self.batch_size, self.output_size[0] / self.fac, self.output_size[1] / self.fac)) self.data_list = [] self.label_list = [] self.order = [] self.dict = {} lines = file(self.flist_name).read().splitlines() cnt = 0 for line in lines: #读取lst厦门蓝帽子最新股价,为后面读取图片做好准备 _, data_img_name, label_img_name = line.strip('\n').split("\t") self.data_list.append(data_img_name) self.label_list.append(label_img_name) self.order.append(cnt) cnt += 1 self.num_data = cnt self._shuffle() def _shuffle(self): random.shuffle(self.order) def _read_img(self, img_name, label_name):      # 这个是在服务器上跑的时候,因为数据集很小,而且经常被同事卡IO,所以我就把数据全部放进了内存 if os.path.join(self.root_dir, img_name) in self.dict: img = self.dict[os.path.join(self.root_dir, img_name)] else: img = cv2.imread(os.path.join(self.root_dir, img_name)) self.dict[os.path.join(self.root_dir, img_name)] = img if os.path.join(self.root_dir, label_name) in self.dict: label = self.dict[os.path.join(self.root_dir, label_name)] else: label = cv2.imread(os.path.join(self.root_dir, label_name),0) self.dict[os.path.join(self.root_dir, label_name)] = label      # 下面是读取图片后的一系统预处理工作 if self.random_flip: flip = random.randint(0, 1) if flip == 1: img = cv2.flip(img, 1) label = cv2.flip(label, 1) # scale jittering scale = random.uniform(self.random_scale[0], self.random_scale[1]) new_width = int(img.shape[1] * scale) # 680 new_height = int(img.shape[0] * scale) # new_width * img.size[1] / img.size[0] img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_NEAREST) label = cv2.resize(label, (new_width, new_height), interpolation=cv2.INTER_NEAREST) #img = cv2.resize(img, (900,450), interpolation=cv2.INTER_NEAREST) #label = cv2.resize(label, (900, 450), interpolation=cv2.INTER_NEAREST) if self.random_crop: start_w = np.random.randint(0, img.shape[1] - self.output_size[1] + 1) start_h = np.random.randint(0, img.shape[0] - self.output_size[0] + 1) img = img[start_h : start_h + self.output_size[0], start_w : start_w + self.output_size[1], :] label = label[start_h : start_h + self.output_size[0], start_w : start_w + self.output_size[1]] if self.random_color: img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) hue = random.uniform(-self.color_aug_range[0], self.color_aug_range[0]) sat = random.uniform(-self.color_aug_range[1], self.color_aug_range[1]) val = random.uniform(-self.color_aug_range[2], self.color_aug_range[2]) img = np.array(img, dtype=np.float32) img[..., 0] += hue img[..., 1] += sat img[..., 2] += val img[..., 0] = np.clip(img[..., 0], 0, 255) img[..., 1] = np.clip(img[..., 1], 0, 255) img[..., 2] = np.clip(img[..., 2], 0, 255) img = cv2.cvtColor(img.astype('uint8'), cv2.COLOR_HSV2BGR) is_rgb = True #cv2.imshow('main', img) #cv2.waitKey() #cv2.imshow('maain', label) #cv2.waitKey() img = np.array(img, dtype=np.float32) # (h, w, c) reshaped_mean = self.mean.reshape(1, 1, 3) img = img - reshaped_mean img[:, :, :] = img[:, :, [2, 1, 0]] img = img.transpose(2, 0, 1) # img = np.expand_dims(img, axis=0) # (1, c, h, w) label_zoomed = cv2.resize(label, None, fx = 1.0 / self.fac, fy = 1.0 / self.fac) label_zoomed = label_zoomed.astype('uint8') return (img, label_zoomed) @property def provide_data(self): """The name and shape of data provided by this iterator""" if self.use_rnn: return [(self.data_name, (self.batch_size, 3, self.output_size[0], self.output_size[1])), (self.init_h_name, (self.batch_size, self.num_hidden))] else: return [(self.data_name, (self.batch_size, 3, self.output_size[0], self.output_size[1]))] @property def provide_label(self): """The name and shape of label provided by this iterator""" return [(self.label_name, (self.batch_size, self.output_size[0] / self.fac, self.output_size[1] / self.fac))] def get_batch_size(self): return self.batch_size def reset(self): self.cursor = -self.batch_size self._shuffle() def iter_next(self): self.cursor += self.batch_size return self.cursor < self.num_data def _getpad(self): if self.cursor + self.batch_size > self.num_data: return self.cursor + self.batch_size - self.num_data else: return 0 def _getdata(self): """Load data from underlying arrays, internal use only""" assert(self.cursor < self.num_data), "DataIter needs reset." data = np.zeros((self.batch_size, 3, self.output_size[0], self.output_size[1])) label = np.zeros((self.batch_size, self.output_size[0] / self.fac, self.output_size[1] / self.fac)) if self.cursor + self.batch_size <= self.num_data: for i in range(self.batch_size): idx = self.order[self.cursor + i] data_, label_ = self._read_img(self.data_list[idx], self.label_list[idx]) data[i] = data_ label[i] = label_ else: for i in range(self.num_data - self.cursor): idx = self.order[self.cursor + i] data_, label_ = self._read_img(self.data_list[idx], self.label_list[idx]) data[i] = data_ label[i] = label_ pad = self.batch_size - self.num_data + self.cursor #for i in pad: for i in range(pad): idx = self.order[i] data_, label_ = self._read_img(self.data_list[idx], self.label_list[idx]) data[i + self.num_data - self.cursor] = data_ label[i + self.num_data - self.cursor] = label_ return mx.nd.array(data), mx.nd.array(label) def next(self): """return one dict which contains "data" and "label" """ if self.iter_next(): data, label = self._getdata() data = [data, self.init_h] if self.use_rnn else [data] label = [label] return DataBatch(data=data, label=label, pad=self._getpad(), index=None, provide_data=self.provide_data, provide_label=self.provide_label) else: raise StopIteration成交量放大 股价微跌

总结:实际上学一个框架的关键还是使用它厦门蓝帽子最新股价,要说诀窍的话也就是多看看源码和文档了,我写这些博客的目的,一是为了记录一些东西,二是让后来者少走一些弯路。所以有些东西不会说的很全。。

厦门蓝帽子最新股价:今天中国银行股价图

将mxnet/目录里找到mxnet/make/子目录厦门蓝帽子最新股价,把该目录下的config.mk复制到mxnet/目录,用文本编辑器打开,找到并修改以下两行:

1. 硬盘没有分区的情况下会出现A:GHOSTERR.TXT厦门蓝帽子最新股价

厦门蓝帽子最新股价:今天中国银行股价图

每个参数的意义在代码内部都可以查到厦门蓝帽子最新股价,简单说一下这里用到的:--list=True说明这次的目的是make list,后面紧跟的是生成的list的名字的前缀,我这里是加了路径,然后是图片所在文件夹的路径,recursive是是否迭代的进入文件夹读取图片,--train-ratio则表示train和val在数据集中的比例。荣宝斋股价

USE_CUDA_PATH = /usr/local/cuda

厦门蓝帽子最新股价:今天中国银行股价图

我这个label是瞎填的厦门蓝帽子最新股价,所以都是0。另外最新的MXnet上面的im2rec是有问题的,它生成的list所有的index都是0,不过据说这个index没什么用.....但我还是改了一下。把yield生成器换成直接append即可。海康威视股价海康威视报价

import mxnet as mximport loggingimport numpy as np logger = logging.getLogger() logger.setLevel(logging.DEBUG)#暂时不需要管的logdef ConvFactory(data, num_filter, kernel, stride=(1,1), pad=(0, 0), act_type="relu"): conv = mx.symbol.Convolution(data=data, workspace=256, num_filter=num_filter, kernel=kernel, stride=stride, pad=pad) return conv #我把这个删除到只有一个卷积的操作def DownsampleFactory(data, ch_3x3): # conv 3x3 conv = ConvFactory(data=data, kernel=(3, 3), stride=(2, 2), num_filter=ch_3x3, pad=(1, 1)) # pool pool = mx.symbol.Pooling(data=data, kernel=(3, 3), stride=(2, 2), pool_type='max') # concat concat = mx.symbol.Concat(*[conv, pool]) return concatdef SimpleFactory(data, ch_1x1, ch_3x3): # 1x1 conv1x1 = ConvFactory(data=data, kernel=(1, 1), pad=(0, 0), num_filter=ch_1x1) # 3x3 conv3x3 = ConvFactory(data=data, kernel=(3, 3), pad=(1, 1), num_filter=ch_3x3) #concat concat = mx.symbol.Concat(*[conv1x1, conv3x3]) return concatif __name__ == "__main__": batch_size = 1 train_dataiter = mx.io.ImageRecordIter( shuffle=True, path_imgrec="/home/erya/dhc/result/try_train.rec", rand_crop=True, rand_mirror=True, data_shape=(3,28,28), batch_size=batch_size, preprocess_threads=1)#这里是使用我们之前的创造的数据,简单的说就是要自己写一个iter,然后把相应的参数填进去厦门蓝帽子最新股价。 test_dataiter = mx.io.ImageRecordIter( path_imgrec="/home/erya/dhc/result/try_val.rec", rand_crop=False, rand_mirror=False, data_shape=(3,28,28), batch_size=batch_size, round_batch=False, preprocess_threads=1)#同理 data = mx.symbol.Variable(name="data") conv1 = ConvFactory(data=data, kernel=(3,3), pad=(1,1), num_filter=96, act_type="relu") in3a = SimpleFactory(conv1, 32, 32) fc = mx.symbol.FullyConnected(data=in3a, num_hidden=10) softmax = mx.symbol.SoftmaxOutput(name='softmax',data=fc)#上面就是定义了一个巨巨巨简单的结构 # For demo purpose, this model only train 1 epoch # We will use the first GPU to do training num_epoch = 1 model = mx.model.FeedForward(ctx=mx.gpu(), symbol=softmax, num_epoch=num_epoch, learning_rate=0.05, momentum=0.9, wd=0.00001) #将整个model训练的架构定下来了,类似于caffe里面solver所做的事情。# we can add learning rate scheduler to the model# model = mx.model.FeedForward(ctx=mx.gpu(), symbol=softmax, num_epoch=num_epoch,# learning_rate=0.05, momentum=0.9, wd=0.00001,# lr_scheduler=mx.misc.FactorScheduler(2))model.fit(X=train_dataiter, eval_data=test_dataiter, eval_metric="accuracy", batch_end_callback=mx.callback.Speedometer(batch_size))#开跑数据。

厦门蓝帽子最新股价:今天中国银行股价图

上个周末的大盘波动,终于给这场比武分出了高下厦门蓝帽子最新股价。股市无神再次规避了风险,而叶荣添就没那么幸运。两人互察账户,差距一下就被拉大800万以上。股市无神在这次对决中,成为最大的赢家。

2.binded,在把data和label的shape传到Bind函数里并且执行之后,显存就分配好了,可以准备好计算能力厦门蓝帽子最新股价。厦门蓝帽子最新股价

发表评论

云鼎资讯Copyright Your WebSite.Some Rights Reserved|云鼎网络| 云鼎网站