def show_board(_boards, _pboards=None, show_float=False): shstr = [' ', ' │ ', '─┘ ', ' └─', '─┐ ', ' ┌─', '───'] idx = 0 for z in range(board_z): print 'LAYER {}'.format(z + 1) for y in range(n_dims_half, board_y + n_dims_half): for x in range(n_dims_half, board_x + n_dims_half): # ビアを赤色で表示 if _pboards is not None and _boards[z][y][x]['type'] == 1 and _pboards[z][y][x]['type'] == 'via': sys.stdout.write('\033[1;31;47m {} \033[0m'.format(nl.int2str(_boards[z][y][x]['data'], 36))) elif _boards[z][y][x]['type'] == 1: sys.stdout.write('\033[1;30;47m {} \033[0m'.format(nl.int2str(_boards[z][y][x]['data'], 36))) else: # 正しい配線形状 fr_color = '30' # 途切れてないセル / 途切れてるセル bg_color = '47' if show_float: if _boards[z][y][x]['float'] != None: bg_color = '43' sys.stdout.write('\033[1;{};{}m{}\033[0m'.format(fr_color, bg_color, shstr[_boards[z][y][x]['shape']])) idx = idx + 1 print ''
def show_board(_board, show_float=False): shstr = [' ', ' │ ', '─┘ ', ' └─', '─┐ ', ' ┌─', '───'] idx = 0 for y in range(n_dims_half, board_y + n_dims_half): for x in range(n_dims_half, board_x + n_dims_half): if _board[y][x]['type'] == 1: sys.stdout.write('\033[1;30;47m {} \033[0m'.format(nl.int2str(_board[y][x]['data'], 36))) else: # 正しい配線形状 fr_color = '30' # 途切れてないセル / 途切れてるセル bg_color = '47' if show_float: if _board[y][x]['float'] != None: bg_color = '43' sys.stdout.write('\033[1;{};{}m{}\033[0m'.format(fr_color, bg_color, shstr[_board[y][x]['shape']])) idx = idx + 1 print ''
loss_test, accuracy_test, result = forward(x_test, y_test, train=False) # 訓練データ/テストデータの誤差と、正解精度を表示 if epoch % 100 == 0: print 'epoch', epoch print 'Train: mean loss={}, accuracy={}'.format(sum_loss / n_train, sum_accuracy / n_train) if testfilename != 'none': print 'Test: mean loss={}, accuracy={}'.format(loss_test.data, accuracy_test.data) # テストデータの配線を表示 idx = 0 str = [' ', ' │ ', '─┘ ', ' └─', '─┐ ', ' ┌─', '───'] for y in range(n_dims_half, board_y + n_dims_half): for x in range(n_dims_half, board_x + n_dims_half): if board[y][x]['type'] == 1: sys.stdout.write('\033[1;30;47m ' + nl.int2str(board[y][x]['data'], 36) + ' \033[0m') else: ex_shape = np.argmax(result.data[idx]) # 正しい配線形状 if (not args.show_wrong) or board[y][x]['shape'] == ex_shape: sys.stdout.write('\033[1;30;47m' + str[ex_shape] + '\033[0m') # 間違ってる配線形状 else: sys.stdout.write('\033[1;31;47m' + str[ex_shape] + '\033[0m') idx = idx + 1 print '' # モデルをシリアライズ化して保存 with open(DIR_DUMP + '/s{}_u{}_e{}_d{}_t{}.pkl'.format(n_dims, n_units, n_epoch, args.dataset, testfilename_short), 'w') as f: pickle.dump(model, f)