当前位置: 首页>>代码示例>>Python>>正文


Python cnn.CNN属性代码示例

本文整理汇总了Python中cnn.CNN属性的典型用法代码示例。如果您正苦于以下问题:Python cnn.CNN属性的具体用法?Python cnn.CNN怎么用?Python cnn.CNN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在cnn的用法示例。


在下文中一共展示了cnn.CNN属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: train

# 需要导入模块: import cnn [as 别名]
# 或者: from cnn import CNN [as 别名]
def train(algorithm, args):
    if algorithm == "mc_svm":
        # create multiclass SVM model
        return MultiSVM()
    elif algorithm == "struct_svm":
        return StructuredSVM(args.iterations)
    elif algorithm == "quad_kernel":
        return StructuredSVM(lambda_fn = lambda x,y: x.dot(y) ** 2)
    elif algorithm == "rbf_kernel":
        return StructuredSVM(lambda_fn = lambda x,y: math.e ** (-np.linalg.norm(x-y) ** 2/(2000)))
    elif algorithm == "cnn":
        # train a neural network
        nn = CNN((128,128,3))
        nn.add_convolution_layer(nodes = 32, size = (3,3))
        nn.add_relu_layer()
        nn.add_pool_layer(shape = (1,1,2))
        nn.add_convolution_layer(nodes = 1, size = (3,3))
        nn.add_fc_output_layer(nodes = 6)
        return nn
    return None 
开发者ID:achintyagopal,项目名称:PaintingToArtists,代码行数:22,代码来源:main.py

示例2: execute

# 需要导入模块: import cnn [as 别名]
# 或者: from cnn import CNN [as 别名]
def execute(planes_hidden, kernel_size, batch_size, has_mask, id_bias,
			rng_seed, eta_list, lmbda, storage_path,
			max_epochs, max_stagnation, wait):
	num_planes = planes_hidden
	if (has_mask):
		num_planes = [3] + num_planes + [1]
	else:
		num_planes = [2] + num_planes + [1]
	neural_net = cnn.CNN(
			num_planes=num_planes,
			kernel_size=kernel_size,
			img_shp=(batch_size, cnn.HEIGHT, cnn.WIDTH),
			has_mask=has_mask,
			id_bias=id_bias,
			rng_seed=rng_seed,
			eta=eta_list[0],
			lmbda=lmbda)

	files = np.load('storage/datapairs_glasses.npz')
	training = files['training']
	validation = files['validation']
	files.close()

	print("\n*** Training network... ***\n")
	trainer.train_nn(
			neural_net=neural_net,
			has_mask=has_mask,
			rng_seed = rng_seed,
			training=training,
			validation=validation,
			decoder=data_organizer.prepare_imagepair,
			storage_path=storage_path,
			max_epochs=max_epochs,
			max_stagnation=max_stagnation,
			eta_list=eta_list[1:],
			wait=wait)
	print("\n*** Stopping criteria met; end of training ***\n") 
开发者ID:JubilantJerry,项目名称:CNN-Glasses-Remover,代码行数:39,代码来源:main.py

示例3: load

# 需要导入模块: import cnn [as 别名]
# 或者: from cnn import CNN [as 别名]
def load(storage_path):
	info_files = np.load(storage_path)
	info = {'arch': info_files['arch'].item(),
			'params': info_files['params'],
			'rng_seed': info_files['rng_seed'].item()}
	info_files.close()
	neural_net = cnn.CNN.load_info(info)
	return CNN_Interface(neural_net) 
开发者ID:JubilantJerry,项目名称:CNN-Glasses-Remover,代码行数:10,代码来源:main.py

示例4: run

# 需要导入模块: import cnn [as 别名]
# 或者: from cnn import CNN [as 别名]
def run():
    (X_train, y_train), (X_test, y_test) = datasets.load_data(img_rows=32, img_cols=32)
    Y_train = np_utils.to_categorical(y_train, nb_classes)
    Y_test = np_utils.to_categorical(y_test, nb_classes)
    model = CNN(input_shape=X_train.shape[1:], nb_classes=nb_classes)
    model.compile(loss='categorical_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
    X_train = preprocess_input(X_train)
    X_test = preprocess_input(X_test)
    csv_logger = CSVLogger('../log/cnn.log')
    checkpointer = ModelCheckpoint(filepath="/tmp/weights.hdf5", monitor="val_acc", verbose=1, save_best_only=True)
    datagen = ImageDataGenerator(
        featurewise_center=False,  # set input mean to 0 over the dataset
        samplewise_center=False,  # set each sample mean to 0
        featurewise_std_normalization=False,  # divide inputs by std of the dataset
        samplewise_std_normalization=False,  # divide each input by its std
        zca_whitening=False,  # apply ZCA whitening
        rotation_range=0,  # randomly rotate images in the range (degrees, 0 to 180)
        width_shift_range=0.1,  # randomly shift images horizontally (fraction of total width)
        height_shift_range=0.1,  # randomly shift images vertically (fraction of total height)
        horizontal_flip=True,  # randomly flip images
        vertical_flip=False)  # randomly flip images
    datagen.fit(X_train)
    model.fit_generator(datagen.flow(X_train, Y_train,
                                     batch_size=batch_size),
                        samples_per_epoch=X_train.shape[0],
                        nb_epoch=nb_epoch,
                        validation_data=(X_test, Y_test), 
                        callbacks=[csv_logger, checkpointer]) 
开发者ID:namakemono,项目名称:keras-anime-face-recognition,代码行数:30,代码来源:train_cnn.py

示例5: __init__

# 需要导入模块: import cnn [as 别名]
# 或者: from cnn import CNN [as 别名]
def __init__(self, sequence_length=0, num_classes=0, vocab_size=0, num_kernels=0, step_size=1e-2, Q=None,
                 FLAGS=None):
        """
        Called when initializing the classifier
        """
        self._estimator_type = "classifier"
        self.Q = tf.constant(Q, dtype=tf.float32, name="input_phi")
        self.sequence_length = sequence_length
        self.num_classes = num_classes
        self.vocab_size = vocab_size
        self.num_kernels = num_kernels
        # Data loading params

        self.FLAGS = FLAGS
        self.FLAGS._parse_flags()

        session_conf = tf.ConfigProto(
            device_count={'GPU': 0},
            allow_soft_placement=self.FLAGS.allow_soft_placement,
            log_device_placement=self.FLAGS.log_device_placement)
        self.sess = tf.Session(config=session_conf)

        self.cnn = CNN(self.Q,
                       sequence_length=sequence_length,
                       num_classes=num_classes,
                       vocab_size=vocab_size,
                       num_kernels=self.num_kernels,
                       embedding_size=self.FLAGS.embedding_dim,
                       filter_sizes=list(map(int, self.FLAGS.filter_sizes.split(","))),
                       num_filters=self.FLAGS.num_filters,
                       l2_reg_lambda=self.FLAGS.l2_reg_lambda)

        # Define Training procedure
        self.optimizer = tf.train.AdagradOptimizer(step_size).minimize(self.cnn.loss)
        self.sess.run(tf.global_variables_initializer()) 
开发者ID:NightmareNyx,项目名称:TextAsGraphClassification,代码行数:37,代码来源:cnn_classifier.py


注:本文中的cnn.CNN属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。