第一个Spark程序

Spark第一个程序开发 wordcount 这里介绍了程序运行在本地模式和Standalone模式两种方式package com.spark.appimport org.apache.spark.{SparkContext, SparkConf}/** * Created by Administrator on 2016/7/24 0024. */ object WordCount { def main(args: Array[S 阅读详情

在本文中,威廉将尝试构建我们的第一个Spark程序,并在之前文章中创建的Spark集群里运行起来

Java程序

对于Java程序来说,使用Maven管理依赖及发布过程中的各个步骤是不错的选择

利用Maven生成Java Project
mvn archetype:generate -DgroupId=com.spark.example -DartifactId=JavaSparkPi

Maven为我们创建了符合标准目录结构的文件

JavaSparkPi
|-src
  |-main
    |-java
      |-com
        |-spark
          |-example
            |-App.java
  |-test
    |-java
      |-com
        |-spark
          |-example
            |-AppTest.java
|-pom.xml

接下来我们将Spark官方实例JavaSparkPi.java作实例,因此用其替换掉生成的App.java,

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.spark.example;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;
import org.apache.spark.api.java.function.Function2;

import java.util.ArrayList;
import java.util.List;

/** 
 * 计算Pi的近似值
 * Usage: JavaSparkPi [slices]
 */
public final class JavaSparkPi {

  public static void main(String[] args) throws Exception {
    # 创建SparkConf对象
    SparkConf sparkConf = new SparkConf().setAppName("JavaSparkPi");
    # 创建JavaSparkContext对象
    JavaSparkContext jsc = new JavaSparkContext(sparkConf);

    int slices = (args.length == 1) ? Integer.parseInt(args[0]) : 2;
    int n = 100000 * slices;
    List<Integer> l = new ArrayList<Integer>(n);
    for (int i = 0; i < n; i++) {
      l.add(i);
    }

    JavaRDD<Integer> dataSet = jsc.parallelize(l, slices);

    int count = dataSet.map(new Function<Integer, Integer>() {
      @Override
      public Integer call(Integer integer) {
        double x = Math.random() * 2 - 1;
        double y = Math.random() * 2 - 1;
        return (x * x + y * y < 1) ? 1 : 0;
      }
    }).reduce(new Function2<Integer, Integer, Integer>() {
      @Override
      public Integer call(Integer integer, Integer integer2) {
        return integer + integer2;
      }
    });

    System.out.println("Pi is roughly " + 4.0 * count / n);

    jsc.stop();
  }
}

此程序实现的功能是计算Pi的近似值,需提供参数slices,默认值为2,slices参数值越大,计算结果的精确度越高,但计算量也就越大

配置pom依赖关系

JavaSparkPi对象引用了org.apache.spark包的对象,因此需要在pom文件中配置依赖关系

编辑JavaSparkPi/pom.xml,在dependencies处加入以下代码

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_2.10</artifactId>
  <version>1.2.0</version>
</dependency>

我们可以通过mvn dependency命令来查看依赖关系

mvn dependency:tree -Ddetail=true
[INFO] com.spark.example:JavaSparkPi:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] \- org.apache.spark:spark-core_2.10:jar:1.2.0:compile
[INFO]    +- com.twitter:chill_2.10:jar:0.5.0:compile
[INFO]    |  \- com.esotericsoftware.kryo:kryo:jar:2.21:compile
[INFO]    |     +- com.esotericsoftware.reflectasm:reflectasm:jar:shaded:1.07:compile
[INFO]    |     +- com.esotericsoftware.minlog:minlog:jar:1.2:compile
[INFO]    |     \- org.objenesis:objenesis:jar:1.2:compile
[INFO]    +- com.twitter:chill-java:jar:0.5.0:compile
[INFO]    +- org.apache.hadoop:hadoop-client:jar:2.2.0:compile
[INFO]    |  +- org.apache.hadoop:hadoop-common:jar:2.2.0:compile
[INFO]    |  |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO]    |  |  +- org.apache.commons:commons-math:jar:2.1:compile
[INFO]    |  |  +- xmlenc:xmlenc:jar:0.52:compile
[INFO]    |  |  +- commons-io:commons-io:jar:2.1:compile
[INFO]    |  |  +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO]    |  |  +- commons-lang:commons-lang:jar:2.5:compile
[INFO]    |  |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO]    |  |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO]    |  |  |  +- commons-digester:commons-digester:jar:1.8:compile
[INFO]    |  |  |  |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO]    |  |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO]    |  |  +- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
[INFO]    |  |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
[INFO]    |  |  +- org.apache.avro:avro:jar:1.7.4:compile
[INFO]    |  |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO]    |  |  +- org.apache.hadoop:hadoop-auth:jar:2.2.0:compile
[INFO]    |  |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO]    |  |     \- org.tukaani:xz:jar:1.0:compile
[INFO]    |  +- org.apache.hadoop:hadoop-hdfs:jar:2.2.0:compile
[INFO]    |  |  \- org.mortbay.jetty:jetty-util:jar:6.1.26:compile
[INFO]    |  +- org.apache.hadoop:hadoop-mapreduce-client-app:jar:2.2.0:compile
[INFO]    |  |  +- org.apache.hadoop:hadoop-mapreduce-client-common:jar:2.2.0:compile
[INFO]    |  |  |  +- org.apache.hadoop:hadoop-yarn-client:jar:2.2.0:compile
[INFO]    |  |  |  |  +- com.google.inject:guice:jar:3.0:compile
[INFO]    |  |  |  |  |  +- javax.inject:javax.inject:jar:1:compile
[INFO]    |  |  |  |  |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO]    |  |  |  |  +- com.sun.jersey.jersey-test-framework:jersey-test-framework-grizzly2:jar:1.9:compile
[INFO]    |  |  |  |  |  +- com.sun.jersey.jersey-test-framework:jersey-test-framework-core:jar:1.9:compile
[INFO]    |  |  |  |  |  |  +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO]    |  |  |  |  |  |  \- com.sun.jersey:jersey-client:jar:1.9:compile
[INFO]    |  |  |  |  |  \- com.sun.jersey:jersey-grizzly2:jar:1.9:compile
[INFO]    |  |  |  |  |     +- org.glassfish.grizzly:grizzly-http:jar:2.1.2:compile
[INFO]    |  |  |  |  |     |  \- org.glassfish.grizzly:grizzly-framework:jar:2.1.2:compile
[INFO]    |  |  |  |  |     |     \- org.glassfish.gmbal:gmbal-api-only:jar:3.0.0-b023:compile
[INFO]    |  |  |  |  |     |        \- org.glassfish.external:management-api:jar:3.0.0-b012:compile
[INFO]    |  |  |  |  |     +- org.glassfish.grizzly:grizzly-http-server:jar:2.1.2:compile
[INFO]    |  |  |  |  |     |  \- org.glassfish.grizzly:grizzly-rcm:jar:2.1.2:compile
[INFO]    |  |  |  |  |     +- org.glassfish.grizzly:grizzly-http-servlet:jar:2.1.2:compile
[INFO]    |  |  |  |  |     \- org.glassfish:javax.servlet:jar:3.1:compile
[INFO]    |  |  |  |  +- com.sun.jersey:jersey-server:jar:1.9:compile
[INFO]    |  |  |  |  |  +- asm:asm:jar:3.1:compile
[INFO]    |  |  |  |  |  \- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO]    |  |  |  |  +- com.sun.jersey:jersey-json:jar:1.9:compile
[INFO]    |  |  |  |  |  +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO]    |  |  |  |  |  |  \- stax:stax-api:jar:1.0.1:compile
[INFO]    |  |  |  |  |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.3-1:compile
[INFO]    |  |  |  |  |  |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO]    |  |  |  |  |  |     \- javax.activation:activation:jar:1.1:compile
[INFO]    |  |  |  |  |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.8.3:compile
[INFO]    |  |  |  |  |  \- org.codehaus.jackson:jackson-xc:jar:1.8.3:compile
[INFO]    |  |  |  |  \- com.sun.jersey.contribs:jersey-guice:jar:1.9:compile
[INFO]    |  |  |  \- org.apache.hadoop:hadoop-yarn-server-common:jar:2.2.0:compile
[INFO]    |  |  \- org.apache.hadoop:hadoop-mapreduce-client-shuffle:jar:2.2.0:compile
[INFO]    |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.2.0:compile
[INFO]    |  +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.2.0:compile
[INFO]    |  |  \- org.apache.hadoop:hadoop-yarn-common:jar:2.2.0:compile
[INFO]    |  +- org.apache.hadoop:hadoop-mapreduce-client-jobclient:jar:2.2.0:compile
[INFO]    |  \- org.apache.hadoop:hadoop-annotations:jar:2.2.0:compile
[INFO]    +- org.apache.spark:spark-network-common_2.10:jar:1.2.0:compile
[INFO]    +- org.apache.spark:spark-network-shuffle_2.10:jar:1.2.0:compile
[INFO]    +- net.java.dev.jets3t:jets3t:jar:0.7.1:compile
[INFO]    |  +- commons-codec:commons-codec:jar:1.3:compile
[INFO]    |  \- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO]    +- org.apache.curator:curator-recipes:jar:2.4.0:compile
[INFO]    |  +- org.apache.curator:curator-framework:jar:2.4.0:compile
[INFO]    |  |  \- org.apache.curator:curator-client:jar:2.4.0:compile
[INFO]    |  +- org.apache.zookeeper:zookeeper:jar:3.4.5:compile
[INFO]    |  |  \- jline:jline:jar:0.9.94:compile
[INFO]    |  \- com.google.guava:guava:jar:14.0.1:compile
[INFO]    +- org.eclipse.jetty:jetty-plus:jar:8.1.14.v20131031:compile
[INFO]    |  +- org.eclipse.jetty.orbit:javax.transaction:jar:1.1.1.v201105210645:compile
[INFO]    |  +- org.eclipse.jetty:jetty-webapp:jar:8.1.14.v20131031:compile
[INFO]    |  |  +- org.eclipse.jetty:jetty-xml:jar:8.1.14.v20131031:compile
[INFO]    |  |  \- org.eclipse.jetty:jetty-servlet:jar:8.1.14.v20131031:compile
[INFO]    |  \- org.eclipse.jetty:jetty-jndi:jar:8.1.14.v20131031:compile
[INFO]    |     \- org.eclipse.jetty.orbit:javax.mail.glassfish:jar:1.4.1.v201005082020:compile
[INFO]    |        \- org.eclipse.jetty.orbit:javax.activation:jar:1.1.0.v201105071233:compile
[INFO]    +- org.eclipse.jetty:jetty-security:jar:8.1.14.v20131031:compile
[INFO]    +- org.eclipse.jetty:jetty-util:jar:8.1.14.v20131031:compile
[INFO]    +- org.eclipse.jetty:jetty-server:jar:8.1.14.v20131031:compile
[INFO]    |  +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:compile
[INFO]    |  +- org.eclipse.jetty:jetty-continuation:jar:8.1.14.v20131031:compile
[INFO]    |  \- org.eclipse.jetty:jetty-http:jar:8.1.14.v20131031:compile
[INFO]    |     \- org.eclipse.jetty:jetty-io:jar:8.1.14.v20131031:compile
[INFO]    +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO]    +- org.apache.commons:commons-math3:jar:3.1.1:compile
[INFO]    +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO]    +- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO]    +- org.slf4j:jul-to-slf4j:jar:1.7.5:compile
[INFO]    +- org.slf4j:jcl-over-slf4j:jar:1.7.5:compile
[INFO]    +- log4j:log4j:jar:1.2.17:compile
[INFO]    +- org.slf4j:slf4j-log4j12:jar:1.7.5:compile
[INFO]    +- com.ning:compress-lzf:jar:1.0.0:compile
[INFO]    +- org.xerial.snappy:snappy-java:jar:1.1.1.6:compile
[INFO]    +- net.jpountz.lz4:lz4:jar:1.2.0:compile
[INFO]    +- org.roaringbitmap:RoaringBitmap:jar:0.4.5:compile
[INFO]    +- commons-net:commons-net:jar:2.2:compile
[INFO]    +- org.spark-project.akka:akka-remote_2.10:jar:2.3.4-spark:compile
[INFO]    |  +- org.spark-project.akka:akka-actor_2.10:jar:2.3.4-spark:compile
[INFO]    |  |  \- com.typesafe:config:jar:1.2.1:compile
[INFO]    |  +- io.netty:netty:jar:3.8.0.Final:compile
[INFO]    |  +- org.spark-project.protobuf:protobuf-java:jar:2.5.0-spark:compile
[INFO]    |  \- org.uncommons.maths:uncommons-maths:jar:1.2.2a:compile
[INFO]    +- org.spark-project.akka:akka-slf4j_2.10:jar:2.3.4-spark:compile
[INFO]    +- org.scala-lang:scala-library:jar:2.10.4:compile
[INFO]    +- org.json4s:json4s-jackson_2.10:jar:3.2.10:compile
[INFO]    |  +- org.json4s:json4s-core_2.10:jar:3.2.10:compile
[INFO]    |  |  +- org.json4s:json4s-ast_2.10:jar:3.2.10:compile
[INFO]    |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.6:compile
[INFO]    |  |  \- org.scala-lang:scalap:jar:2.10.0:compile
[INFO]    |  |     \- org.scala-lang:scala-compiler:jar:2.10.0:compile
[INFO]    |  |        \- org.scala-lang:scala-reflect:jar:2.10.0:compile
[INFO]    |  \- com.fasterxml.jackson.core:jackson-databind:jar:2.3.1:compile
[INFO]    |     +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
[INFO]    |     \- com.fasterxml.jackson.core:jackson-core:jar:2.3.1:compile
[INFO]    +- org.apache.mesos:mesos:jar:shaded-protobuf:0.18.1:compile
[INFO]    +- io.netty:netty-all:jar:4.0.23.Final:compile
[INFO]    +- com.clearspring.analytics:stream:jar:2.7.0:compile
[INFO]    +- com.codahale.metrics:metrics-core:jar:3.0.0:compile
[INFO]    +- com.codahale.metrics:metrics-jvm:jar:3.0.0:compile
[INFO]    +- com.codahale.metrics:metrics-json:jar:3.0.0:compile
[INFO]    +- com.codahale.metrics:metrics-graphite:jar:3.0.0:compile
[INFO]    +- org.tachyonproject:tachyon-client:jar:0.5.0:compile
[INFO]    |  \- org.tachyonproject:tachyon:jar:0.5.0:compile
[INFO]    +- org.spark-project:pyrolite:jar:2.0.1:compile
[INFO]    +- net.sf.py4j:py4j:jar:0.8.2.1:compile
[INFO]    \- org.spark-project.spark:unused:jar:1.0.0:compile
配置maven-shade-plugin

