コード例 #1
0
def scp( source, target, debug=False ):
	from fs import exists, isdir
	from subprocess import Popen
	from shlex import split

	cmd = ['scp', '-Cpr', source, target.replace(' ', '\ ')]
	if debug:
		print ' '.join(cmd)
	Popen(cmd).wait()

	success = exists(source) and exists(target)
	if debug:
		print 'Success: '+str(success)

	return success
コード例 #2
0
def export_neglected_file_list(monitoring_dir, ROOT_DIR, LOG_DIR, backup_file_list):
    today_obj = datetime.datetime.today()
    today_str = str(today_obj.year)+str(today_obj.month)+str(today_obj.day)
    export_name = today_str + "_neglected_files.log"
    export_path = fs.join([ROOT_DIR, LOG_DIR, export_name])
    if not fs.exists(fs.join([ROOT_DIR, LOG_DIR])):
        try:
            fs.mkdir(fs.join([ROOT_DIR, LOG_DIR]))
        except:
            print ("Can't create LOG_DIR in Func:", export_neglected_file_list)
    try:
        fs.touch(export_path)
        file = fs.open(export_path, 'w')
        for f in backup_file_list:
            try:
                file.write('================================================')
                file.write('\n')
                file.write(fs.filename(f))
                file.write('\n')
                file.write(fs.dirname(f))
                file.write('\n')
            except:
                print("Cant' write export file in func: export_neglected_file_list")
    except:
        print ("cant export in func: export_neglected_file_list")
コード例 #3
0
    async def unmute(self,
                     ctx,
                     member: discord.Member,
                     *,
                     reason: str = "No reason given."):
        """Unmutes an user inside of the guild.

        Parameters:
          member - The member to unmute. Can be named, mentioned or ID'd.
          reason - The reason. This is optional, but recommended."""
        muterole = discord.utils.get(ctx.guild.roles, id=447154216985690112)
        await member.remove_roles(muterole, reason=reason)
        await esay(
            ctx,
            discord.Embed(
                title="User unmuted!",
                description=f"{member} has been successfully unmuted.",
                color=0xFF8800))
        embed_unmute = discord.Embed(
            title="Admin Log: User unmuted",
            description="An user has been unmuted inside of this guild.",
            color=0xFF8800)
        embed_unmute.add_field(name="Admin", value=ctx.author)
        embed_unmute.add_field(name="Unmuted User", value=member)
        embed_unmute.add_field(name="Reason", value=reason)
        if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
            with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt", "r") as file:
                chID = file.read()
            logch = self.bot.get_channel(int(chID))
        else:
            logch = ctx
        await esay(logch, embed_unmute)
コード例 #4
0
    async def ban(self, ctx, member: discord.Member, *, reason: str = None):
        """Bans an user from the current guild.

        Parameters:
          member - The user to ban. The user can be mentioned, named or ID'ed.
          reason - (Optional) The reason for the ban. You can leave this empty. The reason will be shown inside of the audit log.

        Permissions:
          Ban/Unban members"""
        await member.ban(reason=f"Banned by {ctx.author}: {reason}")
        await esay(
            ctx,
            discord.Embed(
                title=f"Banned member {member}",
                description=
                f"Member {member} has been successfully banned from this guild!",
                color=0xFF0000))
        embed_ban = discord.Embed(
            title="Admin log: Member ban",
            description="A ban has been issued inside of this server.",
            color=0xFF0000)
        embed_ban.add_field(name="Admin", value=ctx.author)
        embed_ban.add_field(name="Banned member", value=member)
        embed_ban.add_field(name="Reason", value=reason, inline=False)
        if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
            with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt", "r") as file:
                chID = file.read()
            logch = self.bot.get_channel(int(chID))
        else:
            logch = ctx
        await logch.send(embed=embed_ban)
