我有一个Python项目,该项目使用名为UPDATE cities t1, WEBMASTERCOPY t2
SET t1.zip = t2.zip
WHERE t1.city = t2.city AND t1.state = t2.state AND t1.zip IS NULL
的命令行命令中的工具/程序。
如何确保用户拥有我在计算机上使用的所有工具?
我是否必须包含一个自述文件,说明您需要以下工具才能正常运行该程序,或者我是否可以使用某种功能或模块来自动安装缺少的功能?
哦,我是Python的新手,所以也许我只是不了解pip的工作原理。我可以只使用os.system(“ pip install something”)吗?如果我不想特定于平台怎么办?
答案 0 :(得分:4)
约定包括import scipy.io as sio
import numpy as np
import os
import pandas
import pickle
import random
import keras
from keras.models import Sequential, Model
from keras.layers import Conv2D, MaxPool2D, GlobalAveragePooling2D
from keras.layers import Dense, Dropout, Flatten, Activation
from keras.utils import np_utils
from keras.applications.resnet50 import ResNet50
from keras.preprocessing import image
from keras.applications.resnet50 import preprocess_input, decode_predictions
from keras.backend import tf as ktf
import h5py
with open('categs/database.pickle', 'rb') as f:
a=pickle.load(f)
def generate_data(a, batch_size):
while True:
key=random.choice(list(a.keys()))
# X_train= np.load(key+'.npy')
with open('categs/'+key+'.pickle', 'rb') as labels, h5py.File('datafile.hdf5', mode='r') as f:
X_train= np.asarray(f[key])
Y_train=pickle.load(labels)
X_train1=np.zeros((X_train.shape[0], X_train.shape[1], X_train.shape[2],3))
for i in range(1,X_train.shape[0]-1):
X_train1[i,:,:,1]=X_train[i,:,:,0]
X_train1[i,:,:,0]=X_train[i-1, :, :, 0]
X_train1[i, :, :,2]=X_train[i+1, :, :, 0]
X_train=X_train1
X_train1=[]
Y_train=np_utils.to_categorical(Y_train)
yield X_train, Y_train
base_model=ResNet50(include_top=False, weights='imagenet', input_tensor=None, input_shape=(512,512,3), pooling=None)
x=base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(1024, activation='relu')(x)
predictions = Dense(7, activation='softmax')(x)
model = Model(inputs=base_model.input, outputs=predictions)
for layer in base_model.layers:
layer.trainable = False
model.compile(loss='categorical_crossentropy',
optimizer='adam',
metrics=['accuracy'])
model.fit_generator(generator=generate_data(a, batch_size=1), steps_per_epoch=1, epochs=250,workers=6)
,其中包含有关需要安装哪些软件包的信息。您可以阅读更多at the official documentation for pip。
但是,由于手动生成可能很麻烦,因此pipreqs之类的工具可以检查您的项目并通过将您的导入内容与通过官方点子存储库找到的导入内容进行比较来为您生成一个requirements.txt
文件
一旦生成requirements.txt
文件,就可以通过以下方式安装:requirements.txt
。