默认情况下,Maven在本地有名为.m2的仓库文件夹,用于存放所有依赖的jar包,因此在package操作时只会打包依赖的jar包的名称,而不会将真正的内容打包进去

而当在集群中运行程序的时候,情况就有所不同了,我们很难保证所依赖的jar包在所有worker主机上都存在,因此需要生成一个大jar包(uber JAR/assembly JAR),其中包含所有的依赖内容

我们可以通过maven-shade-plugin插件来实现,在pom中加入以下内容:

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <version>2.3</version>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
        </execution>
      </executions>
    </plugin>
  </plugins>
</build>
Maven生成JAR包
mvn clean compile package

成功运行后,我们看到在JavaSparkPi/target文件夹下生成了JavaSparkPi-1.0-SNAPSHOT.jar文件,大小为76M,可见所有的依赖jar包都被包含了进来

此处威廉只是演示如何生成uber JAR,其实spark-core的jar是所有集群主机都肯定拥有的,因此我们不需要把它加入到打包生成的jar包中

修改JavaSparkPi/pom.xml,把spark-core依赖的scope设为provided

<dependency>
  <groupId>org.apache.spark</groupId>
  <artifactId>spark-core_2.10</artifactId>
  <version>1.2.0</version>
  <scope>provided</scope>
</dependency>