コード例 #5
0
    async def pardon(self, ctx, memID: int, *, reason: str = None):
        """Unbans a banned user from the current guild.

        Parameters:
          memID - The ID of the member to be unbanned. You can either find it yourself or use *DD!banlist* to get it.
          reason - (Optional) The reason for the unban. You can leave this empty. The reason will be shown inside of the audit log.

        Permissions:
          Ban/Unban members"""
        memObj = self.bot.get_user_info(user_id=int(memID))
        await memObj.unban(reason=f"Unbanned by {ctx.author}: {reason}")
        await esay(
            ctx,
            discord.Embed(
                title=f"Unbanned member {memObj.name}",
                description=
                f"Member {memObj.name} has been successfully unbanned from this guild!",
                color=0x00FF00))
        embed_unban = discord.Embed(
            title="Admin log: Member unban",
            description="An unban has been issued inside of this server.",
            color=0x00FF00)
        embed_unban.add_field(name="Admin", value=ctx.author)
        embed_unban.add_field(name="Unbanned member", value=memObj)
        embed_unban.add_field(name="Reason", value=reason, inline=False)
        if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
            with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt", "r") as file:
                chID = file.read()
            logch = self.bot.get_channel(int(chID))
        else:
            logch = ctx
        logch.send(embed=embed_unban)
コード例 #6
0
def create_new_backup_root_dir(ROOT_DIR, TARGET_ROOT_DIR, backup_dir_name):
    backup_dir_path = fs.join([ROOT_DIR, TARGET_ROOT_DIR, backup_dir_name])
    if not fs.exists(backup_dir_path):
        try:
            fs.mkdir(backup_dir_path)
            print (backup_dir_path, "was successfully created")
        except:
            print ("Cant create a backup directory in func: create_new_backup_root_dir")
コード例 #7
0
def test__when_deleting_file__should_remove_file_from_fs():
    fs = MemoryFS()
    fs.create(SOURCE)

    sut = _TestFilesystemImpl(fs)

    sut.delete(SOURCE)

    assert not fs.exists(SOURCE)
コード例 #8
0
def main():

  if not fs.exists(DATA_DST):
    fs.mkdir(DATA_DST)

  meta_all = utils.shuffle_meta_data(utils.load_meta_data(DATA_SRC, WIKI_META_OBJ, IMDB_META_OBJ))

  train, test = utils.split_meta_data(meta_all, TRAIN_TEST_SPLIT)
  train, val = utils.split_meta_data(train, TRAIN_VAL_SPLIT)

  # Free the memory
  del meta_all
  gc.collect()

  print("Converting blocks")

  print(" [train] %i Sapmles. %i Blocks required" % (len(train['path']), math.ceil(len(train['path']) / SAMPLES_PER_SPLIT)))

  for i in range(math.ceil(len(train['path']) / SAMPLES_PER_SPLIT)):
    X_train, y_age, y_gender = utils.get_img_array(train, DATA_SRC, age_classes, img_dim=INPUT_DIM, split=i, num_samples_per_split=SAMPLES_PER_SPLIT)
    np.save(fs.add_suffix(fs.join(DATA_DST, TRAIN_DATA_OBJ), '_%02d' % i), X_train)
    np.save(fs.add_suffix(fs.join(DATA_DST, TRAIN_DATA_OBJ), '_label_age_%02d' % i), y_age)
    np.save(fs.add_suffix(fs.join(DATA_DST, TRAIN_DATA_OBJ), '_label_gender_%02d' % i), y_gender)
    
    # Remove the array from memory
    del X_train
    del y_age
    del y_gender
    gc.collect()

  print(" [val] %i Sapmles. 1 Block forced" % (len(val['path'])))

  X_val, y_age, y_gender = utils.get_img_array(val, DATA_SRC, age_classes, img_dim=INPUT_DIM, num_samples_per_split=len(val['path']))
  np.save(fs.join(DATA_DST, VAL_DATA_OBJ), X_val)
  np.save(fs.add_suffix(fs.join(DATA_DST, VAL_DATA_OBJ), '_label_age'), y_age)
  np.save(fs.add_suffix(fs.join(DATA_DST, VAL_DATA_OBJ), '_label_gender'), y_gender)

  # Remove the array from memory
  del X_val
  del y_age
  del y_gender
  gc.collect()

  print("[test] %i Sapmles. %i Blocks required" % (len(test['path']), math.ceil(len(test['path']) / SAMPLES_PER_SPLIT)))

  for i in range(math.ceil(len(test['path']) / SAMPLES_PER_SPLIT)):
    X_test, y_age, y_gender = utils.get_img_array(test, DATA_SRC, age_classes, img_dim=INPUT_DIM, split=i, num_samples_per_split=SAMPLES_PER_SPLIT)
    np.save(fs.add_suffix(fs.join(DATA_DST, TEST_DATA_OBJ), '_%02d' % i), X_test)
    np.save(fs.add_suffix(fs.join(DATA_DST, TEST_DATA_OBJ), '_label_age_%02d' % i), y_age)
    np.save(fs.add_suffix(fs.join(DATA_DST, TEST_DATA_OBJ), '_label_gender_%02d' % i), y_gender)
    
    # Remove the array from memory
    del X_test
    del y_age
    del y_gender
    gc.collect()
