我的构建服务器是基于Linux的。我需要protoc将它集成到我的基于ant的构建系统中。
我在build.xml中使用以下内容:
<exec executable="tools/protoc.exe" failonerror="true">
<arg value="--java_out=../protos/java/generated" />
<arg value="--proto_path=../protos/proto" />
<arg value="../protos/proto/*.proto" />
</exec>
我找到了windows二进制文件,但是找不到用于protoc的linux二进制文件。
任何帮助找到一个或构建静态链接的protoc二进制文件都会很好。
答案 0 :(得分:6)
您是否尝试过下载main protobuf project并关注installation instructions?我似乎记得,如果你只需要二进制文件,它就非常简单:
$ ./autogen.sh
$ ./configure
$ make
(在这种情况下,您可能不需要make install
,如果您只需要protoc
二进制文件。只需找出它的构建位置并复制它。)
答案 1 :(得分:3)
最新版本的预编译二进制文件位于GitHub上的官方releases page。可以在Maven repository上找到以前的版本。
答案 2 :(得分:1)
对于java,您还可以使用已包含不同平台的二进制文件的https://github.com/os72/protoc-jar。
答案 3 :(得分:1)
在Ubuntu上(从12.04开始),您可以在存储库中找到protobuf-compiler
。
sudo apt-get install protobuf-compiler
$> protoc --version
libprotoc 2.6.1
您可能还想安装头文件:
sudo aptitude install libprotobuf-dev
答案 4 :(得分:0)
如果您只想为任何平台编译import tensorflow as tf
import tensorflow_probability as tfp
import matplotlib.pyplot as plt
import numpy as np
mnist = tf.keras.datasets.mnist
tfe = tf.contrib.eager
ed = tfp.edward2
tf.reset_default_graph()
tf.enable_eager_execution()
(x_train, y_train), (x_test, y_test) = mnist.load_data()
pix_w = 28
pix_h = 28
def vis_pix(image):
plt.imshow(image, cmap='Greys')
plt.show()
def scale(x, min_val=0.0, max_val=255.0):
x = tf.cast(x, tf.float32)
return tf.div(tf.subtract(x, min_val), tf.subtract(max_val, min_val))
def create_dataset(x, y):
dataset = tf.data.Dataset.from_tensor_slices((x_train, y_train))
dataset = dataset.map(lambda x, y: (scale(x), tf.one_hot(y, 10)))
dataset = dataset.map(lambda x, y: (tf.reshape(x, [pix_w * pix_h]), y))
dataset = dataset.shuffle(10000).batch(30)
return dataset
train_ds = create_dataset(x_train, y_train)
model = tf.keras.Sequential([
tfp.layers.DenseFlipout(10)
])
optimizer = tf.train.AdamOptimizer()
def loss_fn(model, x, y):
logits = model(x)
neg_log_likelihood = tf.nn.softmax_cross_entropy_with_logits(labels=y,
logits=logits)
kl = sum(model.losses)
elbow_loss = neg_log_likelihood + kl
return elbow_loss
def get_accuracy(model, x, y):
logits = model(x)
yhat = tf.argmax(logits, 1)
is_correct = tf.equal(yhat, tf.argmax(y, 1))
accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))
return accuracy
epochs = 1000
for (batch, (x, y)) in enumerate(train_ds):
optimizer.minimize(lambda: loss_fn(model, x, y),
global_step=tf.train.get_or_create_global_step())
if batch % 10 == 0:
acc = get_accuracy(model, x, y).numpy() * 100
loss = loss_fn(model, x, y).numpy().mean()
print("Iteration {}, loss: {:.3f}, train accuracy:
{:.2f}%".format(batch, loss, acc))
if batch > epochs:
break
个二进制文件,请按照以下步骤操作:
在protobuf项目目录下
/**
*
*
*/
public class Diamond {
public static void main(String[] args) {
int diamondHeight = 18;
int diamondWidth = 21;
String header = "";
header = makeDiamondTemplate(diamondWidth, '+', '-', '-', '-');
System.out.println(header);
makeUpperHalf(diamondHeight / 2, diamondWidth);
makeLowerHalf(diamondHeight / 2, diamondWidth);
System.out.println(header);
makeLowerHalf(diamondHeight / 2, diamondWidth);
makeUpperHalf(diamondHeight / 2, diamondWidth);
System.out.println(header);
}
public static String makeDiamondTemplate(int diamondWidth, char border, char mid, char fillerLeft,
char fillerRight) {
String result = "" + border;
int midIndex = diamondWidth / 2;
for (int i = 1; i < diamondWidth - 1; i++) {
if (midIndex == i) {
result = result + mid;
} else if (i < midIndex) {
result = result + fillerLeft;
} else if (i > midIndex) {
result = result + fillerRight;
}
}
result = result + border;
return result;
}
public static void makeUpperHalf(int diamondHeight, int diamondWidth) {
StringBuilder template = new StringBuilder(makeDiamondTemplate(diamondWidth, '|', '*', ' ', ' '));
int starIndex = diamondWidth / 2;
System.out.println(template);
for (int i = 1; i < diamondHeight; i++) {
template.setCharAt(starIndex - i, '/');
template.setCharAt(starIndex + i, '\\');
System.out.println(template);
}
}
public static void makeLowerHalf(int diamondHeight, int diamondWidth) {
StringBuilder template = new StringBuilder(makeDiamondTemplate(diamondWidth, '|', '*', '\\', '/'));
int starIndex = diamondWidth / 2;
int replaceStart = starIndex - 2;
if (template.length() > 1) {
template.setCharAt(1, ' ');
template.setCharAt(template.length() - 2, ' ');
}
System.out.println(template);
for (int i = 1; i < diamondHeight; i++) {
template.setCharAt(starIndex - replaceStart, ' ');
template.setCharAt(starIndex + replaceStart, ' ');
replaceStart--;
System.out.println(template);
}
}
}
protoc
内置于./autogen.sh
cd protoc-artifacts
./build-protoc.sh linux x86_64 protoc
中
将其重命名为protoc.exe
protobuf/protoc-artifacts/target/linux/x86_64/protoc
答案 5 :(得分:0)
1)从网址https://github.com/protocolbuffers/protobuf/releases
下载二进制文件 2)提取目录并将其保留在特定位置(/user/app/protoc
)
3)在/usr//.bash_profile中将条目添加为
export PROTOC_HOME=/user/app/protoc
export PATH=$PROTOC_HOME/bin:$PATH
4)刷新文件$source /usr/<username>/.bash_profile
下载存储库后,其他选项将逐个运行以下命令:
sudo rm -rf ./protoc
unzip protoc-3.10.1-linux-x86_64.zip -d protoc
chmod 755 -R protoc
BASE=/usr/local
sudo rm -rf $BASE/include/google/protobuf/
sudo cp protoc/bin/protoc $BASE/bin
sudo cp -R protoc/include/* $BASE/include