再次运行mvn clean compile package,可以看到这次的JavaSparkPi-1.0-SNAPSHOT.jar大小仅为5K,不再包含spark-core相关的依赖jar

向Spark集群提交程序
./bin/spark-submit --class com.spark.example.JavaSparkPi --master spark://192.168.32.130:7077 $HOME/JavaSparkPi/target/JavaSparkPi-1.0-SNAPSHOT.jar 1000

Python程序

Python是脚本语言,部署相对简单,不需要编译的步骤,仍然以计算Pi近似值的示例程序为例

./bin/spark-submit \
  --master spark://192.168.32.130:7077 \
  examples/src/main/python/pi.py \
  1000

引用的.zip, .egg, .py文件可以通过--py-files参数来添加

第一个Spark On Yarn程序 环境 hadoop 2.2.0 + Scala 2.10.3 + Spark 0.9 + Idea 13 单机伪分布式的Yarn Idea SBT插件使用:建立SBT项目,然后在Setting中设置SBT autoimport 和 auto 创建目录结构 build.sbt name := "WordCount" version := "1.0" scalaVersion : 阅读详情

相关推荐

Spark快速入门与实战案例解析

在当今的大数据时代,数据处理速度与效率成为了竞争的关键。作为一款开源的分布式计算框架,Apache Spark 以其高效的内存计算和简洁的编程模型,迅速成为数据工程师和科学家们的必备工具。无论是批量数据处理,还是实时数据流分析,Spark 都可以游刃有余地胜任。本篇文章将围绕【Spark 快速入门】展开,通过从基础原理到案例实操的方式,帮助大家快速理解 Spark 的核心概念与应用场景。同时,文章将深入拓展 Spark 相关知识,帮助读者加深理解。