コード例 #9
0
def main():

  if not fs.exists(DATA_DST):
    fs.mkdir(DATA_DST)

  meta_all = utils.shuffle_meta_data(utils.load_meta_data(DATA_SRC, WIKI_META_OBJ, IMDB_META_OBJ))

  train, test = utils.split_meta_data(meta_all, TRAIN_TEST_SPLIT)
  train, val = utils.split_meta_data(train, TRAIN_VAL_SPLIT)

  # Free the memory
  del meta_all
  gc.collect()

  print("Converting blocks")

  print(" [train] %i Sapmles" % (train_samples))

  i = 0
  X_train, y_age, y_gender = utils.get_img_array(train, DATA_SRC, age_classes, img_dim=INPUT_DIM, split=i, num_samples_per_split=train_samples)
  np.save(fs.add_suffix(fs.join(DATA_DST, TRAIN_DATA_OBJ), '_%02d' % i), X_train)
  np.save(fs.add_suffix(fs.join(DATA_DST, TRAIN_DATA_OBJ), '_label_age_%02d' % i), y_age)
  np.save(fs.add_suffix(fs.join(DATA_DST, TRAIN_DATA_OBJ), '_label_gender_%02d' % i), y_gender)
    
  # Remove the array from memory
  del X_train
  del y_age
  del y_gender
  gc.collect()

  print(" [val] %i Sapmles" % (val_samples))

  X_val, y_age, y_gender = utils.get_img_array(val, DATA_SRC, age_classes, img_dim=INPUT_DIM, num_samples_per_split=val_samples)
  np.save(fs.join(DATA_DST, VAL_DATA_OBJ), X_val)
  np.save(fs.add_suffix(fs.join(DATA_DST, VAL_DATA_OBJ), '_label_age'), y_age)
  np.save(fs.add_suffix(fs.join(DATA_DST, VAL_DATA_OBJ), '_label_gender'), y_gender)

  # Remove the array from memory
  del X_val
  del y_age
  del y_gender
  gc.collect()

  print("[test] %i Sapmles" % (test_samples))

  i = 0
  X_test, y_age, y_gender = utils.get_img_array(test, DATA_SRC, age_classes, img_dim=INPUT_DIM, split=i, num_samples_per_split=test_samples)
  np.save(fs.add_suffix(fs.join(DATA_DST, TEST_DATA_OBJ), '_%02d' % i), X_test)
  np.save(fs.add_suffix(fs.join(DATA_DST, TEST_DATA_OBJ), '_label_age_%02d' % i), y_age)
  np.save(fs.add_suffix(fs.join(DATA_DST, TEST_DATA_OBJ), '_label_gender_%02d' % i), y_gender)
  
  # Remove the array from memory
  del X_test
  del y_age
  del y_gender
  gc.collect()
