コード例 #1
0
                                           n_state_space=N_STATE_SPACE, base_impacts=BASE_IMPACTS, agg_weeks=4, save_calc=False)

            print('--------------------------------    ' + str(device) + '    --------------------------------')
            if device == 'cuda':
                print(torch.cuda.get_device_name(0))

            # initialize agents and network optimizers and store them in dicts
            optimizers, all_agents = init_agents(ACTION_SPACE, N_STATE_SPACE, REQUIRED_NEURAL_NETS, ACT_AGT, LEARNING_RATE, device)

            # save initial agents
            torch.save(all_agents, (SAVE_DIR / 'agents_init'), _use_new_zipfile_serialization=False)

            # initialise loop variables
            total_rewards = {'FSC': [], 'Shell': []}
            batch_returns = {'FSC': [], 'Shell': []}
            batch_actions = create_dict(REQUIRED_NEURAL_NETS, ACT_AGT)
            batch_states = {'FSC':   np.empty([BATCH_SIZE, LENGTH_EPISODE, N_STATE_SPACE['FSC']]),
                            'Shell': np.empty([BATCH_SIZE, LENGTH_EPISODE, N_STATE_SPACE['Shell']]),
                            'Gov':   np.empty([BATCH_SIZE, LENGTH_EPISODE, N_STATE_SPACE['Gov']])}
            batch_rewards = {'FSC': np.empty([BATCH_SIZE, LENGTH_EPISODE, 1]),
                             'Shell': np.empty([BATCH_SIZE, LENGTH_EPISODE, 1])}
            support_calc = {'Shell': np.empty([BATCH_SIZE, LENGTH_EPISODE, len(AGENTS) + 1]),
                            'Gov':   np.empty([BATCH_SIZE, LENGTH_EPISODE, len(AGENTS) + 1])}
            reward_shell_calc = np.empty([BATCH_SIZE, LENGTH_EPISODE, 4])
            batch_count = 0
            optim_count = 0
            step_count = 0
            ep = 0
            times = []
            # loop over all episodes (= rollouts)
            while ep < NUM_EPISODES:
コード例 #2
0
ファイル: app.py プロジェクト: Ash3156/krishi
import functions as f
import deployed

app = Flask(__name__)
app.config['MAX_CONTENT_LENGTH'] = 8192 * 8192
app.config['UPLOAD_EXTENSIONS'] = ['.jpg', '.png']
app.config['UPLOAD_PATH'] = 'static/uploads'
app.config['IMAGE_PATH'] = 'static/images'

# code to download and store all images; no longer necessary after run for first time
# since we've now saved all images in the repository and pushed to github
# f.download_images(f.create_dict('static/image_links.csv')[0], "static/images/")

# code to load all necessary info for each plant disease
link_dict=f.create_link_dict("static/info_links.csv")
plant_disease_dict, diseases = f.create_dict('static/disease_info.csv')

# results=['Potato Late Blight', 'Tomato Leaf Mold', 'Tomato Late Blight', 'Peach Healthy']


@app.route('/')
def index():
    return render_template('index.html')

@app.route('/display')
def display():
    files = os.listdir(app.config['UPLOAD_PATH'])
    results=[]
    for file in files:
        results.append(diseases[deployed.predict_new(os.path.join(app.config['UPLOAD_PATH'], file))])
    return render_template('display.html', files=files, pd_dict=plant_disease_dict, results=results, num=len(files), link_dict=link_dict)
コード例 #3
0
 def test_pickle_dict(self):
     functions.create_dict('test_dict')
     files = listdir(path.dirname(path.abspath(__file__)))
     self.assertIn('test_dict', files)