喵手的博客 3503

Intellij IDEA编写Spark应用程序的环境配置和操作步骤

在win系统中使用IDEA开发spark应用程序,并将其打成jar包上传到虚拟机中的三个Ubuntu系统,然后在分布式环境中运行

Where runes of code shape the picture :) 7237

Spark运行第一个Scala程序WordCount

1、前置条件安装 hadoop:https://blog.youkuaiyun.com/jxq0816/article/details/78736449 scala:https://www.runoob.com/scala/scala-install.html2、Idea安装Scala插件 3、代码 object ScalaWordCount { def main(args: Array[St...

2959

Spark系列从入门到精通(二)

Spark 框架的核心是一个计算引擎,整体来说,它采用了标准 master-slave 的结构。 如下图所示,它展示了一个 Spark 执行时的基本结构。

prefect_start的博客 998

编译CycloneDDS和CycloneDDS-CXX踩过的坑——CMake Error at CMakeLists.txt:227 (find_package):

最近编译CycloneDDS和CycloneDDS-CXX踩了两个坑,花了不少时间。做个简单的记录,免得以后又踩到。注意:CycloneDDS-CXX编译依赖CycloneDDS,因此必须先编译CycloneDDS需要严格按照步骤进行,否则要入坑步骤如下,1先编译CycloneDDS以上步骤完成CycloneDDS的编译和安装,生成的bin include lib等位于install目录下面。