コード例 #10
0
def create_archive_tree(monitoring_dir, ROOT_DIR, TARGET_ROOT_DIR, backup_dir_name, backup_dir_list):
    for source_full_path in backup_dir_list:
        re_pattern = re.compile(r'%s' % monitoring_dir)
        source_path = re.sub(re_pattern, '', source_full_path)
        archive_path = fs.join([ROOT_DIR, TARGET_ROOT_DIR, backup_dir_name, source_path])
        if not fs.exists(archive_path):
            try:
                fs.mkdir(archive_path)
            except:
                print (archive_path, "Can't create archive tree in func: create_archive_tree")
コード例 #11
0
def test__when_deleting_directory__should_call_fs_removetree():
    dir_path = "mydir"
    fs = MemoryFS()
    sub_fs = fs.makedir(dir_path)
    sub_fs.create(SOURCE)

    sut = _TestFilesystemImpl(fs)

    sut.delete(dir_path)

    assert not fs.exists(dir_path)
コード例 #12
0
def add_to_report(text, params={}):
    timestamp = params.get('timestamp')

    if not fs.exists('results/%s' % timestamp):
        fs.mkdir('results/%s' % timestamp)

    if isinstance(text, dict):
        with open('results/%s/report.txt' % timestamp, 'at+') as file:
            pprint.pprint(text, stream=file, indent=2)
    else:
        fs.append("results/%s/report.txt" % timestamp, text + '\n')
コード例 #13
0
async def unloadext(ctx, ext):
    if fs.exists(ext + ".py"):
        try:
            bot.unload_extension(ext)
            await ctx.send(f"Extension {ext} successfully unloaded.")
        except Exception as err:
            await ctx.send(
                f"Extension {ext} failed to unload. Reason: ``{err.__class__.__name__}: {err}``"
            )
    else:
        await ctx.send(f"Extension {ext} invalid.")
コード例 #14
0
    def testRollbackSnapshot(self) -> None:
        self.page.selectView("Browse snapshots")
        self.page.selectDataset(self.zfs.dataset)

        # create snapshot
        self.page.createSnapshot("rollback-snapshot")
        self.assertIn("@rollback-snapshot' created", self.page.alertText())
        self.page.closeAlert()

        # create a file
        fs.createTestFile(self.zfs.mountpoint() + "/rollback-test.txt",
                          ["dummy"])
        self.assertTrue(fs.exists(self.zfs.mountpoint() +
                                  "/rollback-test.txt"))

        # rollback
        self.page.rollbackSnapshot("rollback-snapshot")
        self.assertIn("Snapshot 'rollback-snapshot' rolled back",
                      self.page.alertText())
        self.assertFalse(
            fs.exists(self.zfs.mountpoint() + "/rollback-test.txt"))
コード例 #15
0
    async def remove(self,
                     ctx,
                     member: discord.Member,
                     *,
                     reason: str = "No reason specified."):
        """Unwarns an user!

        The warns are set to 0."""
        nowarnfound = False
        with open("../DSB_Files/warns.json", "r") as filetoread:
            warnsdict = json.load(filetoread)
        try:
            warnsdict[str(ctx.guild.id)][str(member.id)] = 0
        except KeyError:
            nowarnfound = True
            await say(
                ctx,
                ":interrobang: - The mentioned user has never been warned!")
        finally:
            if not nowarnfound:
                await esay(
                    ctx,
                    discord.Embed(
                        title="Warns cleaned!",
                        description=f"User {member} is no longer warned!",
                        color=0x00FF00))
                if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
                    with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt",
                              "r") as file:
                        chID = file.read()
                    logch = self.bot.get_channel(int(chID))
                else:
                    logch = ctx
                embed_warncleaned = discord.Embed(
                    title="Admin Log: User unwarn",
                    description=
                    "An user has been unwarned inside of this guild.",
                    color=0xFFFF00)
                embed_warncleaned.add_field(name="Admin",
                                            value=ctx.author.mention)
                embed_warncleaned.add_field(name="Unwarned user",
                                            value=member.mention)
                embed_warncleaned.add_field(name="Reason", value=reason)
                await esay(logch, embed_warncleaned)
                with open("../DSB_Files/warns.json", "w") as filetowrite:
                    json.dump(warnsdict, filetowrite)
            else:
                pass
コード例 #16
0
    async def setlog(self, ctx, channel: discord.TextChannel = None):
        """Sets the log channel.

        Parameters:
          channel - The channel used for the logs. The channel has to be mentioned normally and the bot needs to be able to read and send to it.

        Permissions:
          Administrator"""
        if channel != None:
            fs.write(f"../DSB_Files/log_of_{ctx.guild.id}.txt",
                     str(channel.id))
            await say(ctx, ":white_check_mark: - Log Channel set!")
        else:
            if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
                os.remove(f"../DSB_Files/log_of_{ctx.guild.id}.txt")
                await say(
                    ctx,
                    ":white_check_mark: - Log channel deleted out of memory!")
            else:
                await say(ctx, ":interrobang: - Please mention a channel!")
コード例 #17
0
    async def hackban(self, ctx, userID: int, *, reason: str = None):
        """Bans a user by ID from the current guild.

        This ban is special, as it can ban users that aren't inside of the guild at all. However, their ID is required for this.

        Parameters:
          userID - The ID of the user to ban. Only integers (numeric characters) are accepted.
          reason - (Optional) The reason for the ban. You can leave this empty. The reason will be shown inside of the audit log.

        Permissions:
          Ban/Unban members"""
        user = await self.bot.get_user_info(user_id=userID)
        await ctx.guild.ban(
            user,
            delete_message_days=0,
            reason=f"[HACKBAN] Banned by {ctx.author}: {reason}")
        await esay(
            ctx,
            discord.Embed(
                title=f"Banned member {user}",
                description=
                f"Member {user} has been successfully banned from this guild!",
                color=0xFF0000))
        embed_hban = discord.Embed(
            title="Admin log: Hackban",
            description="A hackban has been issued inside of this server.",
            color=0xFF0000)
        embed_hban.add_field(name="Admin", value=ctx.author)
        embed_hban.add_field(name="Hackbanned member", value=user)
        embed_hban.add_field(name="Reason", value=reason, inline=False)
        if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
            with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt", "r") as file:
                chID = file.read()
            logch = self.bot.get_channel(int(chID))
        else:
            logch = ctx
        await logch.send(embed=embed_hban)
コード例 #18
0
ファイル: test_exists.py プロジェクト: sevnote/python-fs
def test_exists_file():
    assert fs.exists(TEST_FILE) is True