usstmiracle的博客 1900

航空大数据——项目资源汇总及开源(四)

ADS-B项目开源大礼包

cyc头发还挺多的博客 4983

Spark(三)第一个Spark程序

学习过程我们先不去关注Spark的运行环境和部署方式,只要起来了能用,咱就开始先用着,如果一开始就深入研究里面的运行原理,会发现根本出不来了,所以我们先动手实现程序,在过程中慢慢去理解里面的执行原理。 首先我们先去百度看下,要怎么写自己的第一个程序呢?我们可以选择Python,Java,Scala。不过多数推荐Scala,Java现在也能写,但是我稍微去查了些资料,看见Java编写的技术文档不多,很多都是Scala的技术文档和问题解决。所以需要准备下面的东西: 开发环境:IDEA。 Spark版本:spar

lwgzj的博客 1013

Spark入门学习和调优

Spark运行原理自我理解: (1)首先程序有RDD Objects分解为DAG有向无环图 (2)提交DAGScheduler,根据shuffer将DAG分解为一组taskset,即stages (3)Taskset提交TaskScheduler,每个taskset在分解为多个task,即一个task就是一个split分区 (4)T...

purisuit_knowledge的专栏 5818

Neo4j桌面版导入CVS文件

我们的relation.csv是这样的。

m0_53573725的博客 818

SDR实战(四)-AD9361使用手册(三)

本节定义了并行数据端口和串行外设接口(SPI),它们使得AD9361与基带处理器(BBP)之间能够传输数据和控制/状态信息。图63展示了这些接口,并提供了AD9361和BBP在宽带无线系统中使用方式的高级概述。数据接口以两种模式之一运行:兼容标准CMOS模式或兼容低压差分信号(LVDS)模式。每个接口都具有以下部分描述的独特特性。使用CMOS模式时:保持了单端-CMOS逻辑兼容性。可以使用一个或两个数据端口。使用两个端口可以提高数据吞吐量。

hutx0924的博客 6245

Spark安装及IDEA第一个Spark程序

Spark安装及IDEA第一个Spark程序Spark安装Linux下安装解压改名修改conf下配置文件配置系统环境变量启动测试Windows下安装系统变量配置Path变量配置创建IDEA程序 Spark安装 Linux下安装 解压 tar -zxvf spark-3.1.2-bin-hadoop3.2.tgz -C /opt/software/ 改名 mv spark-3.1.2-bin-hadoop3.2/ spark312 修改conf下配置文件 #释放配置文件 cp spark-env.sh.t

Wan的博客 674

YOLOv11改进 - C3k2融合 | C3k2 融合 ARConv 自适应矩形卷积:动态调整卷积核形状与采样点

本文介绍了将自适应矩形卷积(ARConv)模块与YOLOv11相结合的方法。ARConv是针对遥感图像全色锐化任务设计的创新卷积模块,可自适应调整卷积核形状与采样点数量,解决传统卷积刚性限制,实现高效特征提取。其工作流程包括学习卷积核高度和宽度、选择采样点数量、生成采样图、卷积实现与空间自适应增强。我们将集成ARConv的C3k2_ARConv模块引入YOLOv11,对相关代码进行修改和注册,并配置了yolov11 - C3k2_ARConv.yaml文件。实验脚本显示,该结合方式应用于目标检测任务。

魔改工程师的博客 1005

体验第一个spark程序(第四弹)

先启动spark集群或者启动hdfs集群,如果之前有开启,则需要重新关闭再开启spark集群或者启动hdfs集群。以客户端模式连接Yarn集群,集群的位置可以在HADOOP_CONF_DIR环境变量中配置。以集群模式连接Yarn集群,集群的位置可以在HADOOP_CONF_DIR环境变量中配置。在standalone模式下,连接到指定spark集群,默认端口号是7077。在spark目录下启动spark服务(未停止的,先停止在启动)启动Hadoop服务(未停止的,先停止在启动)遇到不能创建问题是因为。...

m0_57781407的博客 2025

fasterlio原理及代码框架梳理

Faster-LIO 的优势是在保持同等高精度的前提下,显著提升计算效率,以支持更极端的应用场景(如高速无人机)和更廉价的硬件平台。可以把 Faster-LIO 理解为用一把更快的“空间哈希筛子”(iVox)替换了原来精细的“动态平衡树”(ikd-Tree),从而在精度损失极小的情况下,实现了效率的显著提升。:只在实际有地图点的空间区域动态创建和保留体素单元,形成一个稀疏的体素地图。是关键:将去畸变点云中的每个点,在 iVox 维护的局部地图中搜索近邻(如5个最近点),构建点到面的距离残差。