コード例 #19
0
    async def add(self,
                  ctx,
                  member: discord.Member,
                  *,
                  reason: str = "No reason specified."):
        """Warns an user!

        If the warns and limit equal, the user will be kicked. However, a warn number that exceeds the limit will cause the bot to ban the user."""
        with open("../DSB_Files/warns.json", "r") as filetoread:
            warnsdict = json.load(filetoread)
        try:
            warnlimit = warnsdict[str(ctx.guild.id)]["limit"]
        except KeyError:
            warnlimit = 3
        try:
            pastwarns = warnsdict[str(ctx.guild.id)][str(member.id)]
            warnsdict[str(ctx.guild.id)][str(member.id)] = pastwarns + 1
        except KeyError:
            warnsdict[str(ctx.guild.id)] = {str(member.id): 1}
        finally:
            if warnsdict[str(ctx.guild.id)][str(member.id)] < warnlimit:
                await esay(
                    ctx,
                    discord.Embed(
                        title="User warned!",
                        description=
                        f"User {member.mention} has been successfully warned. He currently has {warnsdict[str(ctx.guild.id)][str(member.id)]} warns.",
                        color=0xFFFF00))
                if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
                    with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt",
                              "r") as file:
                        chID = file.read()
                    logch = self.bot.get_channel(int(chID))
                else:
                    logch = ctx
                embed_warned = discord.Embed(
                    title="Admin Log: User warn",
                    description="An user has been warned inside of this guild.",
                    color=0xFFFF00)
                embed_warned.add_field(name="Admin", value=ctx.author.mention)
                embed_warned.add_field(name="Warned user",
                                       value=member.mention)
                embed_warned.add_field(name="Reason", value=reason)
                await esay(logch, embed_warned)
            elif warnsdict[str(ctx.guild.id)][str(member.id)] == warnlimit:
                await member.kick(
                    reason=
                    f"[WARN] - Warns have been exceeded. The warn has been executed by {ctx.author} . The reason for the warn is: {reason}"
                )
                await esay(
                    ctx,
                    discord.Embed(
                        title="User kicked!",
                        description=
                        f"User {member} has been kicked due to exceeded warns. The next warn will result in a ban!",
                        color=0xFFFF00))
                if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
                    with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt",
                              "r") as file:
                        chID = file.read()
                    logch = self.bot.get_channel(int(chID))
                else:
                    logch = ctx
                embed_warnkicked = discord.Embed(
                    title="Admin Log: User warn-kick",
                    description=
                    "An user has been warned and warns have been exceeded, the user has been kicked.",
                    color=0xFFFF00)
                embed_warnkicked.add_field(name="Admin",
                                           value=ctx.author.mention)
                embed_warnkicked.add_field(name="Kicked user", value=member)
                embed_warnkicked.add_field(name="Reason", value=reason)
                await esay(logch, embed_warnkicked)
            elif warnsdict[str(ctx.guild.id)][str(member.id)] > warnlimit:
                await member.ban(
                    reason=
                    f"[WARN] - Warns have been exceeded. The warn has been executed by {ctx.author} . The reason for the warn is: {reason}"
                )
                await esay(
                    ctx,
                    discord.Embed(
                        title="User banned!",
                        description=
                        f"User {member} has been banned due to exceeded warns.",
                        color=0xFFFF00))
                if fs.exists(f"../DSB_Files/log_of_{ctx.guild.id}.txt"):
                    with open(f"../DSB_Files/log_of_{ctx.guild.id}.txt",
                              "r") as file:
                        chID = file.read()
                    logch = self.bot.get_channel(int(chID))
                else:
                    logch = ctx
                embed_warnbanned = discord.Embed(
                    title="Admin Log: User warn-ban",
                    description=
                    "An user has been warned and warns have been exceeded, the user has been banned.",
                    color=0xFFFF00)
                embed_warnbanned.add_field(name="Admin",
                                           value=ctx.author.mention)
                embed_warnbanned.add_field(name="Banned user", value=member)
                embed_warnbanned.add_field(name="Reason", value=reason)
                await esay(logch, embed_warnbanned)
            with open("../DSB_Files/warns.json", "w") as filetowrite:
                json.dump(warnsdict, filetowrite)
コード例 #20
0
ファイル: test_exists.py プロジェクト: sevnote/python-fs
def test_exists_dir():
    assert fs.exists(TEST_DIR) is True
コード例 #21
0
ファイル: abstraction_layer.py プロジェクト: coowoole/gaedav
 def exists(self, respath):
    return fs.exists(respath)
コード例 #22
0
ファイル: test_exists.py プロジェクト: sevnote/python-fs
def test_not_exists_dir():
    assert fs.exists(os.path.join(TEST_DIR, "foo")) is False
コード例 #23
0
ファイル: app.py プロジェクト: shivito1/python-subviewer
        for sub in subs:
            start = get_ms(sub.start)
            duration = get_ms(sub.end) - get_ms(sub.start)
            current_time = get_ms(sub.end)
            self.sub_label.after(start, self.update, start, duration, sub.text)
            self.sub_label.after(start + duration, self.update, start,
                                 duration, "")

    def updateText(self, val, verbose=""):
        if verbose:
            print(verbose)
        self.sub_var.set(val)

    def update(self, start, duration, text):
        self.updateText(text, verbose="%i (%i): %s" % (start, duration, text))