Studying…… 246

安卓手机部署酒馆 SillyTavern 全攻略(Termux 本地安装教程)

本文详细介绍了如何在安卓手机上通过 Termux 环境本地部署 SillyTavern,一个功能丰富的角色扮演对话 AI。步骤包括安装 Termux、Git,克隆 SillyTavern 仓库,安装 Node.js 和依赖,启动 SillyTavern,以及可选的高阶玩法——安装 TAI-Extras 扩展模块。文章还提供了常见问题的解决方案和优化技巧,如更新 SillyTavern、处理报错、文件访问、添加快捷命令和禁用安卓后台进程杀死。通过本教程,用户可以在安卓手机上体验本地部署的 AI 对话,享受更高

代码简单说 Vue、JAVA、PHP、Node.js 熟练运用,接口、架构、性能全搞定。 1万+

安装并运行第一个Spark程序

安装并运行第一个Spark程序需要完成以下步骤:安装Java和Spark,配置环境变量,编写并运行Spark程序。

2301_81908848的博客 734

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

第一个spark程序

weixin_37855495的博客 211

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

SparkCore:SparkContext/spark-shell详解,IDEA构建第一个Spark程序

文章目录1、SparkContext详解2、IDEA构建Spark应用程序2.1 安装JDK1.8和Maven3.6.12.2 打开IDEA新建Project2.3 修改pom.xml文件2.3 开发第一个Spark应用程序WordCount3、spark-shell详解 1、SparkContext详解 打开官网: 查看对应版本详细spark信息入口 Documentation -->ol...

11号车厢 968

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

Spark学习笔记(三)-开始第一个spark程序

Spark学习笔记-开始第一个spark程序  在安装完Spark,其实最疑惑还是Spark怎么用的问题,由于也是刚学习linux,也不是很习惯linux下的命令行操作。按照Spark的官方文档,我们开始编写Spark的的第一个程序。一、标准进入spark方式  很多人在安装完spark后就懵了,本人也是一样。毕竟spark在linux下没有什么桌面图标这种明显的东西。要启动Spark,我们先要进入

log_zhan的博客 4409

Spark第一个程序

spark中运行项目有两种方式 在spark-shell中导入依赖,编写代码,执行 和在idea中写好应用,使用spark-submit方式提交到spark运行 Spark-Shell 打开spark-shell 输入程序,读取文件data.txt里面的内容: val lines = sc.textFile("/Users/jeremy/Documents/data.txt") lines.first() lines.count() 先看下文件里面的内容: 结果.

yjt1325的博客 250

开发第一个Spark程序

                                           WorldCount程序一、需求:对文本文件中的单词个数进行统计二、步骤:         1.创建一个Spark Context         2. 加载数据         3.把没一行分割成单词        4.转换成键值对并且计数。三、开发环境       IDEA+Maven, scala开发语言 ...

fengfengchen95的博客 6627

IDEA 写第一个Spark程序

下载成功!!! 重新启动。 重启之后: 点击Create 如果报错,看 此博客主 : https://blog.youkuaiyun.com/huanghanqian/article/details/80413478 报错: Plugin Scala was not installed: Cannot download 'https://plugins.jetbrains.com/plugi...

魚 484

Spark认识&环境搭建&运行第一个Spark程序

摘要:Spark作为新一代大数据计算引擎,因为内存计算的特性,具有比hadoop更快的计算速度。这里总结下对Spark的认识、虚拟机Spark安装、Spark开发环境搭建及编写第一个scala程序、运行第一个Spark程序。 1.Spark是什么 Spark是一个快速且通用的集群计算平台 2.Spark的特点 1)Spark是快速的 Spark扩充了流行的Mapreduce计算模型...

weixin_30823227的博客 87
上一篇: Spark任务运行详解
下一篇: SSH证书连接配置DEBUG步骤
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值