if __name__ == "__main__":
    filename = sys.argv[1]
    print('Starting %s' % filename)

    if fs.exists(filename):
        subs = pysrt.open(filename)

        root = tk.Tk()
        app = Application(master=root, subs=subs)
        app.mainloop()

    else:
        print('Please use a valid subtitle file')
コード例 #24
0
    print("====> Layer: ", key)
    print("Expected Shape: ", nb_filter, stack_size, nb_col, nb_row)
    print("Found Shape: ", np.array(blobs[0].data).shape)

    weights_p = blobs[0].data.reshape(
        (nb_filter, stack_size, nb_col, nb_row)).astype(dtype=np.float32)
    weights_b = blobs[1].data.astype(dtype=np.float32)

    if len(weights_p.shape) > 2:
        # Caffe uses the shape f, (d, y, x)
        # ConvnetJS uses the shape f, (y, x, d)
        weights_p = np.swapaxes(np.swapaxes(weights_p, 3, 1), 2, 1)

    print("Converted to Shape: ", weights_p.shape)

    weights = {
        'filter': weights_p.reshape((nb_filter, stack_size * nb_col * nb_row)),
        'bias': weights_b
    }

    filename = WEIGHTS_DIR + key + '.bin'
    prev_shape = (nb_filter, stack_size, nb_col, nb_row)

    if not fs.exists(fs.dirname(filename)):
        fs.mkdir(fs.dirname(filename))

    with open(fs.add_suffix(filename, "_filter"), 'wb') as f:
        f.write(weights['filter'].astype(np.float32).tostring())

    with open(fs.add_suffix(filename, "_bias"), 'wb') as f:
        f.write(weights['bias'].astype(np.float32).tostring())
コード例 #25
0
	print("Expected Shape: ", nb_filter, stack_size, nb_col, nb_row)	
	print("Found Shape: ", np.array(blobs[0].data).shape)

	weights_p = blobs[0].data.astype(dtype=np.float32)
	weights_b = blobs[1].data.astype(dtype=np.float32)

	if len(weights_p.shape) > 2:
		# Caffe uses the shape f, (d, y, x)
		# ConvnetJS uses the shape f, (y, x, d)
		weights_p = np.swapaxes(np.swapaxes(weights_p, 3, 1), 2, 1)

	print("Converted to Shape: ", weights_p.shape)

	weights = {
		'filter': weights_p.reshape((nb_filter, stack_size*nb_col*nb_row)).tolist(),
		'bias': weights_b.tolist()
	}

	filename = WEIGHTS_DIR + key + '.txt'

	if not fs.exists(fs.dirname(filename)):
		fs.mkdir(fs.dirname(filename))

	fs.write(fs.add_suffix(filename, "_filter"), "")
	for i, f_weights in enumerate(weights['filter']):
		if i == len(weights['filter']) - 1:
			fs.append(fs.add_suffix(filename, "_filter"), ",".join(map(str, f_weights)))
		else:
			fs.append(fs.add_suffix(filename, "_filter"), ",".join(map(str, f_weights)) + "\n")

	fs.write(fs.add_suffix(filename, "_bias"), ",".join(map(str, weights['bias'])))
コード例 #26
0
	print '### Secure Move ###'
elif app == 'smerge':
	settings.behavior = smerge
	print '### Secure Merge ###'
else:
	settings.behavior = scp_plus
	print '### Secure Copy ###'

if len(argv) < 3:
	print 'Aborting: Not enough console arguments.'
	Usage()
	exit()

for i in range(1, len(argv)-1):
	arg = argv[i].rstrip('/')
	if exists(arg):
		settings.sources.append(arg)
	else:
		print 'Omitting source "'+arg+'": Not found.'
settings.target = argv[len(argv)-1].rstrip('/')

print str(len(settings.sources))+' sources: '+str(settings.sources)
print 'target: '+settings.target

if len(settings.sources) < 1:
	print 'Aborting: No sources.'
	exit()


# Main